//[Authorize(Roles = "AddSubjectType")] public IActionResult Add([FromBody] AddSubjectTypeDTO addSubjectTypeDTO) { try { addSubjectTypeDTO.Name = addSubjectTypeDTO.Name.Trim(); if (string.IsNullOrWhiteSpace(addSubjectTypeDTO.Name)) { var message = Messages.EmptyName; message.ActionName = "Add"; message.ControllerName = "Subject Type"; return(BadRequest(message)); } if (_subjectTypeRepositroy.Get(c => c.Name == addSubjectTypeDTO.Name).FirstOrDefault() != null) { var message = Messages.Exist; message.ActionName = "Add"; message.ControllerName = "Subject Type"; return(Conflict(message)); } var subjectType = _mapper.Map <SubjectType>(addSubjectTypeDTO); _subjectTypeRepositroy.Add(subjectType, UserName()); _subjectTypeRepositroy.Save(); return(Ok(subjectType)); } catch { return(BadRequestAnonymousError()); } }
public IActionResult UpdateSubjectType(int id, [FromBody] AddSubjectTypeDTO updateSubjectDTO) { try { updateSubjectDTO.Name = updateSubjectDTO.Name.Trim(); var orginalSubjectType = _subjectTypeRepositroy.Find(id); if (orginalSubjectType == null) { var message = Messages.NotFound; message.ActionName = "Update Subject Type"; message.ControllerName = "Subject Type"; message.Message = "نوع المادة غير موجود"; return(NotFound(message)); } orginalSubjectType = _mapper.Map(updateSubjectDTO, orginalSubjectType); _subjectTypeRepositroy.Update(orginalSubjectType, UserName()); _subjectTypeRepositroy.Save(); return(Ok()); } catch { return(BadRequestAnonymousError()); } }