コード例 #1
0
        public async Task <ActionResult> Edit(ProductViewModel model, string savecontinue)
        {
            if (ModelState.IsValid)
            {
                bool continueEditing = false;
                if (!String.IsNullOrWhiteSpace(savecontinue))
                {
                    continueEditing = true;
                }

                //basic setting
                //this will be removed
                DefaultValues(model);

                //product
                Product product = new Product();
                product = ProductMapping.ViewToModel(model);

                TEBApiResponse apiResponse = await Post <Product>("/Product/UpdateProduct", product);

                if (apiResponse.IsSuccess)
                {
                    if (continueEditing)
                    {
                        //selected tab
                        //SaveSelectedTabName();
                        int productid = JsonConvert.DeserializeObject <int>(Convert.ToString(apiResponse.Data));
                        return(RedirectToAction("Edit", new { id = productid }));
                    }
                    return(RedirectToAction("Index"));
                }
            }
            //If we got this far, something failed, redisplay form
            PrepareProductModel(model, null, false, true);
            //PrepareAclModel(model, null, true);
            //PrepareStoresMappingModel(model, null, true);
            //PrepareCategoryMappingModel(model, null, true);
            //PrepareManufacturerMappingModel(model, null, true);
            //PrepareDiscountMappingModel(model, null, true);

            return(View(model));
        }
コード例 #2
0
        public async Task <ActionResult> Create(ProductViewModel model, string savecontinue)
        {
            if (ModelState.IsValid)
            {
                bool continueEditing = false;
                if (!String.IsNullOrWhiteSpace(savecontinue))
                {
                    continueEditing = true;
                }

                //basic setting
                //this will be removed
                DefaultValues(model);

                //product
                Product product = new Product();
                product = ProductMapping.ViewToModel(model);

                TEBApiResponse apiResponse = await Post <Product>("/Product/InsertProduct", product);

                ////search engine name
                //model.SeName = product.ValidateSeName(model.SeName, product.Name, true);
                //_urlRecordService.SaveSlug(product, model.SeName, 0);
                ////locales
                //UpdateLocales(product, model);
                //categories
                //SaveCategoryMappings(product, model);
                //manufacturers
                //SaveManufacturerMappings(product, model);
                ////ACL (customer roles)
                //SaveProductAcl(product, model);
                ////stores
                //SaveStoreMappings(product, model);
                ////discounts
                //SaveDiscountMappings(product, model);
                //tags
                //_productTagService.UpdateProductTags(product, ParseProductTags(model.ProductTags));
                ////warehouses
                //SaveProductWarehouseInventory(product, model);

                ////quantity change history
                //_productService.AddStockQuantityHistoryEntry(product, product.StockQuantity, product.StockQuantity, product.WarehouseId,
                //    _localizationService.GetResource("Admin.StockQuantityHistory.Messages.Edit"));

                ////activity log
                //_customerActivityService.InsertActivity("AddNewProduct", _localizationService.GetResource("ActivityLog.AddNewProduct"), product.Name);

                //SuccessNotification(_localizationService.GetResource("Admin.Catalog.Products.Added"));

                if (apiResponse.IsSuccess)
                {
                    if (continueEditing)
                    {
                        //selected tab
                        //SaveSelectedTabName();
                        int productid = JsonConvert.DeserializeObject <int>(Convert.ToString(apiResponse.Data));
                        return(RedirectToAction("Edit", new { id = productid }));
                    }
                    return(RedirectToAction("Index"));
                }
            }

            //If we got this far, something failed, redisplay form
            PrepareProductModel(model, null, false, true);
            //PrepareAclModel(model, null, true);
            //PrepareStoresMappingModel(model, null, true);
            //PrepareCategoryMappingModel(model, null, true);
            //PrepareManufacturerMappingModel(model, null, true);
            //PrepareDiscountMappingModel(model, null, true);

            return(View(model));
        }