123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using AutoMapper;
- using Ropin.Inspection.Common.Accessor.Interface;
- using Ropin.Inspection.Model.Entities;
- using Ropin.Inspection.Model.ViewModel;
- using Ropin.Inspection.Repository.Interface;
- using Ropin.Inspection.Service.Interface;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ropin.Inspection.Service
- {
- public class TispContentGroupItemService : ITispContentGroupItemService
- {
- private readonly ITispContentGroupItemRepository _repository;
- private readonly IMapper _mapper;
- private readonly IClaimsAccessor _claims;
- public TispContentGroupItemService(IClaimsAccessor claims, ITispContentGroupItemRepository repository, IMapper mapper)
- {
- _repository = repository;
- _mapper = mapper;
- _claims = claims;
- }
- public async Task CreateContentGroupItemsAsync(IEnumerable<TispContentGroupItemCreateViewModel> items)
- {
-
- foreach (var item in items)
- {
- await _repository.DeleteByGroupIdAsync(item.G_ContentGroupCode);
- _repository.Create(new TISP_ContentGroupItem { G_ContentGroupCode = item.G_ContentGroupCode,G_ContentCode = item.G_ContentCode });
- }
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("创建失败");
- }
- }
- public async Task<IEnumerable<TispContentGroupItemViewModel>> GetContentGroupItemByGroupIdAsync(Guid groupId)
- {
- return await _repository.GetContentGroupItemByGroupIdAsync(groupId);
- }
- public async Task<IEnumerable<TISP_ContentGroupItem>> GetContentGroupItemByIdAsync(Guid groupId,Guid contentId)
- {
- var content = await _repository.GetByConditionAsync(g => g.G_ContentGroupCode == groupId && g.G_ContentCode == contentId);
- if (content.Count()==1&& content.First()==null)
- {
- content = null;
- }
- return content;
- }
- public async Task CreateOneAsync(TispContentGroupItemViewModel viewModel)
- {
- var content = _mapper.Map<TISP_ContentGroupItem>(viewModel);
- //content.G_CreateBy = _claims.ApiUserId;
- //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 DeleteAsync(Guid id)
- {
- var content = await _repository.GetByIdAsync(id);
- if (content == null)
- {
- throw new Exception("没有此巡检内容分组详情");
- }
- _repository.Delete(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("删除失败");
- }
- }
- public Task<IEnumerable<TispContentGroupItemViewModel>> GetAllAsync()
- {
- throw new NotImplementedException();
- }
- public Task<TispContentGroupItemViewModel> GetByIdAsync(Guid id)
- {
- throw new NotImplementedException();
- }
- public Task<bool> IsExistAsync(Guid id)
- {
- throw new NotImplementedException();
- }
- public Task<int> UpdateOneAsync(TispContentGroupItemViewModel viewModel, params string[] fields)
- {
- throw new NotImplementedException();
- }
- }
- }
|