This commit is contained in:
mmrbnjd
2024-04-02 17:14:18 +03:30
parent faa78adae6
commit dd4969f504
11 changed files with 315 additions and 402 deletions

View File

@@ -24,6 +24,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Common\DTOs\" />
<Folder Include="Features\" />
<Folder Include="Validations\" />
</ItemGroup>

View File

@@ -1,16 +0,0 @@
namespace Back.Common.ViewModels
{
public class PagingDto<T>
{
public PagingDto(int RowCount, int pageCount, List<T> list)
{
this.RowCount = RowCount;
this.list = list;
PageCount = pageCount;
}
public int RowCount { get; set; }
public int PageCount { get; set; }
public List<T> list { get; set; }
}
}

View File

@@ -5,7 +5,8 @@ using System.Data;
using System.Globalization;
using System.Reflection;
using System.Security.Cryptography;
using Back.Common.ViewModels;
using Shared.DTOs;
namespace Back.Common
{

View File

@@ -20,8 +20,9 @@ namespace Back.Controllers
[HttpGet("DateTimeServer")]
public async Task<ActionResult<DateTime>> DateTimeServer()
=> Ok(DateTime.Now);
[HttpGet("LastBlog/{Count}")]
public async Task<ActionResult<List<BlogDto>>> LastBlog(int Count)
=> Ok(await _sBase.GetBlog(Count));
[HttpGet("LastBlog")]
public async Task<ActionResult<PagingDto<BlogDto>>> LastBlog(int PageIndex,int PageSize)
=> Ok(await _sBase.GetBlog(PageIndex,PageSize));
}
}

View File

@@ -24,7 +24,7 @@ builder.Services.AddCors(options =>
options.AddPolicy(origins,
policy =>
{
policy.WithOrigins("https://localhost:7224")
policy.WithOrigins("https://localhost:7224", "http://localhost:5107")
.AllowAnyHeader()
.AllowAnyMethod();
});

View File

@@ -1,4 +1,5 @@
using Back.Data.Contracts;
using Back.Common;
using Back.Data.Contracts;
using Back.Data.Models;
using Microsoft.EntityFrameworkCore;
using Shared.DTOs;
@@ -25,17 +26,18 @@ namespace Back.Services
PermissionID=x.PermissionID,
}).ToListAsync();
}
public async Task<List<BlogDto>> GetBlog(int count)
public async Task<PagingDto<BlogDto>> GetBlog(int PageIndex, int PageSize)
{
return await _repoBlog.Get(w=>w.Status).OrderByDescending(o=>o.ID).Take(count)
return await _repoBlog.Get(w=>w.Status).OrderByDescending(o=>o.ID)
.Select(s=>new BlogDto
{
Title = s.Title,
Date=s.Date,
ID=s.ID,
Photo=string.IsNullOrEmpty(s.Photo) ? "blog-grid-1.jpg" : s.Photo
})
.ToListAsync();
}).Paging(PageIndex, PageSize); ;
}
}
}