Files
moadiran/Back/Services/ServBase.cs

57 lines
2.0 KiB
C#
Raw Normal View History

2024-04-02 17:14:18 +03:30
using Back.Common;
using Back.Data.Contracts;
2024-03-30 15:10:36 +03:30
using Back.Data.Models;
using Microsoft.EntityFrameworkCore;
using Shared.DTOs;
namespace Back.Services
{
public class ServBase
{
private readonly IAsyncRepository<Pricing> _repoPricing;
2024-03-31 01:33:17 +03:30
private readonly IAsyncRepository<Blog> _repoBlog;
public ServBase(IAsyncRepository<Pricing> repoPricing, IAsyncRepository<Blog> repoBlog)
2024-03-30 15:10:36 +03:30
{
_repoPricing = repoPricing;
2024-03-31 01:33:17 +03:30
_repoBlog = repoBlog;
2024-03-30 15:10:36 +03:30
}
public async Task<List<BasePriceDto>> GetBasePrice()
{
return await _repoPricing.GetAll().Select(x => new BasePriceDto
{
Price = x.Price,
2024-03-31 01:33:17 +03:30
CalculationType = x.CalculationTypeID == 1 && x.PermissionID == 16 ? "هر ارسال"
:x.CalculationTypeID== 1 && x.PermissionID != 16 ? "واحدی"
2024-03-30 15:10:36 +03:30
: x.CalculationTypeID == 2 ? "نامحدود" : "روزانه",
PermissionID=x.PermissionID,
}).ToListAsync();
}
2024-04-02 17:14:18 +03:30
public async Task<PagingDto<BlogDto>> GetBlog(int PageIndex, int PageSize)
2024-03-31 01:33:17 +03:30
{
2024-04-02 17:14:18 +03:30
return await _repoBlog.Get(w=>w.Status).OrderByDescending(o=>o.ID)
2024-03-31 01:33:17 +03:30
.Select(s=>new BlogDto
{
Title = s.Title,
Date=s.Date,
ID=s.ID,
2024-04-03 14:36:33 +03:30
Photo=string.IsNullOrEmpty(s.Photo) ? "blog-SampleTitle.jpg" : s.Photo
2024-04-02 17:14:18 +03:30
}).Paging(PageIndex, PageSize); ;
2024-03-31 01:33:17 +03:30
}
2024-04-03 14:36:33 +03:30
public async Task<BlogDtoFull?> GetBlogByID(int ID)
{
var result= await _repoBlog.Get(w => w.Status && w.ID==ID)
.Select(s => new BlogDtoFull
{
Title = s.Title,
Date = s.Date,
ID = s.ID,
Photo = string.IsNullOrEmpty(s.Photo) ? "blog-SampleTitle.jpg" : s.Photo,
Text=s.Text,
Time=s.Time
}).FirstOrDefaultAsync();
return result;
}
2024-03-30 15:10:36 +03:30
}
}