public async Task <IActionResult> Update(ColorValidation colorValidation) { if (colorValidation == null) { return(BadRequest(404)); } if (ModelState.IsValid) { var color = new Color { Codigo = colorValidation.Codigo, Descripcion = colorValidation.Descripcion }; var spec = new ColorConNumeroSpecification(color.Codigo); var colorValido = await _unitOfWork.Repository <Color>().GetEntityWithSpec(spec); if (colorValido != null) { colorValido.Codigo = color.Codigo; colorValido.Descripcion = color.Descripcion; _unitOfWork.Repository <Color>().Update(colorValido); await _unitOfWork.Complete(); _unitOfWork.Dispose(); return(RedirectToAction("Index")); } } return(RedirectToAction("Edit")); }
public async Task <IActionResult> Crear(ColorValidation colorValidation) { if (colorValidation == null) { return(BadRequest(404)); } if (ModelState.IsValid) { var color = new Color { Codigo = colorValidation.Codigo, Descripcion = colorValidation.Descripcion }; var spec = new ColorConNumeroSpecification(color.Codigo); var colorValido = await _unitOfWork.Repository <Color>().GetEntityWithSpec(spec); if (colorValido == null) { _unitOfWork.Repository <Color>().Add(color); await _unitOfWork.Complete(); _unitOfWork.Dispose(); return(RedirectToAction("Index")); } ModelState.AddModelError("", "El codigo ya existe, ingrese uno nuevo"); } return(View()); }
public async Task <IActionResult> Edit(int codigoColor) { if (ModelState.IsValid) { var spec = new ColorConNumeroSpecification(codigoColor); var colorValido = await _unitOfWork.Repository <Color>().GetEntityWithSpec(spec); if (colorValido != null) { var colorValidation = new ColorValidation { Codigo = colorValido.Codigo, Descripcion = colorValido.Descripcion }; return(View(colorValidation)); } } return(View()); }