public ActionResult Save(EditProductViewModel model, string command)
        {
            string cmd = command.ToLower();

            if (cmd == "save" || cmd == "saveandexit")
            {
                if (ModelState.IsValid)
                {
                    // Merge the properties on this page with those already in the database
                    var product = ProductService.FindProductModel(model.Product.Id, null, null, false);
                    if (product != null)
                    {
                        product.InnerQuantity  = model.Product.InnerQuantity;
                        product.OuterQuantity  = model.Product.OuterQuantity;
                        product.MasterQuantity = model.Product.MasterQuantity;
                        product.PackingTypeId  = model.Product.PackingTypeId;

                        product.Length = model.Product.Length;
                        product.Width  = model.Product.Width;
                        product.Height = model.Product.Height;
                        product.Weight = model.Product.Weight;

                        product.PackedLength = model.Product.PackedLength;
                        product.PackedWidth  = model.Product.PackedWidth;
                        product.PackedHeight = model.Product.PackedHeight;
                        product.PackedWeight = model.Product.PackedWeight;

                        product.InnerLength = model.Product.InnerLength;
                        product.InnerWidth  = model.Product.InnerWidth;
                        product.InnerHeight = model.Product.InnerHeight;
                        product.InnerWeight = model.Product.InnerWeight;

                        product.MasterLength = model.Product.MasterLength;
                        product.MasterWidth  = model.Product.MasterWidth;
                        product.MasterHeight = model.Product.MasterHeight;
                        product.MasterWeight = model.Product.MasterWeight;

                        product.UnitCBM          = model.Product.UnitCBM;
                        product.WeightPerProduct = model.Product.WeightPerProduct;
                    }
                    else
                    {
                        product = model.Product;
                    }

                    var modelError = ProductService.ValidateModel(product);
                    if (!modelError.IsError)
                    {
                        modelError = ProductService.InsertOrUpdateProduct(product, CurrentUser, model.LGS);
                    }

                    if (modelError.IsError)
                    {
                        prepareEditModel(model, product.Id);
                        model.SetErrorOnField(ErrorIcon.Error,
                                              modelError.Message,
                                              "Product_" + modelError.FieldName);
                        return(View("Edit", model));
                    }
                    else
                    {
                        if (cmd == "saveandexit")
                        {
                            return(RedirectToAction("Products", "Products", new { BrandId = product.BrandId }));
                        }
                        else
                        {
                            model.SetErrorOnField(ErrorIcon.Information, EvolutionResources.infChangesSuccessfullySaved, "", null, null, null, null, true);
                            return(RedirectToAction("Edit", new { Id = product.Id }));
                        }
                    }
                }
                else
                {
                    prepareEditModel(model, model.Product.Id);
                    return(View("Edit", model));
                }
            }
            else
            {
                return(RedirectToAction("Products", "Products", new { BrandId = model.Product.BrandId }));
            }
        }
        public ActionResult Save(EditProductViewModel model, string command)
        {
            string cmd = command.ToLower();

            if (cmd == "save" || cmd == "saveandexit")
            {
                if (ModelState.IsValid)
                {
                    // Merge the properties on this page with those already in the database
                    var product = ProductService.FindProductModel(model.Product.Id, null, null, false);
                    if (product != null)
                    {
                        product.CountryOfOriginId  = model.Product.CountryOfOriginId;
                        product.PrimarySupplierId  = model.Product.PrimarySupplierId;
                        product.ManufacturerId     = model.Product.ManufacturerId;
                        product.SupplierItemNumber = model.Product.SupplierItemNumber;
                        product.SupplierItemName   = model.Product.SupplierItemName;
                    }
                    else
                    {
                        product = model.Product;
                    }

                    var modelError = ProductService.ValidateModel(product);
                    if (!modelError.IsError)
                    {
                        modelError = ProductService.InsertOrUpdateProduct(product, CurrentUser, model.LGS);
                    }

                    if (modelError.IsError)
                    {
                        prepareEditModel(CurrentCompany, model, product.Id);
                        model.SetErrorOnField(ErrorIcon.Error,
                                              modelError.Message,
                                              "Product_" + modelError.FieldName);
                        return(View("Edit", model));
                    }
                    else
                    {
                        if (cmd == "saveandexit")
                        {
                            return(RedirectToAction("Products", "Products", new { BrandId = product.BrandId }));
                        }
                        else
                        {
                            model.SetErrorOnField(ErrorIcon.Information, EvolutionResources.infChangesSuccessfullySaved, "", null, null, null, null, true);
                            return(RedirectToAction("Edit", new { Id = product.Id }));
                        }
                    }
                }
                else
                {
                    prepareEditModel(CurrentCompany, model, model.Product.Id);
                    return(View("Edit", model));
                }
            }
            else
            {
                return(RedirectToAction("Products", "Products", new { BrandId = model.Product.BrandId }));
            }
        }
        public ActionResult Save(EditProductViewModel model, string command)
        {
            string cmd = command.ToLower();

            if (cmd == "save" || cmd == "saveandexit")
            {
                if (ModelState.IsValid)
                {
                    // Merge the properties on this page with those already in the database
                    var product = ProductService.FindProductModel(model.Product.Id, null, null, false);
                    if (product != null)
                    {
                        product.AdditionalCategory.CategoryId    = model.Product.AdditionalCategory.CategoryId;
                        product.AdditionalCategory.FormatId      = model.Product.AdditionalCategory.FormatId;
                        product.AdditionalCategory.FormatTypeId  = model.Product.AdditionalCategory.FormatTypeId;
                        product.AdditionalCategory.SeasonId      = model.Product.AdditionalCategory.SeasonId;
                        product.AdditionalCategory.PackingTypeId = model.Product.AdditionalCategory.PackingTypeId;
                        product.AdditionalCategory.KidsAdultsId  = model.Product.AdditionalCategory.KidsAdultsId;
                        product.AdditionalCategory.AgeGroupId    = model.Product.AdditionalCategory.AgeGroupId;
                        product.AdditionalCategory.DvlptTypeId   = model.Product.AdditionalCategory.DvlptTypeId;
                        product.AdditionalCategory.PCProductId   = model.Product.AdditionalCategory.PCProductId;
                        product.AdditionalCategory.PCDvlptId     = model.Product.AdditionalCategory.PCDvlptId;
                    }
                    else
                    {
                        product = model.Product;
                    }

                    var modelError = ProductService.ValidateModel(product);
                    if (!modelError.IsError)
                    {
                        modelError = ProductService.InsertOrUpdateProduct(product, CurrentUser, model.LGS);
                    }

                    if (modelError.IsError)
                    {
                        prepareEditModel(model, product.Id);
                        model.SetErrorOnField(ErrorIcon.Error,
                                              modelError.Message,
                                              "Product_AdditionalCategory_" + modelError.FieldName);
                        return(View("Edit", model));
                    }
                    else
                    {
                        if (cmd == "saveandexit")
                        {
                            return(RedirectToAction("Products", "Products", new { BrandId = product.BrandId }));
                        }
                        else
                        {
                            model.SetErrorOnField(ErrorIcon.Information, EvolutionResources.infChangesSuccessfullySaved, "", null, null, null, null, true);
                            return(RedirectToAction("Edit", new { Id = product.Id }));
                        }
                    }
                }
                else
                {
                    prepareEditModel(model, model.Product.Id);
                    return(View("Edit", model));
                }
            }
            else
            {
                return(RedirectToAction("Products", "Products", new { BrandId = model.Product.BrandId }));
            }
        }
Beispiel #4
0
        public ActionResult Save(EditProductViewModel model, string command)
        {
            string cmd = command.ToLower();

            if (cmd == "save" || cmd == "saveandexit" || cmd == "approve")
            {
                if (ModelState.IsValid)
                {
                    // Merge the properties on this page with those already in the database
                    var product = ProductService.FindProductModel(model.Product.Id, null, null, false);
                    if (product != null)
                    {
                        product.PrimaryMediaId        = model.Product.PrimaryMediaId;
                        product.ItemName              = model.Product.ItemName;
                        product.ProductAvailabilityId = model.Product.ProductAvailabilityId;
                        product.ProductStatus         = model.Product.ProductStatus;
                        product.ItemNameLong          = model.Product.ItemNameLong;
                        product.ItemNameFormat        = model.Product.ItemNameFormat;
                        product.ItemNameStyle         = model.Product.ItemNameStyle;
                        product.ItemNumber            = model.Product.ItemNumber;
                        product.AB               = model.Product.AB;
                        product.Set              = model.Product.Set;
                        product.ItemDescription  = model.Product.ItemDescription;
                        product.MaterialId       = model.Product.MaterialId;
                        product.BarCode          = model.Product.BarCode;
                        product.InnerBarCode     = model.Product.InnerBarCode;
                        product.MasterBarCode    = model.Product.MasterBarCode;
                        product.HSCode           = model.Product.HSCode;
                        product.WebCategoryId    = model.Product.WebCategoryId;
                        product.WebSubCategoryId = model.Product.WebSubCategoryId;
                        if (model.Approved == 1)
                        {
                            product.ApprovedById   = CurrentUser.Id;
                            product.ApprovedDate   = DateTimeOffset.Now;
                            product.ApprovedByText = CurrentUser.FullName;
                        }
                    }
                    else
                    {
                        product = model.Product;
                    }

                    var modelError = ProductService.InsertOrUpdateProduct(product, CurrentUser, model.LGS);
                    if (modelError.IsError)
                    {
                        prepareEditModel(model, product.Id);
                        model.SetErrorOnField(ErrorIcon.Error,
                                              modelError.Message,
                                              "Product_" + modelError.FieldName);
                        return(View("Edit", model));
                    }
                    else
                    {
                        switch (cmd)
                        {
                        case "saveandexit":
                            return(RedirectToAction("Products", "Products", new { BrandId = product.BrandId }));

                        case "approve":
                            model.SetErrorOnField(ErrorIcon.Information, EvolutionResources.infProductHasBeenApproved, "", null, null, null, null, true);
                            return(RedirectToAction("Edit", new { Id = product.Id }));

                        default:
                            model.SetErrorOnField(ErrorIcon.Information, EvolutionResources.infChangesSuccessfullySaved, "", null, null, null, null, true);
                            return(RedirectToAction("Edit", new { Id = product.Id }));
                        }
                    }
                }
                else
                {
                    prepareEditModel(model, model.Product.Id);
                    return(View("Edit", model));
                }
            }
            else
            {
                return(RedirectToAction("Products", "Products", new { BrandId = model.Product.BrandId }));
            }
        }