Ejemplo n.º 1
0
        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 }));
        }
Ejemplo n.º 2
0
 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
     });
 }
Ejemplo n.º 3
0
        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 }));
        }