public async Task <IActionResult> Create(ValorViewModel model) { if (ModelState.IsValid) { try { var valor = await _converterHelper.ToValorAsync(model, true); _context.Add(valor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, "El valor ya se encuentra registrado"); } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); } } } return(View(model)); }
public async Task <Valorestbl> ToValorAsync(ValorViewModel model, bool IsNew) { return(new Valorestbl { Val_Valor = model.Val_Valor, Val_FechaCreacion = DateTime.Today, Id = IsNew ? 0 : model.Id, Val_Estado = 'A', }); }
// GET: Valor/Create public IActionResult Create() { var model = new ValorViewModel { Val_FechaCreacion = DateTime.Today, Val_Estado = 'A', }; return(View(model)); }