71 lines
2.7 KiB
C#
71 lines
2.7 KiB
C#
using Back.Common;
|
|
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;
|
|
private readonly IAsyncRepository<Question> _repoQuestion;
|
|
public ServBase(IAsyncRepository<Pricing> repoPricing, IAsyncRepository<Blog> repoBlog, IAsyncRepository<Question> repoQuestion)
|
|
{
|
|
_repoPricing = repoPricing;
|
|
_repoBlog = repoBlog;
|
|
_repoQuestion = repoQuestion;
|
|
}
|
|
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<PagingDto<BlogDto>> GetBlog(int PageIndex, int PageSize)
|
|
{
|
|
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-SampleTitle.jpg" : s.Photo
|
|
}).Paging(PageIndex, PageSize); ;
|
|
}
|
|
public async Task<PagingDto<QuestionDto>> GetQuestion(int PageIndex, int PageSize)
|
|
{
|
|
return await _repoQuestion.Get(w => w.Status)
|
|
.Include(inc=>inc.questionCategory).OrderByDescending(o => o.ID)
|
|
.Select(s => new QuestionDto
|
|
{
|
|
Answer=s.Answer,
|
|
Category=s.questionCategory.Title,
|
|
Title=s.Title,
|
|
ID = s.ID
|
|
}).Paging(PageIndex, PageSize);
|
|
}
|
|
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;
|
|
}
|
|
|
|
}
|
|
}
|