public async Task <ActionResult <FamilyViewModel> > CreateAsync(FamilyViewModel familyView) { if (ModelState.IsValid) { var family = _mapper.Map <FamilyViewModel, Family>(familyView); var createdFamily = await _service.CreateAsync(family); familyView.Id = createdFamily.Id; return(CreatedAtAction(nameof(GetByIdAsync), new { id = familyView.Id }, familyView)); } return(BadRequest(familyView)); }
public async Task <IActionResult> Create(CreateFamilyViewModel vm) { if (ModelState.IsValid) { var result = await _services.CreateAsync(_mapper.Map <FamilyDTO>(vm)); if (result.IsValid) { await _systemAuditService.AuditAsync(User.GetEmail(), _accessor.GetIp(), Operations.Insert, Tables.Family); return(RedirectToAction("Index", new { id = vm.HashIdEmployee })); } TempData["ErrorsList"] = result.ErrorsList; } return(View(vm)); }
public async Task <ActionResult> Create(FamilyViewModel model) { try { if (ModelState.IsValid) { var family = new Core.Model.Family() { Name = model.Name, IsActive = true }; var result = await _familyService.CreateAsync(family); return(RedirectToAction("Index")); } return(View("Edit", model)); } catch (Exception ex) { return(View("Edit", model)); } }