コード例 #1
0
ファイル: HomeController.cs プロジェクト: Severius5/Lanyards
        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 }));
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: Severius5/Lanyards
 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
     });
 }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: Severius5/Lanyards
        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 }));
        }