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();
        }
Exemple #2
0
        public async Task <IActionResult> GetPrecaution(int id)
        {
            PrecautionDTO Precaution = await _precautionService.GetPrecautionAsync(id);

            if (Precaution == null)
            {
                return(NotFound());
            }
            return(Ok(Precaution));
        }
Exemple #3
0
        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();
        }
Exemple #5
0
        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));
        }