public IActionResult Update([FromBody] UpdateSubjectDto UpdateSubjectDto) { var subject = _abstractUnitOfWork.Repository <Subjects>().Find(UpdateSubjectDto.Id); if (subject == null) { return(NotFound()); } if (subject.StudySemesterId != UpdateSubjectDto.StudySemesterId) { var dependancySubject = _abstractUnitOfWork.Repository <DependenceSubject>().Get(c => c.SubjectId == UpdateSubjectDto.Id || c.DependsOnSubjectId == UpdateSubjectDto.Id).ToList(); dependancySubject.ForEach(ds => { _abstractUnitOfWork.Remove(ds, SentencesHelper.System); }); var equivalentSubject = _abstractUnitOfWork.Repository <EquivalentSubject>().Get(c => c.FirstSubject == UpdateSubjectDto.Id || c.SecoundSubject == UpdateSubjectDto.Id).ToList(); equivalentSubject.ForEach(es => { _abstractUnitOfWork.Remove(es, SentencesHelper.System); }); } _mapper.Map <UpdateSubjectDto, Subjects>(UpdateSubjectDto, subject); _abstractUnitOfWork.Update(subject, UserName()); return(Ok()); }
public IActionResult UpdateYearSystem(int Id, [FromBody] AddYearSystemDTO updateYearSystem) { try { var orginalYearSystem = _abstractUnitOfWork.Repository <YearSystem>().Get(c => c.Id == Id, c => c.SettingYearSystem, c => c.Years).SingleOrDefault(); if (orginalYearSystem == null) { var message = Messages.NotFound; message.ActionName = "Update"; message.ControllerName = "YearSystem"; return(NotFound(message)); } if (orginalYearSystem.Years.Count > 0) { var newSettingList = updateYearSystem.Settings; var oldSettingList = orginalYearSystem.SettingYearSystem.ToList(); for (int i = 0; i < oldSettingList.Count; i++) { var settingId = oldSettingList[i].SettingId; var newSetting = newSettingList.Where(c => c.Id == settingId).SingleOrDefault(); if (newSetting == null) { //لم يتم إرسال كامل الإعدادات return(Conflict()); } if (newSetting.Count != oldSettingList[i].Count) { return(Conflict()); } oldSettingList[i].Note = newSetting.Note; _abstractUnitOfWork.Update(oldSettingList[i], UserName()); } } else { var newSettingList = updateYearSystem.Settings; var oldSettingList = orginalYearSystem.SettingYearSystem.ToList(); for (int i = 0; i < oldSettingList.Count; i++) { var settingId = oldSettingList[i].SettingId; var newSetting = newSettingList.Where(c => c.Id == settingId).SingleOrDefault(); if (newSetting == null) { //لم يتم إرسال كامل الإعدادات return(Conflict()); } oldSettingList[i].Count = newSetting.Count; oldSettingList[i].Note = newSetting.Note; _abstractUnitOfWork.Update(oldSettingList[i], UserName()); } } orginalYearSystem.IsMain = updateYearSystem.IsMain; orginalYearSystem.Name = updateYearSystem.Name; orginalYearSystem.Note = updateYearSystem.Note; _abstractUnitOfWork.Update(orginalYearSystem, UserName()); _abstractUnitOfWork.Commit(); return(Ok()); } catch { return(BadRequestAnonymousError()); } }