72 lines
2.5 KiB
C#
72 lines
2.5 KiB
C#
using AutoMapper;
|
|
using Complex.Common.Dto;
|
|
using Complex.Domain.Entities;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Complex.Application.Basic
|
|
{
|
|
public interface IBasicService
|
|
{
|
|
ResultDto<List<UnitStateDto>> UnitStateList(Guid ComplexId);
|
|
ResultDto<int> InsertUnitState(UnitStateDto unitState);
|
|
ResultDto<bool> EditUnitState(UnitStateDto unitState);
|
|
}
|
|
public class BasicService : IBasicService
|
|
{
|
|
private readonly IComplexDBContext _complexDBContext;
|
|
private readonly IMapper _mapper;
|
|
|
|
public BasicService(IComplexDBContext complexDBContext, IMapper mapper)
|
|
{
|
|
_complexDBContext = complexDBContext;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
public ResultDto<List<UnitStateDto>> UnitStateList(Guid ComplexId)
|
|
{
|
|
var UnitStates = _complexDBContext.UnitStates.Where(s => s.ComplexId == ComplexId || !s.ComplexId.HasValue).ToList()
|
|
.Select(u=>_mapper.Map<UnitStateDto>(u)).ToList();
|
|
return new ResultDto<List<UnitStateDto>>
|
|
{
|
|
Data = UnitStates,
|
|
IsSuccess = true,
|
|
RowCount = UnitStates.Count
|
|
};
|
|
|
|
}
|
|
|
|
public ResultDto<bool> EditUnitState(UnitStateDto unitStateDto)
|
|
{
|
|
var unitState = _complexDBContext.UnitStates.FirstOrDefault(us => us.Id == unitStateDto.Id);
|
|
unitState.Title = unitStateDto.Title;
|
|
unitState.Icon= unitStateDto.Icon;
|
|
_complexDBContext.SaveChanges();
|
|
return new ResultDto<bool> { IsSuccess = true, Message="ویرایش با موفقیت انجام شد"};
|
|
}
|
|
|
|
public ResultDto<int> InsertUnitState(UnitStateDto unitStateDto)
|
|
{
|
|
var newUnitState = new UnitState();
|
|
newUnitState.Title= unitStateDto.Title;
|
|
newUnitState.Icon= unitStateDto.Icon;
|
|
newUnitState.ComplexId= unitStateDto.ComplexId;
|
|
_complexDBContext.UnitStates.Add(newUnitState);
|
|
_complexDBContext.SaveChanges();
|
|
|
|
return new ResultDto<int> { IsSuccess = true, Data= newUnitState.Id, Message = "ثبت با موفقیت انجام شد" };
|
|
}
|
|
}
|
|
public class UnitStateDto
|
|
{
|
|
public int Id { get; set; }
|
|
public Guid? ComplexId { set; get; }
|
|
public string Title { set; get; }
|
|
public string Icon { set; get; }
|
|
}
|
|
|
|
}
|