public async Task AddPrecautionAsync(PrecautionDTO precautionDTO, User user) { await CheckIfAdminAsync(user); var Precaution = _mapper.Map <PrecautionDTO, Precaution>(precautionDTO); await _repoWrapper.Precaution.CreateAsync(Precaution); await _repoWrapper.SaveAsync(); }
public async Task <IActionResult> GetPrecaution(int id) { PrecautionDTO Precaution = await _precautionService.GetPrecautionAsync(id); if (Precaution == null) { return(NotFound()); } return(Ok(Precaution)); }
public async Task <IActionResult> AddPrecaution(PrecautionDTO PrecautionDTO) { if (ModelState.IsValid) { await _precautionService.AddPrecautionAsync(PrecautionDTO, await _userManager.GetUserAsync(User)); return(NoContent()); } return(BadRequest(ModelState)); }
public async Task ChangePrecautionAsync(PrecautionDTO precautionDTO, User user) { await CheckIfAdminAsync(user); var Precaution = await _repoWrapper.Precaution.GetFirstAsync(x => x.Id == precautionDTO.Id); Precaution.Name = precautionDTO.Name; _repoWrapper.Precaution.Update(Precaution); await _repoWrapper.SaveAsync(); }
public async Task <IActionResult> EditPrecaution(PrecautionDTO PrecautionDTO) { if (ModelState.IsValid) { try { await _precautionService.ChangePrecautionAsync(PrecautionDTO, await _userManager.GetUserAsync(User)); return(NoContent()); } catch (NullReferenceException) { return(NotFound()); } } return(BadRequest(ModelState)); }