コード例 #1
0
        public async Task <ActionResult> Update(int id, CategoryDtos categoryDtos)
        {
            try
            {
                var exist = await this._categoryRepositry.GetOneAsyn(id);

                if (exist == null)
                {
                    return(NotFound($"No Category found with this id {id}."));
                }

                var category = _mapper.Map <Category>(categoryDtos);

                var data = await _categoryRepositry.Update(id, category);

                if (data == false)
                {
                    return(BadRequest("This category could not be updated."));
                }

                return(Ok("This category has been updated."));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #2
0
 public ActionResult Edit(Category category)
 {
     if (ModelState.IsValid)
     {
         categoryService.Update(category);
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }