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()); }
// [Authorize(Roles = "RemoveGroup")] public IActionResult RemoveGroup(int id) { if (id == 1) { return(BadRequest(Messages.CannotDelete)); } try { Group group = _abstractUnitOfWork.Repository <Group>().GetIQueryable(c => c.Id == id) .Include(c => c.GroupPrivilage) .Include(c => c.UserGroup) .FirstOrDefault(); if (group == null) { var message = Messages.NotFound; message.ActionName = "Remove Group"; message.ControllerName = "Group"; message.Message = "المجموعة غير موجودة"; return(NotFound(message)); } group.GroupPrivilage.ToList().ForEach(item => _abstractUnitOfWork.Remove(item, UserName())); group.UserGroup.ToList().ForEach(item => _abstractUnitOfWork.Remove(item, UserName())); _abstractUnitOfWork.Remove(group, UserName()); _abstractUnitOfWork.Commit(); return(Ok()); } catch (Exception) { return(BadRequestAnonymousError()); } }
public IActionResult Get() { var x = _abstractUnitOfWork.Repository <Students>().Get(c => c.Ssn == "S15001", c => c.StudentSubject).FirstOrDefault(); return(Ok()); }
public IActionResult Add(AddYearSystemDTO addYearSystemDTO) { try { addYearSystemDTO.Name = addYearSystemDTO.Name.Trim(); if (string.IsNullOrWhiteSpace(addYearSystemDTO.Name)) { var message = Messages.EmptyName; message.ActionName = "Add"; message.ControllerName = "Year System"; return(BadRequest(message)); } var settingId = addYearSystemDTO.Settings.Select(c => c.Id).ToList(); var mainSettinId = this._settingsRepositroy.Get().Select(c => c.Id).ToList(); // this number of role shoud replace in correct way if (settingId.Count < mainSettinId.Count()) { var message = new BadRequestErrors(); message.ActionName = "Add"; message.ControllerName = "Year System"; message.Message = "لم يتم إرسال كامل الإعدادات"; return(Conflict(message)); } settingId.Sort(); if (settingId.Except(mainSettinId).Any() || mainSettinId.Except(settingId).Any()) { var message = new BadRequestErrors() { ActionName = "Add", ControllerName = "Year System", Message = "لام يتم إرسال جميع الإعدادات او تم إرسال قيمة خاطئة" }; return(Conflict(message)); } if (addYearSystemDTO.IsMain) { var oldMain = _abstractUnitOfWork.Repository <YearSystem>().Get(c => c.IsMain).FirstOrDefault(); if (oldMain != null) { oldMain.IsMain = false; _abstractUnitOfWork.Repository <YearSystem>().Update(oldMain, UserName()); } } YearSystem yearSystem = _mapper.Map <YearSystem>(addYearSystemDTO); _abstractUnitOfWork.Add(yearSystem, UserName()); foreach (var item in addYearSystemDTO.Settings) { var setting = _settingsRepositroy.Find(item.Id); var settingYearSystem = new SettingYearSystem { YearSystem = yearSystem.Id, Setting = setting, Count = item.Count, Note = item.Note }; _abstractUnitOfWork.Add(settingYearSystem, UserName()); } _abstractUnitOfWork.Commit(); return(Ok(_mapper.Map <ResponseYearSystem>(yearSystem))); } catch (Exception ex) { return(BadRequestAnonymousError()); } }