Esempio n. 1
0
        public async Task <IActionResult> Create(AddProductVM prod)
        {
            if (ModelState.IsValid)
            {
                string  uniqueFileName = FileCheck(prod);
                Product product        = new Product
                {
                    Category = prod.Category,
                    InStock  = prod.InStock,

                    ImageUrl = uniqueFileName,

                    CategoryId      = prod.CategoryId,
                    IsPreffered     = true,
                    LongDescription = prod.Description,
                    Name            = prod.ProductName,
                    Price           = prod.Price,
                    ProductId       = Guid.NewGuid(),
                };
                await _product.AddAsync(product);

                return(RedirectToAction(nameof(Index)));
            }


            ViewData["CategoryId"] = new SelectList(_category.AllCategories(), "CategoryId", "CategoryName", prod.CategoryId);
            return(View(prod));
        }
        public ActionResult Create(AddProductVM model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = FileCheck(model);
                model.NumberSold = 0;
                Product product = new Product
                {
                    ProductName = model.ProductName,
                    Description = model.Description,
                    Price       = model.Price,
                    Color       = model.Color,
                    Quantity    = model.Quantity,
                    NumberSold  = model.NumberSold,
                    Size        = model.Size,
                    ImageUrl    = uniqueFileName,
                    CategoryId  = model.CategoryId,
                    _Category   = model._Category
                };
                _productRepository.Add(product);
                return(RedirectToAction(nameof(ManageProduct)));
            }
            ViewBag.CategoryId = new SelectList(_categoryRepository.AllCategories(), "Id", "Name");

            return(View());
        }
Esempio n. 3
0
        public ActionResult Create(AddProductVM newProduct, HttpPostedFileBase firstImage, HttpPostedFileBase secondImage)
        {
            if (ModelState.IsValid == false)
            {
                IEnumerable <Category> categories = categoryAppService.GetAll();
                IEnumerable <Color>    Colors     = colorAppService.GetAll();
                newProduct.Categories = categories;
                newProduct.Colors     = Colors;
                return(View(newProduct));
            }
            var FirstfileName = Path.GetFileName(firstImage.FileName);
            var path          = Path.Combine(Server.MapPath("~/Content/images"), FirstfileName);

            firstImage.SaveAs(path);
            newProduct.MainImage = FirstfileName;

            var SecondfileName = Path.GetFileName(secondImage.FileName);
            var path2          = Path.Combine(Server.MapPath("~/Content/images"), SecondfileName);

            secondImage.SaveAs(path2);
            newProduct.SecondaryImage = SecondfileName;
            productAppService.Insert(newProduct);
            //productAppService.AssignColorToProduct(productIdentity, productIdentity.ColorID);
            TempData["successMsg"] = "New product added successfully";
            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> EditProduct(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product product = await db.Products.FindAsync(id);

            if (product == null)
            {
                return(HttpNotFound());
            }
            var model = new AddProductVM
            {
                Id            = product.Id,
                Name          = product.Name,
                Description   = product.Description,
                Slug          = product.Slug,
                ImageUrl      = product.ImageUrl,
                SkuCode       = product.SkuCode,
                BarcodeUrl    = product.BarcodeUrl,
                PackSize      = product.PackSize,
                SellingPrice  = product.SellingPrice,
                SupplierPrice = product.SupplierPrice,
                CategoryId    = product.CategoryId,
                SupplierId    = product.SupplierId,
                Categories    = new SelectList(db.Categories.ToList(), "Id", "Name"),
                Suppliers     = new SelectList(db.Suppliers.ToList(), "Id", "Name")
            };

            return(View(model));
        }
        public async Task <IActionResult> NewProduct([FromForm] AddProductVM productVm)
        {
            Product product = new Product();

            product.BrandId     = productVm.BrandId;
            product.Description = productVm.Description;
            product.Model       = productVm.Model;
            product.PriceBy     = productVm.PriceBy;
            if (ModelState.IsValid)
            {
                await ctx.Products.AddAsync(product);

                ctx.SaveChanges();
                if (productVm.Files != null)
                {
                    foreach (var uploadedFile in productVm.Files)
                    {
                        // путь к папке Files
                        string path = "/Files/" + uploadedFile.FileName;
                        // сохраняем файл в папку Files в каталоге wwwroot
                        using (var fileStream = new FileStream(appEnvironment.WebRootPath + path, FileMode.Create))
                        {
                            await uploadedFile.CopyToAsync(fileStream);
                        }
                        ProductPhotos photo = new ProductPhotos {
                            ProductId = product.ProductId, Path = path
                        };
                        ctx.ProductPhotos.Add(photo);
                    }
                    ctx.SaveChanges();
                }
            }
            return(Ok());
        }
Esempio n. 6
0
        public IActionResult Products(int companyId, int productId)
        {
            AddProductVM addProductVM = new AddProductVM();

            addProductVM.CompanyId = companyId;
            addProductVM.Category  = _masterDataService.GetCategory().Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(), Text = x.Name
            });
            var product = _userService.GetProductById(productId);

            if (product != null)
            {
                addProductVM.UploadPath =
                    System.IO.File.Exists(Path.Combine(webHostEnvironment.WebRootPath, "images/" + product.ImagePath))
                        ? "/images/" + product.ImagePath
                        : "/images/noimage.png";
                addProductVM.ProductName   = product.ProductName;
                addProductVM.ProductId     = product.Id;
                addProductVM.Price         = product.Price.ToString();
                addProductVM.DiscountPrice = (product.Price - product.Price * product.Discount / 100).ToString();
                addProductVM.Description   = product.Description;
                addProductVM.ProductCode   = product.ProductCode;
                addProductVM.Discount      = product.Discount.ToString();
            }
            ViewBag.CompanyId = companyId;

            return(View(addProductVM));
        }
        public AddProductV()
        {
            InitializeComponent();
            AddProductVM vm = new AddProductVM(DependencyInjection.ServiceProvider.GetService <IStartUpData>());

            DataContext = vm;
        }
Esempio n. 8
0
        public void Insert(AddProductVM ProductViewModel)
        {
            var product = Mapper.Map <Product>(ProductViewModel);

            TheUnitOfWork.Product.Insert(product);
            TheUnitOfWork.Commit();
        }
Esempio n. 9
0
        public ActionResult Add()
        {
            AddProductVM model = new AddProductVM();

            model.Categories = _categoryService.GetActive();
            model.Suppliers  = _supplierService.GetActive();
            return(View(model));
        }
Esempio n. 10
0
        public ActionResult Edit(AddProductVM product)
        {
            Mapper.Initialize(c => c.CreateMap <AddProductVM, AddProductDTO>());
            AddProductDTO    productDTO = Mapper.Map <AddProductVM, AddProductDTO>(product);
            OperationDetails op         = _productManagerService.EditProduct(productDTO.Id, productDTO);

            return(Json(new { Succedeed = op.Succedeed, message = op.Message, prop = op.Property }));
        }
Esempio n. 11
0
        public bool Update(AddProductVM ProductViewModel)
        {
            var product = Mapper.Map <Product>(ProductViewModel);

            TheUnitOfWork.Product.Update(product);
            TheUnitOfWork.Commit();

            return(true);
        }
        public IActionResult AddProduct(AddProductVM viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            DataBaseTools.AddProduct(viewModel);
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult AddProduct()
        {
            AddProductVM model = new AddProductVM
            {
                Categories = new SelectList(db.Categories.ToList(), "Id", "Name"),
                Suppliers  = new SelectList(db.Suppliers.ToList(), "Id", "Name")
            };

            return(View(model));
        }
Esempio n. 14
0
        public ActionResult Create()
        {
            IEnumerable <Category> categories   = categoryAppService.GetAll();
            IEnumerable <Color>    colors       = colorAppService.GetAll();
            AddProductVM           addProductVM = new AddProductVM();

            addProductVM.Categories = categories;
            addProductVM.Colors     = colors;
            return(View(addProductVM));
        }
Esempio n. 15
0
        public ActionResult AddProduct()
        {
            ViewBag.Message = "Add product page.";
            AddProductVM acVM = new AddProductVM();

            acVM.AllProducts    = Mapper.Map <List <ProductVM> >(db.Products);
            acVM.AllCategories  = Mapper.Map <List <CategoryVM> >(db.Categories);
            acVM.CurrentProduct = new ProductVM();

            return(View(acVM));
        }
Esempio n. 16
0
        public ActionResult EditProduct(int id)
        {
            var entity  = db.Products.Find(id);
            var product = Mapper.Map <ProductVM>(entity);

            var vmAddProduct = new AddProductVM();

            vmAddProduct.CurrentProduct = product;

            return(View(vmAddProduct));
        }
Esempio n. 17
0
        public ActionResult AddProduct(AddProductVM product)
        {
            if (ModelState.IsValid)
            {
                var entity = Mapper.Map <ProductEntity>(product.CurrentProduct);
                db.Products.Add(entity);
                db.Entry(entity).State = EntityState.Added;

                db.SaveChanges();
            }

            return(RedirectToAction("AddProduct"));
        }
Esempio n. 18
0
        public ActionResult Edit(AddProductVM product)
        {
            IEnumerable <Category> categories = categoryAppService.GetAll();
            IEnumerable <Color>    Colors     = colorAppService.GetAll();

            ViewBag.categories = categories;
            ViewData["Colors"] = Colors;
            if (ModelState.IsValid)
            {
                productAppService.Update(product);
                return(RedirectToAction("Index"));
            }
            return(View(product));
        }
Esempio n. 19
0
        public ActionResult Add(AddProductVM product)
        {
            // To exclude the size or color from validation when the product has only color or only size
            if (product.HasSize || product.HasColor)
            {
                if (!product.HasColor)
                {
                    for (int i = 0; i < product.ProductOptionValues.Count; i++)
                    {
                        this.ModelState.Remove("ProductOptionValues[" + i + "].ColorValueId");
                    }
                }
                if (!product.HasSize)
                {
                    for (int i = 0; i < product.ProductOptionValues.Count; i++)
                    {
                        this.ModelState.Remove("ProductOptionValues[" + i + "].SizeValueId");
                    }
                }
            }
            //////////////

            if (ModelState.IsValid)
            {
                Mapper.Initialize(c => c.CreateMap <AddProductVM, AddProductDTO>());
                AddProductDTO    productdto = Mapper.Map <AddProductVM, AddProductDTO>(product);
                OperationDetails op         = _productManagerService.AddProduct(productdto);


                return(Json(new { Succedeed = op.Succedeed, message = op.Message, prop = op.Property }));
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();
                product.Colors    = _productManagerService.GetAllColors();
                product.Sizes     = _productManagerService.GetSizesOfCat(product.SizeCategoryId);
                product.Designers = _DesignerService.GetAllDesigners(CurrentLanguage);
                //product.BaseCategories = _productManagerService.GetSubCategories((long)CurrentWebsite, CurrentLanguage);
                product.BaseCategories = _categoryService.GetAllPathsByWebsite(CurrentWebsite, CurrentLanguage);
                List <AttributeGroupDTO> attribueGroups = _attributeGroupService.GetAllAttributeGroups(CurrentLanguage);
                product.AttributesGroups = attribueGroups;
                if (product.HasSize)
                {
                    product.AllSizeAttributes = _manageSizeAttributesService.GetSizeAttributesBySizeCaategoryId(product.SizeCategoryId.Value, CurrentLanguage);
                }
                return(View(product));
            }
        }
Esempio n. 20
0
        public ActionResult EditProduct(AddProductVM product)
        {
            if (!ModelState.IsValid)
            {
                return(View(product));
            }

            var entity = Mapper.Map <ProductEntity>(product.CurrentProduct);

            db.Products.Attach(entity);
            db.Entry(entity).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("AddProduct"));
        }
Esempio n. 21
0
        public ActionResult Add(int subCategoryId)
        {
            AddProductVM addProductVM = this.service.GetAddProductVM(subCategoryId);

            if (addProductVM == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            if (this.Request.IsAjaxRequest())
            {
                return(this.PartialView(addProductVM));
            }

            return(this.View(addProductVM));
        }
Esempio n. 22
0
        private string UploadedFile(AddProductVM model)
        {
            string uniqueFileName = null;

            if (model.ImagePath != null)
            {
                string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.ImagePath.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.ImagePath.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
Esempio n. 23
0
        public ActionResult Update(Guid id)
        {
            Product      product = _productService.GetByID(id);
            AddProductVM model   = new AddProductVM();

            model.Products.ID          = product.ID;
            model.Products.Name        = product.Name;
            model.Products.Author      = product.Author;
            model.Products.CategoryID  = product.CategoryID;
            model.Products.Price       = product.Price;
            model.Products.Quantity    = product.Quantity;
            model.Products.UnitInStock = product.UnitInStock;
            model.Categories           = _categoryService.GetActive();

            return(View(model));
        }
 public IActionResult AddProduct(AddProductVM addProductVM)
 {
     if (ModelState.IsValid)
     {
         Product newProduct = new Product
         {
             Name        = addProductVM.Name,
             Price       = addProductVM.Price,
             Category    = addProductVM.Category,
             Description = addProductVM.Description
         };
         Database.Products.Add(newProduct);
         return(Redirect("/Product"));
     }
     return(View(addProductVM));
 }
        private string FileCheck(AddProductVM model)
        {
            string uniqueFileName = null;

            if (model.Photo != null)
            {
                string uploadsFolder = Path.Combine(_environment.WebRootPath, "images/");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                string filePath = Path.Combine(uploadsFolder + uniqueFileName);
                using (var filestream = new FileStream(filePath, FileMode.Create))
                {
                    model.Photo.CopyTo(filestream);
                }
            }

            return(uniqueFileName);
        }
Esempio n. 26
0
        public ActionResult UpdateProduct(int id)
        {
            AddProductVM model   = new AddProductVM();
            Product      product = db.Products.FirstOrDefault(x => x.ID == id);

            model.Product.ID          = product.ID;
            model.Product.ProductName = product.ProductName;
            model.Product.Description = product.Description;
            model.Product.UnitPrice   = product.UnitPrice;
            model.Product.UnitStock   = product.UnitStock;

            List <Category> categorymodel = db.Categories.Where(x => x.Status == Model.Enum.Status.Active || x.Status == Model.Enum.Status.Updated).ToList();

            model.Categories = categorymodel;

            return(View(model));
        }
Esempio n. 27
0
        public IActionResult AddProduct(AddProductVM addProductVM)
        {
            if (!ModelState.IsValid)
            {
                ShowToaster("Please fill required fields", ToasterLevel.Danger);
                return(RedirectToAction("Products", "Company", new { companyId = addProductVM.CompanyId }));
            }
            var           config = new MapperConfiguration(cfg => cfg.CreateMap <AddProductVM, AddProductDTO>());
            var           mapper = new Mapper(config);
            AddProductDTO dto    = mapper.DefaultContext.Mapper.Map <AddProductDTO>(addProductVM);

            dto.ImagePath = UploadedFile(addProductVM);
            _userService.CreateAndUpdateProduct(dto);
            var status = addProductVM.ProductId == 0 ? "Created" : "Updated";

            ShowToaster("Product " + status + " successfully", ToasterLevel.Success);

            return(RedirectToAction("Products", "Company", new { companyId = dto.CompanyId }));
        }
Esempio n. 28
0
        public ActionResult Add(int choice, long?Id)
        {
            //  bool? color, bool? size,long? sizeCategoryId
            AddProductVM product = new AddProductVM();

            product.SizeCategoryId = Id;
            product.Colors         = _productManagerService.GetAllColors();
            product.Sizes          = _productManagerService.GetSizesOfCat(Id);
            product.Designers      = _DesignerService.GetAllDesigners(CurrentLanguage);

            //product.BaseCategories = _productManagerService.GetSubCategories((long)CurrentWebsite, CurrentLanguage);
            product.BaseCategories = _categoryService.GetAllPathsByWebsite(CurrentWebsite, CurrentLanguage);
            // List<DesignerDTO> designers = _DesignerService.GetAllDesigners(CurrentLanguage);
            // product.Designers = designers;

            List <AttributeGroupDTO> attribueGroups = _attributeGroupService.GetAllAttributeGroups(CurrentLanguage);

            product.AttributesGroups = attribueGroups;
            if (choice == 1 || choice == 3)
            {
                product.HasColor = true;
            }
            else
            {
                product.HasColor = false;
            }

            if (choice == 2 || choice == 3)
            {
                product.HasSize = true;
            }
            else
            {
                product.HasSize = false;
            }
            if (product.HasSize)
            {
                product.AllSizeAttributes = _manageSizeAttributesService.GetSizeAttributesBySizeCaategoryId(Id.Value, CurrentLanguage);
            }
            return(View(product));
        }
Esempio n. 29
0
        public AddProductVM GetAddProductVM(int subCategoryId)
        {
            var manufacturersSelectList = this.GetManufacturersSelectList();

            var subCategory = this.Context.SubCategories.Find(subCategoryId);

            if (subCategory == null)
            {
                return(null);
            }

            var productVM = new AddProductVM
            {
                DepartmentId  = subCategory.Category.Department.Id,
                CategoryId    = subCategory.Category.Id,
                SubCategoryId = subCategoryId,
                Manufacturers = manufacturersSelectList
            };

            return(productVM);
        }
Esempio n. 30
0
        //Product

        public ActionResult AddProduct()
        {
            ViewBag.Message = "Add product page.";
            AddProductVM acVM = new AddProductVM();
            var          cats = db.Categories.ToList();

            acVM.AllCategories = Mapper.Map <List <CategoryVM> >(cats);
            acVM.AllProducts   = Mapper.Map <ICollection <ProductVM> >(db.Products.ToList());


            acVM.CurrentProduct          = new ProductVM();
            acVM.CurrentProduct.Pictures = new List <PictureVM>();

            //fill blank pictures
            for (int i = 0; i < 4; i++)
            {
                acVM.CurrentProduct.Pictures.Add(new PictureVM());
            }

            return(View(acVM));
        }