public async Task <IActionResult> Create(LanyardViewModel model) { if (!ModelState.IsValid) { return(View("ModifyLanyard", model)); } var id = await _lanyardsService.CreateLanyard(ConvertToDto(model)); return(RedirectToAction(nameof(Details), new { id })); }
private Lanyard ConvertToDto(LanyardViewModel vm) { return(new Lanyard { BackImgAddress = vm.BackImgUrl, CreationDate = vm.CreationDate, Description = vm.Description, FrontImgAddress = vm.FrontImgUrl, Id = vm.Id, Text = vm.Text, Type = (LanyardType)vm.Type }); }
public async Task <IActionResult> Edit(LanyardViewModel model) { if (!ModelState.IsValid) { return(View("ModifyLanyard", model)); } var isSuccess = await _lanyardsService.UpdateLanyard(ConvertToDto(model)); if (!isSuccess) { ModelState.AddModelError(string.Empty, "Could not update lanyard"); return(View("ModifyLanyard", model)); } return(RedirectToAction(nameof(Details), new { model.Id })); }