コード例 #1
0
 public async Task <IActionResult> Edit(int id, [Bind("Name")] CategoryViewModel category)
 {
     category.Id = id;
     if (ModelState.IsValid)
     {
         try
         {
             await _dataService.Update(_mapper.Map <CategoryVO>(category));
         }
         catch (KeyNotFoundException)
         {
             return(NotFound());
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(category));
 }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, TodoItemViewModel todoItem, List <int> tagId)
        {
            todoItem.Id = id;
            if (ModelState.IsValid)
            {
                try
                {
                    await _todoItemdataService.Update(_mapper.Map <TodoItemVO>(todoItem));

                    await _itemTagService.Update(id, tagId);
                }
                catch (KeyNotFoundException)
                {
                    return(NotFound());
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ViewData["Categories"] = _mapper.Map <IEnumerable <CategoryViewModel> >(await _categorydataService.GetAll());
                ViewData["Tags"]       = _mapper.Map <IEnumerable <TagViewModel> >(await _tagdataService.GetAll());
                return(View(todoItem));
            }
        }