using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using wispro.sp.api.Controllers; using wispro.sp.entity; using wispro.sp.share; namespace wispro.sp.api.AppealHandler { public class ChangeDoPersonReviewer : IDoAppealObject { public void DoAppeal(AppealObject appeal, int appealRecordId, DbContext spContext) { bool isAggree = false; foreach (var iv in appeal.inputFieldValues) { if (iv.InputField == null) { iv.InputField = ((spDbContext)spContext).InputFields.FirstOrDefault(s => s.Id == iv.InputFieldId); } if (iv.InputField.FieldName == "审核意见" && iv.Value == "确认变更") { isAggree = true; break; } } if (isAggree) { var result = ((spDbContext)spContext).InputFieldValues.Where(f => f.AppealRecordId == appealRecordId && f.InputField.AppealState == 0).ToList(); string strOldPerson = ""; string strNewPerson = ""; foreach (var iv in result) { if (iv.InputField == null) { iv.InputField = ((spDbContext)spContext).InputFields.FirstOrDefault(s => s.Id == iv.InputFieldId); } if (iv.InputField.FieldName == "变更前处理人") { strOldPerson = iv.Value; continue; } if (iv.InputField.FieldName == "变更后处理人") { strNewPerson = iv.Value; continue; } } var appRecord = ((spDbContext)spContext).AppealRecords.FirstOrDefault(f => f.Id == appealRecordId); if(appRecord != null) { var itemStaffs = ((spDbContext)spContext).ItemStaffs.Include(p=>p.DoPerson).Where(s => s.ItemId == appRecord.ItemId.Value); var newStaff = ((spDbContext)spContext).Staffs.FirstOrDefault(s=>s.Name == strNewPerson.Trim()); if (newStaff != null) { bool oldPersonExist = false; foreach (ItemStaff staff in itemStaffs) { if (staff.DoPerson.Name == strOldPerson.Trim()) { ((spDbContext)spContext).Staffs.Remove(staff.DoPerson); oldPersonExist = true; break; } } if (oldPersonExist) { ((spDbContext)spContext).ItemStaffs.Add(new ItemStaff() { ItemId = appRecord.ItemId.Value, DoPersonId = newStaff.Id }); } else { throw new ApplicationException("变更前处理人不存在!"); } } else { throw new ApplicationException("变更后处理人不存在!"); } } //((spDbContext)spContext).PerformanceItems.Add(Item); //((spDbContext)spContext).SaveChanges(); } } } }