示例#1
0
        public Results.GenericResult Put(int id, [FromBody] TodoDto model)
        {
            var result = new Results.GenericResult();

            var validatorResult = validator.Validate(model);

            if (validatorResult.IsValid)
            {
                try
                {
                    result.Success = appService.Update(model);
                    if (!result.Success)
                    {
                        throw new Exception($"Todo {id} can't be updated");
                    }
                }
                catch (Exception ex)
                {
                    result.Errors = new string[] { ex.Message };
                }
            }
            else
            {
                result.Errors = validatorResult.GetErrors();
            }


            return(result);
        }
示例#2
0
        public IActionResult Put([FromBody] TodoViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var todoViewModel = _todoAppService.Update(model);

            return(Ok(todoViewModel));
        }
示例#3
0
 public void Put(int id, [FromBody] TodoViewModel value)
 {
     try
     {
         if (ModelState.IsValid)
         {
             value.Id = id;
             _todoApp.Update(Mapper.Map <TodoViewModel, Todo>(value));
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#4
0
 public async Task <IActionResult> Put([FromBody] TodoAppViewModel todoAppViewModel)
 {
     return(ModelState.IsValid ? CustomResponse(await _todoAppService.Update(todoAppViewModel))
         : CustomResponse(todoAppViewModel));
 }
示例#5
0
 public bool Put(int id, [FromBody] TodoVM todo)
 {
     return(appService.Update(todo));
 }