Exemplo n.º 1
0
        public async Task <ActionResult <VisitTypeDto> > AddVisitType([FromBody] VisitTypeForCreationDto visitTypeForCreation)
        {
            var validationResults = new VisitTypeForCreationDtoValidator().Validate(visitTypeForCreation);

            validationResults.AddToModelState(ModelState, null);

            if (!ModelState.IsValid)
            {
                return(BadRequest(new ValidationProblemDetails(ModelState)));
                //return ValidationProblem();
            }

            var visitType = _mapper.Map <VisitType>(visitTypeForCreation);
            await _visitTypeRepository.AddVisitType(visitType);

            var saveSuccessful = await _visitTypeRepository.SaveAsync();

            if (saveSuccessful)
            {
                VisitType visitTypeFromRepo = await _visitTypeRepository.GetVisitTypeAsync(visitType.Id);

                var visitTypeDto = _mapper.Map <VisitTypeDto>(visitTypeFromRepo);
                var response     = new Response <VisitTypeDto>(visitTypeDto);

                return(CreatedAtRoute("GetVisitType",
                                      new { visitTypeDto.Id },
                                      response));
            }

            return(StatusCode(500));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([FromForm] VisitTypeViewModel visitTypeVM)
        {
            if (ModelState.IsValid)
            {
                var newVisitType = await _visitTypeRepo.AddVisitType(visitTypeVM.VisitType);

                TempData["message"]     = "Your data has been submitted successfully.";
                TempData["toasterType"] = ToasterType.success;

                //return RedirectToAction(nameof(Index));

                return(RedirectToAction(nameof(Edit), new { id = newVisitType.Id, returnUrl = visitTypeVM.ReturnUrl }));
            }

            TempData["message"]     = "A problem has been ocurred while submitting your data.";
            TempData["toasterType"] = ToasterType.info;

            return(View("Edit", VisitTypeViewModelFactory.Create(visitTypeVM.VisitType, visitTypeVM.ReturnUrl)));
        }