コード例 #1
0
        public ActionResult AddEditProduct(Int32?ProductId)
        {
            var model = new AddEditProductViewModel();

            model.Fill(CargarDatosContext(), ProductId);
            return(View(model));
        }
コード例 #2
0
        public ActionResult AddEditProduct(AddEditProductViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    model.Fill(CargarDatosContext(), model.ProductId);
                    TryUpdateModel(model);
                    PostMessage(MessageType.Error);
                    return(View(model));
                }

                Product product = null;

                if (model.ProductId.HasValue)
                {
                    product = context.Product.FirstOrDefault(x => x.ProductId == model.ProductId);
                }
                else
                {
                    product       = new Product();
                    product.State = ConstantHelpers.ESTADO.ACTIVO;
                    context.Product.Add(product);
                }

                product.SubFamilyId            = model.SubFamilyId.Value;
                product.TypeExistenceId        = model.TypeExistenceId;
                product.MeasureUnitPrimaryId   = model.MeasureUnitPrimaryId;
                product.MeasureUnitSecondaryId = model.MeasureUnitSecondaryId;
                product.InternalCode           = model.InternalCode;
                product.IsActive                    = model.IsActive;
                product.Barcode                     = model.Barcode;
                product.Color                       = model.Color;
                product.InvoiceDescription          = model.InvoiceDescription;
                product.LocalDescription            = model.LocalDescription;
                product.DesignName                  = model.DesignName;
                product.DesignNumber                = model.DesignNumber;
                product.LotNumberPurchase           = model.LotNumberPurchase;
                product.TaxPercentageAdvalorenId    = model.TaxPercentageAdvalorenId;
                product.TaxPercentageAffectionIGVId = model.TaxPercentageAffectionIGVId;
                product.TaxPercentagePerceptionId   = model.TaxPercentagePerceptionId;
                product.TaxPercentageDetractionId   = model.TaxPercentageDetractionId;
                product.IsSale                      = model.IsSale;
                product.IsPurchase                  = model.IsPurchase;
                product.OtherMeasureUnit            = model.OtherMeasureUnit;
                product.ConversionFactor            = model.ConversionFactor;
                product.MinimumStock                = model.MinimumStock;
                product.MinimumLot                  = model.MinimumLot;

                context.SaveChanges();
                PostMessage(MessageType.Success);

                return(RedirectToAction("ListProduct", "Master"));
            }
            catch (Exception ex)
            {
                PostMessage(MessageType.Error);
                model.Fill(CargarDatosContext(), model.ProductId);
                return(View(model));
            }
        }