public async Task <IActionResult> Create([FromForm] VisitViewModel visitVm) { if (ModelState.IsValid) { visitVm.VisitTypes = default; visitVm.Employees = default; visitVm.Offices = default; visitVm.RegisterControls = default; visitVm.VisitStates = default; //visitVm.VisitPersons = default; var newVisit = await _visitRepo.AddVisit(visitVm.Visit); TempData["message"] = "Your data has been submitted successfully."; TempData["toasterType"] = ToasterType.success; //return RedirectToAction(nameof(Index)); return(RedirectToAction(nameof(Edit), new { id = newVisit.Id, returnUrl = visitVm.ReturnUrl })); } TempData["message"] = "A problem has been ocurred while submitting your data."; TempData["toasterType"] = ToasterType.info; return(View("Edit", VisitViewModelFactory.Create(visitVm.Visit, visitVm.ReturnUrl, VisitTypes, Employees, Offices, RegisterControls, VisitStates))); }
public async Task <ActionResult <VisitDto> > AddVisit([FromBody] VisitForCreationDto visitForCreation) { var validationResults = new VisitForCreationDtoValidator().Validate(visitForCreation); validationResults.AddToModelState(ModelState, null); if (!ModelState.IsValid) { return(BadRequest(new ValidationProblemDetails(ModelState))); //return ValidationProblem(); } var visit = _mapper.Map <Visit>(visitForCreation); await _visitRepo.AddVisit(visit); var saveSuccessful = await _visitRepo.SaveAsync(); if (saveSuccessful) { var visitFromRepo = await _visitRepo.GetVisitAsync(visit.Id); var visitDto = _mapper.Map <VisitDto>(visitFromRepo); var response = new Response <VisitDto>(visitDto); return(CreatedAtRoute("GetVisit", new { visitDto.Id }, response)); } return(StatusCode(500)); }
public async Task <AddVisitDto> AddVisit(AddVisitDto addVisitDto) { var visitToAdd = _mapper.Map <Visit>(addVisitDto); var addedVisit = await _visitRepository.AddVisit(visitToAdd); var result = _mapper.Map <AddVisitDto>(addedVisit); return(result); }
public ActionResult Create([Bind(Include = "VisitID,DoctorID,PatientID,DateOfVisit,Description,Price")] Visit visit) { ViewBag.DoctorID = new SelectList(_doctorRepository.GetDoctors(), "Id", "FullName"); ViewBag.PatientID = new SelectList(_patientRepository.GetPatients(), "Id", "FullName"); if (ModelState.IsValid) { _visitRepository.AddVisit(visit); _visitRepository.Save(); return(RedirectToAction("Index")); } return(View(visit)); }