Пример #1
0
        public void Add(ProductAddViewModel model)
        {
            var product = new Product
            {
                Name        = model.Name,
                Description = model.Description,
                Price       = model.Price,
                Category    = model.CategoryId
            };

            _context.Products.Add(product);
            _context.SaveChanges();
        }
Пример #2
0
        public IActionResult Add(ProductAddViewModel model)
        {
            var product = new Product(model.Id, model.Name, model.Count, model.Description);

            if (product == null)
            {
                return(View(model));
            }

            _productRepository.Add(product);

            return(RedirectToAction("Index"));
        }
Пример #3
0
        public async Task AddAsync(ProductAddViewModel productModel, string userId)
        {
            await this.db.Products.AddAsync(new Product
            {
                ProductType = Enum.Parse <ProductType>(productModel.ProductType, true),
                Image       = productModel.Image,
                Description = productModel.Description,
                Price       = productModel.Price,
                CreatorId   = userId,
            });

            await this.db.SaveChangesAsync();
        }
Пример #4
0
        public void Save(ProductAddViewModel model)
        {
            var product = new Product()
            {
                Name        = model.Name,
                Description = model.Description,
                Price       = model.Price,
                Category    = _context.Categories.Single(x => x.Id == model.CategoryId)
            };

            _context.Products.Add(product);
            _context.SaveChanges();
        }
        public ActionResult List(int ItemNo)
        {
            if (Session["Customer"] == null)
            {
                return(Redirect("/CustomerLogin/CustomerLoginIndex"));
            }
            using (var db = new ModelContext())
            {
                var item = db.Products.Find(ItemNo);

                var a = new ProductAddViewModel(item);
                return(View(a));
            }
        }
Пример #6
0
        public async Task <IActionResult> Add(Product product)
        {
            if (product.ImageUpload.Length == 0 && product.ImageUpload == null)
            {
                TempData.Add("message", " file not selected");
                return(RedirectToAction("Add"));
            }
            else
            {
                product.Image = product.ProductName + ".jpg";
                string path_root      = _appEnvironment.WebRootPath + "/Upload";
                string path_to_Images = path_root + "\\" + product.Image;
                using (var stream = new FileStream(path_to_Images, FileMode.Create))

                {
                    await product.ImageUpload.CopyToAsync(stream);
                }
            }

            ProductValidator productValidator = new ProductValidator();
            ValidationResult result           = productValidator.Validate(product);

            if (!result.IsValid)
            {
                ProductAddViewModel model = new ProductAddViewModel()
                {
                    Product       = product,
                    Categories    = _categoryService.GetAllCategories(),
                    SubCategories = _subCategoryService.GetAll(),
                    //ValidationResults = new List<string>()
                };

                foreach (var x in result.Errors)
                {
                    ModelState.AddModelError(x.PropertyName, x.ErrorMessage);
                }

                return(View(model));
            }
            else
            {
                _productService.Add(product);
                TempData.Add("message", "Product was successfully added");
                return(RedirectToAction("Add"));
            }
            //if (ModelState.IsValid)
            //{
            //
            //}
        }
        public ActionResult Add(ProductAddViewModel model)
        {
            var product = new Product();

            product.CategoryId    = model.CategoryId;
            product.ProductName   = model.ProductName;
            product.Status        = model.Status;
            product.Picture       = model.Picture;
            product.SalePrice     = model.SalePrice;
            product.PurchasePrice = model.PurchasePrice;
            product.Stock         = model.Stock;
            product.TradeMark     = model.TradeMark;
            _productService.Create(product);
            return(Redirect("/Product/Index"));
        }
Пример #8
0
        public ActionResult Add()
        {
            foreach (var item in _categoryService.GetAll().Where(c => int.Parse(c.ParentId) == 0))
            {
                categoryList.Add(item);
                GetSubCategory(item.CategoryName, item.CategoryId);
            }

            var model = new ProductAddViewModel
            {
                Product    = new Product(),
                Categories = categoryList
            };

            return(View(model));
        }
Пример #9
0
        public async Task <IActionResult> Add(ProductAddViewModel product, IFormFile Image)
        {
            if (!ModelState.IsValid)
            {
                return(View(product));
            }

            product.Content = this.html.Sanitize(product.Content);

            var fileName = await SaveImage(Image);

            await this.productService.CreateAsync(product.Title, product.Content, fileName);

            TempData[WebConstants.TempDataSuccessMessageKey] = ($"Product {product.Title} successfuly added.");
            return(RedirectToAction(nameof(ProductController.Index), new { page = 1 }));
        }
Пример #10
0
        public async Task <ActionResult> Add(ProductAddViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                await db.MapDataAndSave(viewModel);

                return(Json(new { success = true, message = "Added Successfully" }));
            }
            ViewBag.Suppliers = await db.IncludeSuppliersDropdown();

            ViewBag.Categories = await db.IncludeCategoriesDropdown();

            ViewBag.Manufactures = await db.IncludeManufacturesDropdown();

            return(new HttpStatusCodeResult(400));
        }
Пример #11
0
 public ActionResult Add(ProductAddViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             using (TransactionScope scope = new TransactionScope())
             {
                 scope.Complete();
             }
         }
         catch
         {
         }
     }
     return(View(model));
 }
Пример #12
0
        public async Task <IActionResult> Add(ProductAddViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (viewModel.File.IsImage())
                {
                    PersianCalendar pc           = new PersianCalendar();
                    var             uploadResult = await _uploadService.UploadFile(viewModel.File, string.Format("{0}://{1}{2}", Request.Scheme, Request.Host.Value, Request.PathBase.Value), "Products\\" + pc.GetYear(DateTime.Now) + "\\" + pc.GetMonth(DateTime.Now) + "\\" + pc.GetDayOfMonth(DateTime.Now));

                    if (uploadResult.Status)
                    {
                        var product = _mapper.Map <Product>(viewModel);
                        product.PhotoUrl = uploadResult.Url;

                        await _db.ProductRepository.AddAsync(product);

                        await _db.SaveAsync();

                        return(Redirect("/Admin/Product"));
                    }
                    else
                    {
                        ModelState.AddModelError("File", "خطا در آپلود تصویر محصول");
                        var categories = await _db.CategoryRepository.GetAsync();

                        ViewData["CategoryId"] = new SelectList(categories, "Id", "Name", viewModel.CategoryId);
                        return(View(viewModel));
                    }
                }
                else
                {
                    ModelState.AddModelError("File", "تصویر محصول معتبر نیست");
                    var categories = await _db.CategoryRepository.GetAsync();

                    ViewData["CategoryId"] = new SelectList(categories, "Id", "Name", viewModel.CategoryId);
                    return(View(viewModel));
                }
            }
            else
            {
                var categories = await _db.CategoryRepository.GetAsync();

                ViewData["CategoryId"] = new SelectList(categories, "Id", "Name", viewModel.CategoryId);
                return(View(viewModel));
            }
        }
Пример #13
0
        public IActionResult Add()
        {
            var model = new ProductAddViewModel();

            try
            {
                model = new ProductAddViewModel
                {
                    Categories = GetCategories()
                };
            }
            catch (Exception e)
            {
                SetErrorMessage(e);
            }

            return(View(model));
        }
Пример #14
0
        public IActionResult Create(ProductAddViewModel model)
        {
            if (ModelState.IsValid)
            {
                var product = new Products();
                product.Style  = model.Style;
                product.Colour = model.Colour;
                product.Sku    = model.Sku;
                product.Title  = model.Title;
                product.Price  = model.Price;
                product.Stock  = model.Stock;

                _productrepository.Add(product);

                TempData["PROD"] = "You have added a new product!";
            }
            return(View());
        }
Пример #15
0
        public IActionResult Add()
        {
            Checker.CheckLangId(HttpContext, db, "adminLangId").Wait();
            HttpContext.SetCurrentPage("Index", "Product");
            int langId = HttpContext.GetLanguage("adminLangId");
            ProductAddViewModel model = new ProductAddViewModel
            {
                categoryLanguages = db.CategoryLanguages
                                    .Where(cl => cl.LanguageId == langId)
                                    .Include(cl => cl.Category)
                                    .ToList(),
                sizes = db.Sizes.ToList(),

                languages = db.Languages.ToList()
            };

            return(View(model));
        }
Пример #16
0
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            ProductAddViewModel product = new ProductAddViewModel()
            {
                Name       = TxtBoxName.Text,
                CategoryId = (ComboCategory.SelectedItem as Category).Id,
                Price      = float.Parse(TxtBoxPrice.Text),
                Quantity   = int.Parse(TxtBoxQty.Text),
                Images     = Photos
            };
            var prod = _productProvider.AddProduct(product);

            if (prod != null)
            {
                MessageBox.Show($"Продукт успешно сохранен. ID = {prod.Id.ToString()}");
            }

            this.Close();
        }
Пример #17
0
        public IActionResult AddProduct(ProductAddViewModel model)
        {
            if (ModelState.IsValid)
            {
                Product product = new Product()
                {
                    Description  = model.Description,
                    SellingPrice = model.SellingPrice,
                    BuyingPrice  = model.BuyingPrice,
                    CategoryId   = model.CategoryId,
                    ProductName  = model.ProductName,
                    Marka        = model.Marka,
                    Stok         = model.Stok
                };

                _productService.Add(product);
                return(RedirectToAction("Index", "Product"));
            }
            return(View(model));
        }
Пример #18
0
        public async Task <IActionResult> Add()
        {
            ProductAddViewModel dto = new ProductAddViewModel();

            //Get All Category
            var categorys = await _llkRepository.getAll();

            var categoryDTO = _mapper.Map <List <LoaiLinhKienDTO> >(categorys);

            ViewBag.Category = categoryDTO;

            //Get All Manufactuer
            var manufactuers = await _nccRepository.getAll();

            var manuDTO = _mapper.Map <List <NhaCungCapDTO> >(manufactuers);

            ViewBag.Manu = manuDTO;

            return(View("~/Views/Admin/Product/Add.cshtml", dto));
        }
Пример #19
0
 public IActionResult AddProduct([FromBody] ProductAddViewModel model)
 {
     Thread.Sleep(3000);
     if (!ModelState.IsValid)
     {
         var errrors = CustomValidator.GetErrorsByModel(ModelState);
         return(BadRequest(errrors));
     }
     try
     {
         var cat = _context.Categories.SingleOrDefault(c => c.Name == model.Category);
         if (cat == null)
         {
             cat = new Category
             {
                 Name = model.Category
             };
             _context.Categories.Add(cat);
             _context.SaveChanges();
         }
         var product = new Product
         {
             CategoryId = cat.Id,
             Name       = model.Name
         };
         _context.Products.Add(product);
         _context.SaveChanges();
         var result = new ProductViewModel
         {
             Id       = product.Id,
             Name     = product.Name,
             Category = cat.Name
         };
         return(Ok(result));
     }
     catch
     {
         return(BadRequest(new { invalid = "Помилка збереження даних!" }));
     }
 }
Пример #20
0
        public IActionResult Put([FromBody] ProductAddViewModel product)
        {
            if (product == null)
            {
                return(BadRequest());
            }

            var result = _productService.UpdateProduct(product.Id,
                                                       new ProductDto
            {
                Name        = product.Name,
                Description = product.Description,
                Discount    = product.Discount,
                Price       = product.Price,
                Quantity    = product.Quantity
            });

            if (result == false)
            {
                return(NotFound());
            }
            return(Ok(product));
        }
        public IActionResult AddProduct(ProductAddViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = ProcessUploadedFile(model);


                Product newProduct = new Product
                {
                    Name         = model.Name,
                    Description  = model.Description,
                    Price        = model.Price,
                    Availability = model.Availability,
                    ImageURL     = uniqueFileName
                };

                _productsRepository.Add(newProduct);

                return(RedirectToAction("index", new { id = newProduct.Id }));
            }

            return(View());
        }
        private string ProcessUploadedFile(ProductAddViewModel model)
        {
            string uniqueFileName = null;

            if (model.Photo != null)
            {
                // Get path of the wwwroot folder using HostingEnvornment
                string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                // Append a unique guid value and a dash to the file name
                uniqueFileName = Guid.NewGuid().ToString() + "-" + model.Photo.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);

                // Create File stream
                FileStream fileStream = new FileStream(filePath, FileMode.Create);
                // Use CopyTo() method provided by IFormFile interface to
                // copy the file to wwwroot/images folder
                model.Photo.CopyTo(fileStream);
                // Close File Stream
                fileStream.Close();
            }

            return(uniqueFileName);
        }
Пример #23
0
 public ActionResult Create(ProductAddViewModel model)
 {
     if (model.Count == 0 || model.Price == 0 || model.Name == null || model.Description == null)
     {
         ModelState.AddModelError("", "Invalid enter data.");
     }
     else
     {
         using (TransactionScope scope = new TransactionScope())
         {
             Product product = new Product()
             {
                 Name        = model.Name,
                 Price       = model.Price,
                 Description = model.Description,
                 Count       = model.Count,
                 IsAvailable = model.IsAvailable,
             };
             _context.Products.Add(product);
             if (model.DescriptionImages != null)
             {
                 for (int i = 0; i < model.DescriptionImages.Count(); i++)
                 {
                     var temp = model.DescriptionImages[i];
                     if (temp != null)
                     {
                         _context.ProductDescriptionImages
                         .FirstOrDefault(t => t.Name == temp).ProductId = product.Id;
                     }
                 }
             }
             _context.SaveChanges();
             scope.Complete();
         }
     }
     return(RedirectPermanent("/Product/Index"));
 }
Пример #24
0
        public Product AddProduct(ProductAddViewModel productAdd)
        {
            //MessageBox.Show(Environment.CurrentDirectory);
            Product product = new Product
            {
                Name       = productAdd.Name,
                CategoryId = productAdd.CategoryId,
                Price      = productAdd.Price,
                Quantity   = productAdd.Quantity,
                DateCreate = DateTime.Now
            };

            _productRepository.Add(product);
            _productRepository.SaveChanges();
            if (productAdd.Images.Count > 0)
            {
                List <string> imgTemp = new List <string>();
                foreach (var p in productAdd.Images)
                {
                    string fSaveName     = Guid.NewGuid().ToString() + ".jpg";
                    string fImages       = Environment.CurrentDirectory + ConfigurationManager.AppSettings["ImageStore"].ToString();
                    string fNameOriginal = "o_" + fSaveName;
                    string fNameSmall    = "s_" + fSaveName;
                    // Will not overwrite if the destination file already exists.
                    try
                    {
                        File.Copy(p.SourceOriginal, Path.Combine(fImages, fNameOriginal));
                        imgTemp.Add(fNameOriginal);

                        ProductImage image = new ProductImage // сохраняем в таблицу ProductImages
                        {
                            Name      = fSaveName,            // сохраняем имя без приставки
                            ProductId = product.Id
                        };
                        _productImageRepository.Add(image);
                        // Catch exception if the file was already copied.

                        using (FileStream stream = new FileStream(Path.Combine(fImages, fNameSmall), FileMode.Create))
                        {
                            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
                            //TextBlock myTextBlock = new TextBlock();
                            //myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString();
                            encoder.Frames.Add(p.ImagePhoto);
                            //MessageBox.Show(myPalette.Colors.Count.ToString());
                            encoder.Save(stream);
                        }
                    }
                    catch (IOException copyError)
                    {
                        MessageBox.Show(copyError.Message);
                        foreach (var item in imgTemp)
                        {
                            File.Delete(Path.Combine(fImages, item));
                        }
                        return(null);
                    }
                }
                _productImageRepository.SaveChanges();
            }
            return(product);
        }
Пример #25
0
        public async Task <IActionResult> CreateProduct(ProductAddViewModel productModel)
        {
            await this.productsService.AddAsync(productModel, productModel.UserId);

            return(Ok("Done"));
        }
Пример #26
0
        public async Task <IActionResult> AddPost([FromForm] ProductAddViewModel dto)
        {
            if (!ModelState.IsValid)
            {
                //Get All Category
                var categorys = await _llkRepository.getAll();

                var categoryDTO = _mapper.Map <List <LoaiLinhKienDTO> >(categorys);
                ViewBag.Category = categoryDTO;

                //Get All Manufactuer
                var manufactuers = await _nccRepository.getAll();

                var manuDTO = _mapper.Map <List <NhaCungCapDTO> >(manufactuers);
                ViewBag.Manu = manuDTO;

                return(View("~/Views/Admin/Product/Add.cshtml", dto));
            }

            //Lưu Hình vào Server
            string contentRootPath = _webHostEnvironment.ContentRootPath;
            string pathS           = "";
            Random rnd             = new Random();

            pathS = Path.Combine(contentRootPath, "images");
            pathS = Path.Combine(pathS, "products");
            string Hinh = "";

            foreach (var formFile in dto.files)
            {
                if (formFile.Length > 0)
                {
                    try
                    {
                        string fileName = dto.MaLK + rnd.Next(1, 100000) + Path.GetExtension(formFile.FileName);
                        string _path    = Path.Combine(contentRootPath, "wwwroot\\images");
                        _path = Path.Combine(_path, "products");
                        _path = Path.Combine(_path, fileName);
                        using (var fileStream = new FileStream(_path, FileMode.Create))
                        {
                            await formFile.CopyToAsync(fileStream);
                        }
                        Hinh += fileName + ",";
                    }
                    catch
                    {
                        //Get All Category
                        var categorys = await _llkRepository.getAll();

                        var categoryDTO = _mapper.Map <List <LoaiLinhKienDTO> >(categorys);
                        ViewBag.Category = categoryDTO;

                        //Get All Manufactuer
                        var manufactuers = await _nccRepository.getAll();

                        var manuDTO = _mapper.Map <List <NhaCungCapDTO> >(manufactuers);
                        ViewBag.Manu = manuDTO;
                        ModelState.AddModelError("Hinh", "Upload hình không thành công");
                        return(View("~/Views/Admin/Product/Add.cshtml", dto));
                    }
                }
            }
            Hinh = Hinh.Remove(Hinh.Length - 1);

            //Create Entity
            LinhKien lk = new LinhKien();

            lk.TenLK    = dto.TenLK;
            lk.MaLK     = dto.MaLK;
            lk.MoTa     = dto.MoTa;
            lk.TGBH     = dto.TGBH;
            lk.SLTonKho = dto.SLTonKho;

            DonGia donGia = new DonGia();

            donGia.DonGiaBan = (decimal)dto.Gia;
            donGia.GiamGia   = dto.GiamGia;
            donGia.ApDung    = true;
            donGia.Ngay      = DateTime.Now.Date;

            List <DonGia> donGias = new List <DonGia>();

            donGias.Add(donGia);
            lk.DonGias = donGias;

            var loaillk = await _llkRepository.getById(dto.Loai);

            var ncc = await _nccRepository.getById(dto.NCC);

            lk.Loai = loaillk;
            lk.NCC  = ncc;
            lk.Hinh = Hinh;

            await _linhKienRepository.Add(lk);

            return(Redirect("/admin/product"));
        }
Пример #27
0
        //public void Add(ProductAddViewModel model)
        //{
        //    throw new NotImplementedException();
        //}

        public void Save(ProductAddViewModel model)
        {
            throw new NotImplementedException();
        }
        public ActionResult ProductAddResult(ProductAddViewModel pro)
        {
            if (Session["Customer"] == null)
            {
                return(Redirect("/CustomerLogin/CustomerLoginIndex"));
            }
            using (var db = new ModelContext())
            {
                //空欄、形式チェック
                if (!ModelState.IsValid)
                {
                    return(View("List", pro));
                }
                //数量ゼロチェック
                if (pro.Quantity <= 0)
                {
                    ViewBag.N = false;
                    return(View("List", pro));
                }
                //在庫チェック
                int x     = pro.ItemNo;
                var stock = db.Products.Find(x);
                var y     = (from a in db.OrderDetails
                             where a.ItemNo == x && a.Status == 1
                             select(int?) a.Quantity).Sum() ?? 0;

                int s = stock.Stock - y;
                if (s < pro.Quantity)
                {
                    ViewBag.E = false;
                    return(View("List", pro));
                }

                //希望納期チェック(過去or90日以上未来)
                DateTime dfrom    = DateTime.Now;
                DateTime dto      = pro.DeliveryDate;
                double   interval = (dto - dfrom).TotalDays;
                if (interval < 0 || interval > 90)
                {
                    ViewBag.D = false;
                    return(View("List", pro));
                }

                //カートへ追加
                var u = new CartDetail
                {
                    ItemNo       = pro.ItemNo,
                    Quantity     = pro.Quantity,
                    DeliveryDate = pro.DeliveryDate,
                    CustomerId   = (int)Session["Customer"]
                };

                //時刻除外)
                string result = pro.DeliveryDate.ToString();
                ViewBag.Date = result.Substring(0, 10);
                //単価を三桁区切り
                ViewBag.UnitP = String.Format("{0:#,0}", pro.UnitPrice);
                //合計金額を三桁区切り
                var price = pro.UnitPrice * pro.Quantity;
                ViewBag.Price = String.Format("{0:#,0}", price);

                ViewBag.ItemN  = pro.ItemName;
                ViewBag.Result = u;
                ViewBag.Url    = stock.PhotoUrl;

                db.CartDetails.Add(u);
                db.SaveChanges();

                return(View());
            }
        }
Пример #29
0
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            ProductAddViewModel product = new ProductAddViewModel()
            {
                Name       = TxtBoxName.Text,
                CategoryId = (ComboCategory.SelectedItem as Category).Id,
                Price      = float.Parse(TxtBoxPrice.Text),
                Quantity   = int.Parse(TxtBoxQty.Text),
                Images     = Photos
            };
            var prod = _productProvider.AddProduct(product);

            if (prod != null)
            {
                MessageBox.Show($"Продукт успешно сохранен. ID = {prod.Id.ToString()}");
            }
            Photos.Clear();
            //Photos.Add(new Photo() { });
            this.Close();
            #region OldAddCode
            //foreach (var p in Photos)
            //{
            //    MessageBox.Show(p.SourceOriginal);
            //}

            //using (EfContext context = new EfContext())
            //{
            //Product product = new Product
            //{
            //    Name = TxtBoxName.Text,
            //    CategoryId = (ComboCategory.SelectedItem as Category).Id,
            //    Price = float.Parse(TxtBoxPrice.Text),
            //    Quantity = int.Parse(TxtBoxQty.Text),
            //    DateCreate = DateTime.Now,
            //};
            //context.Products.Add(product);
            //context.SaveChanges();
            //MessageBox.Show($"Id = {product.Id.ToString()}");
            //if (Photos.Count > 0)
            //{

            //    List<string> imgTemp = new List<string>();
            //    foreach (var p in Photos)
            //    {
            //        //MessageBox.Show(p.SourceOriginal);
            //        string fOriginalName = Path.GetFileName(p.SourceOriginal);
            //        string fOriginalPath = Path.GetDirectoryName(p.SourceOriginal);
            //        string fSmallName = Path.GetFileName(p.Source);
            //        string fSmallPath = Environment.CurrentDirectory + ConfigurationManager.AppSettings["ImagePath"].ToString();
            //        string fImages = Environment.CurrentDirectory + ConfigurationManager.AppSettings["ImageStore"].ToString();
            //        // Will not overwrite if the destination file already exists.
            //        try
            //        {
            //            File.Copy(Path.Combine(fOriginalPath, fOriginalName), Path.Combine(fImages, "o_" + fSmallName));
            //            imgTemp.Add("o_" + fSmallName);
            //            File.Copy(Path.Combine(fSmallPath, fSmallName), Path.Combine(fImages, "s_" + fSmallName));
            //            imgTemp.Add("s_" + fSmallName);

            //            ProductImage image = new ProductImage // сохраняем в таблицу ProductImages
            //            {
            //                Name = fSmallName,
            //                ProductId = product.Id
            //            };
            //            context.ProductImages.Add(image);

            //            // Catch exception if the file was already copied.
            //        }
            //        catch (IOException copyError)
            //        {
            //            MessageBox.Show(copyError.Message);
            //            foreach (var item in imgTemp)
            //            {
            //                File.Delete(Path.Combine(fImages, item));
            //            }
            //            return;
            //        }

            //    }
            //    context.SaveChanges();
            //}
            //}
            #endregion
            //this.DialogResult = true;
        }
        public override void Execute(object parameter)
        {
            //OrderAddViewModel addViewModel = new OrderAddViewModel();
            //OrderAddWindow addWindow = new OrderAddWindow();

            //addViewModel.DetailPanel = addWindow.DetailPanel;
            //addViewModel.DetailPanel.Children.Add(new SingleOrderDetailControl());
            //addWindow.DataContext = addViewModel;

            //addWindow.ShowDialog();
            //return;

            ProductAddWindow productAddWindow = new ProductAddWindow();

            ProductAddViewModel productAddViewModel = new ProductAddViewModel
            {
                CurrentProduct = productViewModel.CurrentProduct,
                CurrentWindow  = productAddWindow
            };

            #region Category-for Combobox

            List <Category>      categories     = DB.CategoryRepository.Get();
            List <CategoryModel> categoryModels = new List <CategoryModel>();
            CategoryMapper       categoryMapper = new CategoryMapper();

            for (int i = 0; i < categories.Count; i++)
            {
                Category category = categories[i];

                CategoryModel categoryModel = categoryMapper.Map(category);

                categoryModels.Add(categoryModel);
            }

            productAddViewModel.Categories = categoryModels;

            #endregion

            productAddWindow.DataContext           = productAddViewModel;
            productAddWindow.WindowStyle           = System.Windows.WindowStyle.None;
            productAddWindow.AllowsTransparency    = true;
            productAddWindow.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            productAddWindow.ShowDialog();

            // Refresh products list
            List <Product>      products      = DB.ProductRepository.Get();
            List <ProductModel> productModels = new List <ProductModel>();
            ProductMapper       productMapper = new ProductMapper();

            for (int i = 0; i < products.Count; i++)
            {
                Product product = products[i];

                ProductModel productModel = productMapper.Map(product);

                productModels.Add(productModel);
            }

            Enumeration.Enumerate(productModels);

            productViewModel.AllProducts = productModels;
            productViewModel.Products    = new ObservableCollection <ProductModel>(productModels);

            productViewModel.CurrentProduct = new ProductModel();
        }