using AutoMapper; using DTO; using DTO.Models; using IServices; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using zhengcaioa.IService; using zhengcaioa.Models; namespace Services { public class WfApplytypeService : IWfApplytypeService { private readonly zhengcaioaContext _context; private readonly IMapper _mapper; public WfApplytypeService(zhengcaioaContext context, IMapper mapper) { _context = context; _mapper = mapper; } public ResultEntity save(WfApplytypeDTO dto) { ResultEntity resultEntity = new ResultEntity(); try { var model = _mapper.Map(dto); if (String.IsNullOrEmpty(model.Id)) { model.Id = Guid.NewGuid().ToString(); _context.WfApplytypes.Add(model); } else { var updateWfApplytype = _context.WfApplytypes.Find(model.Id); updateWfApplytype.Applyno = model.Applyno; updateWfApplytype.Applytiye = model.Applytiye; updateWfApplytype.Sort = model.Sort; updateWfApplytype.Deelurl = model.Deelurl; updateWfApplytype.RecStatus = model.RecStatus; // updateWfApplytype.Creater = WfApplytype.Creater; //updateWfApplytype.Createtime = WfApplytype.Createtime; updateWfApplytype.Modifier = model.Modifier; updateWfApplytype.Modifytime = model.Modifytime; } _context.SaveChanges(); resultEntity.ReturnID = model.Id; resultEntity.Result = true; } catch (Exception ex) { resultEntity.Result = false; resultEntity.Message = "保存失败,请联系管理员"; } return resultEntity; } public WfApplytypeDTO Get(string id) { WfApplytype entity = _context.WfApplytypes.Find(id); if (entity.RecStatus != "A") { entity = new WfApplytype(); } var WfApplytypeDTO = _mapper.Map(entity); return WfApplytypeDTO; } public ResultDataEntity SearchByPaging(WfApplytypeDTOSearch searchEntity) { ResultDataEntity data = new ResultDataEntity(); List list = new List(); ///WfApplytypes var query = (from a in _context.WfApplytypes where a.RecStatus == "A" && (string.IsNullOrWhiteSpace(searchEntity.Applytiye) || a.Applytiye.Contains(searchEntity.Applytiye.Trim())) select new WfApplytypeDTO { Id = a.Id, Applyno = a.Applyno, Applytiye = a.Applytiye, Sort = a.Sort, Deelurl = a.Deelurl, Creater = a.Creater, Createtime = a.Createtime, RecStatus = a.RecStatus, Modifier = a.Modifier, Modifytime = a.Modifytime, } ).OrderBy(x => x.Sort).ToList(); //if (searchEntity.totalrows == 0) searchEntity.totalrows = query.Count(); var lianlist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList(); data.LoadData(searchEntity, lianlist); return data; } public ResultEntity ModifyStatus(string id, string userid) { ResultEntity result = new ResultEntity(); result.Result = true; var model = _context.WfApplytypes.Find(id); if (model != null) { model.RecStatus = "D"; model.Modifier = userid; model.Modifytime = DateTime.Now; _context.SaveChanges(); } return result; } /// /// 获取所有有效流程类型 /// /// public List GetList() { var listRole = _context.WfApplytypes.Where(r => r.RecStatus == "A").OrderBy(x=>x.Sort).ToList(); var list = _mapper.Map>(listRole); return list; } } }