adding poet fullurl field to view model

This commit is contained in:
Hamid Reza Mohammadi 2020-12-23 19:06:08 +03:30
parent 7fdabd93d7
commit 05e5a0990f
6 changed files with 78 additions and 8 deletions

View File

@ -24,11 +24,11 @@ namespace RMuseum.Controllers
[HttpGet]
[Route("poets")]
[AllowAnonymous]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoet[]))]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoetViewModel[]))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> GetPoets(bool websitePoets = true)
{
RServiceResult<GanjoorPoet[]> res =
RServiceResult<GanjoorPoetViewModel[]> res =
await _ganjoorService.GetPoets(websitePoets);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);

View File

@ -8,7 +8,7 @@
/// <summary>
/// poet info
/// </summary>
public GanjoorPoet Poet { get; set; }
public GanjoorPoetViewModel Poet { get; set; }
/// <summary>
/// poet cat info

View File

@ -0,0 +1,28 @@
namespace RMuseum.Models.Ganjoor.ViewModels
{
/// <summary>
/// Ganjoor Poet
/// </summary>
public class GanjoorPoetViewModel
{
/// <summary>
/// id
/// </summary>
public int Id { get; set; }
/// <summary>
/// name
/// </summary>
public string Name { get; set; }
/// <summary>
/// description
/// </summary>
public string Description { get; set; }
/// <summary>
/// urlslug
/// </summary>
public string FullUrl { get; set; }
}
}

View File

@ -3525,6 +3525,31 @@
poet cat info
</summary>
</member>
<member name="T:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoetViewModel">
<summary>
Ganjoor Poet
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoetViewModel.Id">
<summary>
id
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoetViewModel.Name">
<summary>
name
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoetViewModel.Description">
<summary>
description
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoetViewModel.FullUrl">
<summary>
urlslug
</summary>
</member>
<member name="T:RMuseum.Models.ImportJob.ImportJob">
<summary>
Import Job

View File

@ -17,7 +17,7 @@ namespace RMuseum.Services
/// </summary>
/// <param name="websitePoets"></param>
/// <returns></returns>
Task<RServiceResult<GanjoorPoet[]>> GetPoets(bool websitePoets);
Task<RServiceResult<GanjoorPoetViewModel[]>> GetPoets(bool websitePoets);
/// <summary>
/// get poet by id

View File

@ -29,21 +29,31 @@ namespace RMuseum.Services.Implementation
/// </summary>
/// <param name="websitePoets"></param>
/// <returns></returns>
public async Task<RServiceResult<GanjoorPoet[]>> GetPoets(bool websitePoets)
public async Task<RServiceResult<GanjoorPoetViewModel[]>> GetPoets(bool websitePoets)
{
try
{
return new RServiceResult<GanjoorPoet[]>
return new RServiceResult<GanjoorPoetViewModel[]>
(
await _context.GanjoorPoets
.Where(p => !websitePoets || p.Id < 200)
.OrderBy(p => p.Name)
.Select
(
p => new GanjoorPoetViewModel()
{
Id = p.Id,
Name = p.Name,
Description = p.Description,
FullUrl = _context.GanjoorCategories.Where(c => c.PoetId == p.Id && c.ParentId == null).Single().FullUrl
}
)
.ToArrayAsync()
);
}
catch (Exception exp)
{
return new RServiceResult<GanjoorPoet[]>(null, exp.ToString());
return new RServiceResult<GanjoorPoetViewModel[]>(null, exp.ToString());
}
}
@ -128,7 +138,14 @@ namespace RMuseum.Services.Implementation
(
new GanjoorPoetCompleteViewModel()
{
Poet = await _context.GanjoorPoets.Where(p => p.Id == cat.PoetId).FirstOrDefaultAsync(),
Poet = await _context.GanjoorPoets.Where(p => p.Id == cat.PoetId)
.Select(p => new GanjoorPoetViewModel()
{
Id = p.Id,
Name = p.Name,
Description = p.Description,
FullUrl = _context.GanjoorCategories.Where(c => c.PoetId == p.Id && c.ParentId == null).Single().FullUrl
}) .FirstOrDefaultAsync(),
Cat = catViewModel
}
);