123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using AutoMapper;
- using Ropin.Inspection.Common.Accessor.Interface;
- using Ropin.Inspection.Model.Entities;
- using Ropin.Inspection.Repository.Interface;
- using Ropin.Inspection.Service.Interface;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ropin.Inspection.Service
- {
- public class TasksQzServices : ITasksQzServices
- {
- private readonly ITasksQzRepository _repository;
- private readonly IMapper _mapper;
- private readonly IClaimsAccessor _claims;
- public TasksQzServices(IClaimsAccessor claims, ITasksQzRepository repository, IMapper mapper)
- {
- _repository = repository;
- _mapper = mapper;
- _claims = claims;
- }
- public async Task<IEnumerable<TasksQz>> GetAllAsync()
- {
- var pagedList = await _repository.GetAllAsync();
- return pagedList;
- }
- public async Task CreateOneAsync(TasksQz viewModel)
- {
- viewModel.CreateBy = _claims.ApiUserId;
- viewModel.CreateTime = DateTime.Now;
- viewModel.IsDeleted = false;
- _repository.Create(viewModel);
- 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("没有此任务");
- }
- content.IsDeleted = true;
- _repository.Update(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("删除失败");
- }
- }
- public async Task<TasksQz> GetByIdAsync(Guid id)
- {
- var content = await _repository.GetByIdAsync(id);
- return content;
- }
- public Task<bool> IsExistAsync(Guid id)
- {
- throw new NotImplementedException();
- }
- public Task<int> UpdateOneAsync(TasksQz viewModel, params string[] fields)
- {
- throw new NotImplementedException();
- }
- public async Task UpdateAsync(Guid id, TasksQz updateModel)
- {
- var content = await _repository.GetByIdAsync(id);
- if (content == null)
- {
- throw new Exception("没有此任务");
- }
- //content.C_LastUpdatedBy = _claims.ApiUserId;
- //content.D_LastUpdatedOn = DateTime.Now;
- //_mapper.Map(updateModel, content, typeof(TispRouteUpdateViewModel), typeof(TISP_Route));
- _repository.Update(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("更新失败");
- }
- }
- //public async Task<IEnumerable<TasksQz>> GetContentsConditionAsync(Expression<Func<T, bool>> whereLambda, string ordering, bool IsPagination, int pageIndex, int pageSize)
- //{
- // var predicate = PredicateBuilder.New<TasksQz>(true);//查询条件,推荐后台使用这种方式灵活筛选
- // #region 添加条件查询
- // predicate = predicate.And(i => i.C_Status.Equals("1"));
- // if (!string.IsNullOrEmpty(searchModel.C_Name))
- // {
- // predicate = predicate.And(i => i.C_Name.Contains(searchModel.C_Name));
- // }
- // #endregion
- // var list = await _repository.GetPageAsync(predicate, "C_Name,-D_CreateOn", searchModel.IsPagination, searchModel.PageIndex, searchModel.PageSize);
- // searchModel.TotalCount = list.Totals;
- // var dtoList = _mapper.Map<List<TISP_Content>, List<TispContentViewModel>>(list.Rows);
- // return dtoList;
- //}
- }
- }
|