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] [HttpGet]
[Route("poets")] [Route("poets")]
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoet[]))] [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoetViewModel[]))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> GetPoets(bool websitePoets = true) public async Task<IActionResult> GetPoets(bool websitePoets = true)
{ {
RServiceResult<GanjoorPoet[]> res = RServiceResult<GanjoorPoetViewModel[]> res =
await _ganjoorService.GetPoets(websitePoets); await _ganjoorService.GetPoets(websitePoets);
if (!string.IsNullOrEmpty(res.ExceptionString)) if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString); return BadRequest(res.ExceptionString);

View File

@ -8,7 +8,7 @@
/// <summary> /// <summary>
/// poet info /// poet info
/// </summary> /// </summary>
public GanjoorPoet Poet { get; set; } public GanjoorPoetViewModel Poet { get; set; }
/// <summary> /// <summary>
/// poet cat info /// 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 poet cat info
</summary> </summary>
</member> </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"> <member name="T:RMuseum.Models.ImportJob.ImportJob">
<summary> <summary>
Import Job Import Job

View File

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

View File

@ -29,21 +29,31 @@ namespace RMuseum.Services.Implementation
/// </summary> /// </summary>
/// <param name="websitePoets"></param> /// <param name="websitePoets"></param>
/// <returns></returns> /// <returns></returns>
public async Task<RServiceResult<GanjoorPoet[]>> GetPoets(bool websitePoets) public async Task<RServiceResult<GanjoorPoetViewModel[]>> GetPoets(bool websitePoets)
{ {
try try
{ {
return new RServiceResult<GanjoorPoet[]> return new RServiceResult<GanjoorPoetViewModel[]>
( (
await _context.GanjoorPoets await _context.GanjoorPoets
.Where(p => !websitePoets || p.Id < 200) .Where(p => !websitePoets || p.Id < 200)
.OrderBy(p => p.Name) .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() .ToArrayAsync()
); );
} }
catch (Exception exp) 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() 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 Cat = catViewModel
} }
); );