コード例 #1
0
        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"));
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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());
        }