42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
using Back.Data.Contracts;
|
|
using Back.Data.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Shared.DTOs;
|
|
|
|
namespace Back.Services
|
|
{
|
|
public class ServBase
|
|
{
|
|
private readonly IAsyncRepository<Pricing> _repoPricing;
|
|
private readonly IAsyncRepository<Blog> _repoBlog;
|
|
public ServBase(IAsyncRepository<Pricing> repoPricing, IAsyncRepository<Blog> repoBlog)
|
|
{
|
|
_repoPricing = repoPricing;
|
|
_repoBlog = repoBlog;
|
|
}
|
|
public async Task<List<BasePriceDto>> GetBasePrice()
|
|
{
|
|
return await _repoPricing.GetAll().Select(x => new BasePriceDto
|
|
{
|
|
Price = x.Price,
|
|
CalculationType = x.CalculationTypeID == 1 && x.PermissionID == 16 ? "هر ارسال"
|
|
:x.CalculationTypeID== 1 && x.PermissionID != 16 ? "واحدی"
|
|
: x.CalculationTypeID == 2 ? "نامحدود" : "روزانه",
|
|
PermissionID=x.PermissionID,
|
|
}).ToListAsync();
|
|
}
|
|
public async Task<List<BlogDto>> GetBlog(int count)
|
|
{
|
|
return await _repoBlog.Get(w=>w.Status).OrderByDescending(o=>o.ID).Take(count)
|
|
.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();
|
|
}
|
|
}
|
|
}
|