Пример #1
0
        public ActionResult Editar(int?id, ToDoViewModel toDoViewModel)
        {
            if (ModelState.IsValid)
            {
                var toDo = Mapper.Map <ToDoViewModel, ToDo>(toDoViewModel);
                toDo.UpdateDate = DateTime.Now;
                _toDoAppService.Update(toDo);
                return(RedirectToAction("index"));
            }

            return(PartialView(toDoViewModel));
        }
Пример #2
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);
        }
Пример #3
0
        public async Task <IActionResult> Update([FromBody] UpdateToDoRequest request)
        {
            try
            {
                var result = await _appService.Update(request);

                return(Response(result));
            }
            catch (Exception ex)
            {
                _logger.LogError("ERROR: {message}", ex.Message);
                return(BadRequest(ex));
            }
        }
Пример #4
0
 public bool Put(int id, [FromBody] ToDoDTO model)
 {
     return(_appService.Update(model));
 }