Exemplo n.º 1
0
        public async Task <ActionResult> New(Movement movement)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _service.Add(movement);

                    return(RedirectToAction(nameof(Index)));
                }
                catch (ModelValidationException e)
                {
                    ModelState.AddModelError("MovementValidation", e.Message);
                    return(View(await GetViewModel(movement)));
                }
                catch (DbUpdateException e)
                {
                    TempData["ErrorMessage"] = e.Message;
                    return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, e.Message));
                }
            }
            else
            {
                return(View(await GetViewModel(movement)));
            }
        }