123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- using AutoMapper;
- using Ropin.Inspection.Common.Accessor.Interface;
- using Ropin.Inspection.Model.Entities;
- using Ropin.Inspection.Model.SearchModel.LGS;
- using Ropin.Inspection.Model.ViewModel.LGS;
- using Ropin.Inspection.Repository.LGS.Interface;
- using Ropin.Inspection.Service.LGS.Interface;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ropin.Inspection.Service.LGS
- {
- public class LargeScreenControlService: ILargeScreenControlService
- {
- private readonly ILargeScreenControlRepository _repository;
- private readonly IMapper _mapper;
- private readonly IClaimsAccessor _claims;
- private readonly InspectionDbContext _sqlDBContext;
- public LargeScreenControlService(IClaimsAccessor claims, InspectionDbContext sqlDBContext, ILargeScreenControlRepository repository, IMapper mapper)
- {
- _repository = repository;
- _mapper = mapper;
- _claims = claims;
- _sqlDBContext = sqlDBContext;
- }
- public async Task<IEnumerable<LargeScreenControlViewModel>> GetConditionAsync(LargeScreenControlSearch searchModel)
- {
- var list = await _repository.GetConditionAsync(searchModel);
- return list;
- }
- public async Task CreateOneAsync(LargeScreenControlViewModel viewModel)
- {
- var content = _mapper.Map<TLGS_LargeScreenControl>(viewModel);
- content.C_ID = Guid.NewGuid().ToString();
- content.C_CreateBy = _claims.ApiUserId.ToString();
- content.C_Creator = _claims.ApiUserName;
- content.D_CreateOn = DateTime.Now;
- content.C_Status = "1";
- _repository.Create(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("创建失败");
- }
- }
- public async Task UpdateAsync(LargeScreenControlViewModel viewModel, string Id)
- {
- var content = await _repository.GetByIdAsync(Id);
- if (content == null)
- {
- throw new Exception("没有此数据");
- }
- _mapper.Map(viewModel, content, typeof(LargeScreenControlViewModel), typeof(TLGS_LargeScreenControl));
- content.C_LastUpdatedBy = _claims.Linsence == null ? _claims.ApiUserId.ToString() : "6e864cbc-5252-11ec-8681-fa163e02b3e4";
- content.D_LastUpdatedOn = DateTime.Now;
- content.C_Modifier = _claims.ApiUserName;
- _repository.Update(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("更新失败");
- }
- }
- public async Task SaveAsync(List<LargeScreenControlViewModel> viewModel)
- {
- try
- {
- foreach (var item in viewModel)
- {
- if (string.IsNullOrEmpty(item.C_ID))
- {
- var content = _mapper.Map<TLGS_LargeScreenControl>(item);
- content.C_ID = Guid.NewGuid().ToString();
- content.C_CreateBy = _claims.ApiUserId.ToString();
- content.C_Creator = _claims.ApiUserName;
- content.D_CreateOn = DateTime.Now;
- content.C_Status = "1";
- _repository.Create(content);
- }
- else
- {
- var content = await _repository.GetByIdAsync(item.C_ID);
- if (content == null)
- {
- throw new Exception("没有此数据");
- }
- _mapper.Map(item, content, typeof(LargeScreenControlViewModel), typeof(TLGS_LargeScreenControl));
- content.C_LastUpdatedBy = _claims.Linsence == null ? _claims.ApiUserId.ToString() : "6e864cbc-5252-11ec-8681-fa163e02b3e4";
- content.D_LastUpdatedOn = DateTime.Now;
- content.C_Modifier = _claims.ApiUserName;
- _repository.Update(content);
- }
- }
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("创建失败");
- }
- }
- catch (Exception ex)
- {
- throw new Exception("创建异常");
- }
- }
- public async Task DeleteAsync(string id)
- {
- var content = await _repository.GetByIdAsync(id);
- if (content == null)
- {
- throw new Exception("数据库中没有此数据");
- }
- content.C_LastUpdatedBy = _claims.ApiUserId.ToString();
- content.D_LastUpdatedOn = DateTime.Now;
- content.C_Modifier = _claims.ApiUserName;
- content.C_Status = "0";
- _repository.Update(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("删除失败");
- }
- }
- public async Task DeleteByLargeScreenCodeAsync(string LargeScreenCode)
- {
- var content=await _repository.GetByConditionAsync(t=>t.C_LargeScreenCode == LargeScreenCode);
- if (content!=null&& content.Count()>0)
- {
- var result = await _repository.DeleteByLargeScreenCodeAsync(LargeScreenCode);
- if (!result)
- {
- throw new Exception("删除失败");
- }
- }
- }
- public async Task<LargeScreenControlViewModel> GetByIdAsync(string id)
- {
- LargeScreenControlSearch searchModel = new LargeScreenControlSearch();
- searchModel.IsPagination = false;
- searchModel.C_ID = id;
- var list = await _repository.GetConditionAsync(searchModel);
- return list?.FirstOrDefault();
- }
- public Task<bool> IsExistAsync(string id)
- {
- throw new NotImplementedException();
- }
- public Task<int> UpdateOneAsync(LargeScreenControlViewModel viewModel, params string[] fields)
- {
- throw new NotImplementedException();
- }
- }
- }
|