Пример #1
0
        public ActionResult Add([Bind(Prefix = "AddForm")] ProductsAddForm form)
        {
            var model = new ProductsAddViewModel { AddForm = form };

            if (ModelState.IsValid)
            {
                using (var transaction = _session.BeginTransaction())
                {
                    var product = new Product
                                  {
                                      Name = form.Name,
                                      Description = form.Description ?? string.Empty
                                  };

                    var primaryVariant = new ProductVariant
                                         {
                                             Price = form.Price.Value,
                                             Sku = form.Sku ?? string.Empty,
                                             Product = product
                                         };

                    product.Variants = new[] { primaryVariant };

                    _session.Save(product);
                    transaction.Commit();
                    return RedirectToAction("View", new { id = product.Id });
                }
            }

            SetupAddViewModel(model);
            return View(model);
        }
        public ActionResult Add(ProductsAddViewModel viewModel)
        {
            // ValidateProduct(viewModel.Product);

            if (ModelState.IsValid)
            {
                var product   = viewModel.Product;
                var inventory = viewModel.Inventory;


                _inventoriesRepository.Add(inventory);
                var inventoryId = _inventoriesRepository.GetLast(includeRelatedEntoties: true).Id;

                product.InventoryId = inventoryId;

                _productsRepository.Add(product);


                TempData["Message"] = "Votre produit a été ajouté a la liste.";

                return(RedirectToAction("Index"));
            }

            viewModel.Init(_productTypesRepository, _suppliersRepository, _unitsRepository, User.Identity.GetUserId());

            return(View(viewModel));
        }
Пример #3
0
        public ActionResult Add()
        {
            var model = new ProductsAddViewModel { AddForm = new ProductsAddForm() };

            SetupAddViewModel(model);
            return View(model);
        }
Пример #4
0
        public ActionResult Add([Bind(Prefix = "AddForm")] ProductsAddForm form)
        {
            var model = new ProductsAddViewModel {
                AddForm = form
            };

            if (ModelState.IsValid)
            {
                using (var transaction = _session.BeginTransaction())
                {
                    var product = new Product
                    {
                        Name        = form.Name,
                        Description = form.Description ?? string.Empty
                    };

                    var primaryVariant = new ProductVariant
                    {
                        Price   = form.Price.Value,
                        Sku     = form.Sku ?? string.Empty,
                        Product = product
                    };

                    product.Variants = new[] { primaryVariant };

                    _session.Save(product);
                    transaction.Commit();
                    return(RedirectToAction("View", new { id = product.Id }));
                }
            }

            SetupAddViewModel(model);
            return(View(model));
        }
Пример #5
0
        public ActionResult Add()
        {
            var model = new ProductsAddViewModel {
                AddForm = new ProductsAddForm()
            };

            SetupAddViewModel(model);
            return(View(model));
        }
        public ActionResult Add()
        {
            var viewModel = new ProductsAddViewModel();

            viewModel.Product.UserId = User.Identity.GetUserId();
            //viewModel.Product.User.UserName = User.Identity.GetUserName();
            viewModel.Inventory.UserId = User.Identity.GetUserId();
            // viewModel.Inventory.User.UserName = User.Identity.GetUserName();

            viewModel.Init(_productTypesRepository, _suppliersRepository, _unitsRepository, User.Identity.GetUserId());

            return(View(viewModel));
        }
Пример #7
0
        public ActionResult add()
        {
            ProductsAddViewModel         addviewModel = new ProductsAddViewModel();
            IEnumerable <SelectListItem> mallslist    = mallsBll.FindList(pt => true, true, "Id").ToList().Select(a => new SelectListItem
            {
                Text  = a.Name,
                Value = a.Id.ToString()
            });

            addviewModel.ListMalls = mallslist;

            List <ProductType> onelist = producttypeBll.FindList(p => p.tpLevel == 1, true, "Id").ToList();

            ViewData["ptypone"] = onelist;

            return(View(addviewModel));
        }
Пример #8
0
        private static void SetupAddViewModel(ProductsAddViewModel model)
        {
            var defaultItems = new[] { "Title", "Color", "Size" };

            model.DefaultOptionNameListItems = (from it in defaultItems
                                                select new SelectListItem
            {
                Value = it,
                Text = it
            }).ToList();

            if (model.AddForm.Options == null)
            {
                model.AddForm.Options = new List <ProductOptionData>();
            }

            var options = model.AddForm.Options;

            // make sure we have 3 options
            if (options.Count < 1)
            {
                options.Add(new ProductOptionData {
                    Disabled = true
                });
            }

            if (options.Count < 2)
            {
                options.Add(new ProductOptionData {
                    Disabled = true
                });
            }

            if (options.Count < 3)
            {
                options.Add(new ProductOptionData {
                    Disabled = true
                });
            }
        }
Пример #9
0
        private static void SetupAddViewModel(ProductsAddViewModel model)
        {
            var defaultItems = new[] { "Title", "Color", "Size" };

            model.DefaultOptionNameListItems = (from it in defaultItems
                                                select new SelectListItem
                                                       {
                                                           Value = it,
                                                           Text = it
                                                       }).ToList();

            if (model.AddForm.Options == null)
            {
                model.AddForm.Options = new List<ProductOptionData>();
            }

            var options = model.AddForm.Options;

            // make sure we have 3 options
            if (options.Count < 1)
            {
                options.Add(new ProductOptionData { Disabled = true });
            }

            if (options.Count < 2)
            {
                options.Add(new ProductOptionData { Disabled = true });
            }

            if (options.Count < 3)
            {
                options.Add(new ProductOptionData { Disabled = true });
            }
        }