82 lines
2.8 KiB
C#
82 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using _0_Framework.Application;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.ClassificationSchemeAgg;
|
|
using CompanyManagment.App.Contracts.ClassificationScheme;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class ClassificationSchemeRepository :RepositoryBase<long, ClassificationScheme>, IClassificationSchemeRepository
|
|
{
|
|
private readonly CompanyContext _context;
|
|
public ClassificationSchemeRepository(CompanyContext context) : base(context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<ClassificationSchemePartialModel> ClassificationSchemePartialModel(long workshopId)
|
|
{
|
|
var hasScheme =await _context.ClassificationSchemes.AnyAsync(x => x.WorkshopId == workshopId);
|
|
if (!hasScheme)
|
|
return new ClassificationSchemePartialModel()
|
|
{
|
|
HasScheme = false,
|
|
|
|
};
|
|
|
|
var schemeList = _context.ClassificationSchemes.Where(x => x.WorkshopId == workshopId).Select(x =>
|
|
new EditClassificationScheme()
|
|
{
|
|
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
IncludingDateGr = x.IncludingDateGr,
|
|
ExecutionDateGr = x.ExecutionDateGr,
|
|
EndSchemeDateGr = x.EndSchemeDateGr,
|
|
IncludingDateFa = x.IncludingDateGr.ToFarsi(),
|
|
ExecutionDateFa = x.ExecutionDateGr.ToFarsi(),
|
|
DesignerFullName = x.DesignerFullName,
|
|
DesignerPhone = x.DesignerPhone,
|
|
TypeOfCoefficient = x.TypeOfCoefficient
|
|
|
|
}).ToListAsync();
|
|
return new ClassificationSchemePartialModel()
|
|
{
|
|
HasScheme = true,
|
|
WorkshopId = workshopId,
|
|
ClassificationSchemesList = schemeList.GetAwaiter().GetResult()
|
|
};
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// دریافت اطلاعات طرح برای ویرایش
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public Task<EditClassificationScheme> GetClassificationScheme(long id)
|
|
{
|
|
return _context.ClassificationSchemes.Select(x =>
|
|
new EditClassificationScheme()
|
|
{
|
|
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
IncludingDateGr = x.IncludingDateGr,
|
|
ExecutionDateGr = x.ExecutionDateGr,
|
|
EndSchemeDateGr = x.EndSchemeDateGr,
|
|
IncludingDateFa = x.IncludingDateGr.ToFarsi(),
|
|
ExecutionDateFa = x.ExecutionDateGr.ToFarsi(),
|
|
DesignerFullName = x.DesignerFullName,
|
|
DesignerPhone = x.DesignerPhone,
|
|
TypeOfCoefficient = x.TypeOfCoefficient
|
|
|
|
}).FirstOrDefaultAsync(x => x.Id == id);
|
|
}
|
|
|
|
|
|
} |