Ejemplo n.º 1
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product product = db.Products.Find(id);

            if (product == null)
            {
                return(HttpNotFound());
            }

            var model = new ProductAdminViewModel
            {
                Name          = product.Name,
                CategoryID    = product.CategoryID,
                BrandID       = product.BrandID,
                Price         = product.Price,
                discontinued  = product.discontinued,
                DescriptionEN = product.DescriptionEN,
                DescriptionFR = product.DescriptionFR
            };

            ViewBag.BrandID    = new SelectList(db.ProductBrands, "Id", "Name", product.BrandID);
            ViewBag.CategoryID = new SelectList(db.ProductCategories, "Id", "Name", product.CategoryID);
            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ChangeOrRemoveProduct(Guid guid, bool delete = false)
        {
            if (await _adminRepository.GetProductByIdAsync(guid) != null)
            {
                var product = await _adminRepository.GetProductByIdAsync(guid);

                ViewBag.guid = guid;
                var item = new ProductAdminViewModel()
                {
                    Category                 = product.Category,
                    DiscountPercentage       = product.DiscountPercentage,
                    Comments                 = product.Comments,
                    ImgSource                = product.ImgSource,
                    HtmlProductDemonstration = product.HtmlProductDemonstration,
                    Name   = product.Name,
                    Price  = product.Price,
                    Slogan = product.Slogan
                };
                return(View("ChangeOrRemove/ChangeOrRemoveProduct", item));
            }
            if (delete == true)
            {
                await _adminRepository.DeleteProduct(guid);

                return(View("ChangeOrRemove/GetId"));
            }
            if (guid != Guid.Empty)
            {
                ModelState.AddModelError("", "شناسه نامعتبر است");
            }
            return(View("ChangeOrRemove/GetId"));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int id, FormCollection form)
        {
            Product product = _wineRepository.FindProdById(id);

            try
            {
                UpdateModel(product, "Product");
                product.PhotoUrl = form["PhotoUrl"].ToString();
                _wineRepository.Save();

                return(RedirectToAction("Index"));
            }
            catch
            {
                ProductAdminViewModel viewModel = new ProductAdminViewModel()
                {
                    Product   = product,
                    Countries = _wineRepository.FindAllCountries().ToList(),
                    Grapes    = _wineRepository.FindAllGrapes().ToList(),
                    Wines     = _wineRepository.FindAllWines().ToList(),
                    Producers = _wineRepository.FindAllProducers().ToList(),
                    Promotes  = _wineRepository.FindAllPromotes().ToList(),
                    Tastes    = _wineRepository.FindAllTastes().ToList()
                };
                return(View());
            }
        }
Ejemplo n.º 4
0
        public ActionResult ParseProduct(string productURL)
        {
            Product product = new Product();

            product.ID = 0;
            if (productURL != null)
            {
                Product tempProduct = null;
                if (productURL.ToLower().Contains("next"))
                {
                    tempProduct = this.nextParser.ParseNextProduct(productURL);
                }
                else if (productURL.ToLower().Contains("boden"))
                {
                    tempProduct = this.bodenParser.ParseBodenProduct(productURL);
                }

                if (tempProduct != null)
                {
                    product = tempProduct;
                }
            }
            else
            {
                TempData["message"] = @"Invalid product link";
            }

            ProductAdminViewModel productViewModel = new ProductAdminViewModel()
            {
                product = product, prices = product.GetPriceInfos()
            };

            return(View("Edit", productViewModel));
        }
        public HttpResponseMessage GetAll()
        {
            ProductAdminViewModel kq       = new ProductAdminViewModel();
            List <ProductSModel>  products = new List <ProductSModel>();

            using (MobileStoreServiceEntities data = new MobileStoreServiceEntities())
            {
                List <PRODUCT> pro = data.PRODUCTs.ToList();
                kq.Mans = data.MANUFACTUREs.ToList();
                kq.Cats = data.CATEGORies.ToList();

                foreach (var item in pro)
                {
                    ProductSModel s = new ProductSModel();
                    s.ID       = item.PRODUCT_ID;
                    s.Name     = item.MODEL;
                    s.Image    = item.PRODUCT_IMG;
                    s.Price    = item.PRICE;
                    s.Category = getNameOfCategory(item.PRODUCT_ID, data);
                    s.NSX      = getNameOfNXS((int)item.MANUFACTURE_ID, data);
                    s.Editing  = false;
                    s.Delete   = item.DELETED == 1;

                    products.Add(s);
                }

                kq.Products = products;
            }

            string json = JsonConvert.SerializeObject(products);

            return(CreateResponse(HttpStatusCode.OK, kq));
        }
        public ActionResult ProductsDestroy([DataSourceRequest]DataSourceRequest request, ProductAdminViewModel model)
        {
            if (ModelState.IsValid && model != null)
            {
                this.productsService.DeleteProduct(model.Id);
            }

            return Json(new[] { model }.ToDataSourceResult(request, ModelState));
        }
        public ViewResult Create()
        {
            ProductAdminViewModel model = new ProductAdminViewModel
            {
                Categories = _categoryRepository.GetAll()
            };

            return(View("Edit", model));
        }
        public ViewResult Edit(int id)
        {
            Product product             = _productRepository.GetById(id);
            ProductAdminViewModel model = _mapper.Map <ProductAdminViewModel>(product);

            model.Categories = _categoryRepository.GetAll();

            return(View(model));
        }
        public ActionResult Details(int id)
        {
            Product product             = _productRepository.GetById(id);
            ProductAdminViewModel model = _mapper.Map <ProductAdminViewModel>(product);

            model.Created = product.Created.ToLocalTime();
            model.Edited  = product.Edited.GetValueOrDefault().ToLocalTime();

            return(View(model));
        }
Ejemplo n.º 10
0
        public ViewResult Edit(int ID)
        {
            Product product = repository.Products
                              .FirstOrDefault(p => p.ID == ID);
            ProductAdminViewModel productViewModel = new ProductAdminViewModel()
            {
                product = product, prices = product.GetPriceInfos()
            };

            return(View(productViewModel));
        }
Ejemplo n.º 11
0
        public ActionResult Edit(ProductAdminViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", model));
            }

            _productRepository.Update(Mapper.Map <Product>(model));

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 12
0
        public ActionResult Create(ProductAdminViewModel product)
        {
            if (ModelState.IsValid)
            {
                CreateProduct(product);
                //db.Products.Add(product);
                //db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BrandID    = new SelectList(db.ProductBrands, "Id", "Name", product.BrandID);
            ViewBag.CategoryID = new SelectList(db.ProductCategories, "Id", "Name", product.CategoryID);
            return(View(product));
        }
Ejemplo n.º 13
0
        public ActionResult Edit(ProductAdminViewModel model)
        {
            var validImageTypes = new string[]
            {
                "image/gif",
                "image/jpeg",
                "image/pjpeg",
                "image/png"
            };

            if (model.ImageUpload != null)
            {
                if (model.ImageUpload != null || model.ImageUpload.ContentLength > 0 && !validImageTypes.Contains(model.ImageUpload.ContentType))
                {
                    ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image.");
                }
            }

            if (ModelState.IsValid)
            {
                var product = db.Products.Find(model.Id);
                if (product == null)
                {
                    return(new HttpNotFoundResult());
                }

                product.Name          = model.Name;
                product.Price         = model.Price;
                product.BrandID       = model.BrandID;
                product.CategoryID    = model.CategoryID;
                product.DescriptionFR = model.DescriptionFR;
                product.DescriptionEN = model.DescriptionEN;
                product.discontinued  = model.discontinued;

                if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0)
                {
                    var uploadDir = "~/uploads";
                    var imagePath = Path.Combine(Server.MapPath(uploadDir), model.ImageUpload.FileName);
                    var imageUrl  = Path.Combine(uploadDir, model.ImageUpload.FileName);
                    model.ImageUpload.SaveAs(imagePath);
                    product.PictureURL = imageUrl;
                }

                db.Entry(product).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Ejemplo n.º 14
0
        // id == ProductId
        public IActionResult ProductDetails(int id)
        {
            Product product = _admin.GetProduct(id);
            List <ProductGallery> productGalleries = _admin.GetProductGalleries(id);
            List <ProductField>   productFields    = _admin.GetProductFields(id);

            var viewModel = new ProductAdminViewModel();

            viewModel.FillProduct = product;
            viewModel.FillGallery = productGalleries;
            viewModel.FillField   = productFields;

            return(View(viewModel));
        }
        public ActionResult ProductsUpdate([DataSourceRequest]DataSourceRequest request, ProductAdminViewModel model)
        {
            if (ModelState.IsValid && model != null)
            {
                var updated = AutoMapper.Mapper.Map<Product>(model);          

                updated.UserId = this.CurrentUser.Id;
                var updatedmodel = this.productsService
                    .UpdateProduct(updated)
                    .ProjectTo<ProductAdminViewModel>()
                    .FirstOrDefault();
            }

            return Json(new[] { model }.ToDataSourceResult(request, ModelState));
        }
Ejemplo n.º 16
0
        public ActionResult Create([Bind(Exclude = "ImageMimeType")] ProductAdminViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", model));
            }

            model.ImageMimeType = model.ImageData?.ContentType;

            Product product = Mapper.Map <Product>(model);

            _productRepository.Create(product);

            return(RedirectToAction("Index"));
        }
        public ActionResult ProductsCreate([DataSourceRequest]DataSourceRequest request, ProductAdminViewModel model)
        {
            if (ModelState.IsValid && model != null)
            {
                var newProduct = Mapper.Map<Product>(model);

                newProduct.UserId = this.CurrentUser.Id;

                var result = this.productsService.AddProduct(newProduct);

                Mapper.Map(result, model);
            }

            return Json(new[] { model }.ToDataSourceResult(request, ModelState));
        }
Ejemplo n.º 18
0
        public ActionResult Create()
        {
            ProductAdminViewModel viewModel = new ProductAdminViewModel()
            {
                Product   = new Product(),
                Countries = _wineRepository.FindAllCountries().ToList(),
                Grapes    = _wineRepository.FindAllGrapes().ToList(),
                Wines     = _wineRepository.FindAllWines().ToList(),
                Producers = _wineRepository.FindAllProducers().ToList(),
                Promotes  = _wineRepository.FindAllPromotes().ToList(),
                Tastes    = _wineRepository.FindAllTastes().ToList()
            };

            return(View(viewModel));
        }
Ejemplo n.º 19
0
 public ActionResult Edit(ProductAdminViewModel productViewModel)
 {
     if (ModelState.IsValid)
     {
         Product product = productViewModel.product;
         product.SetPriceInfos(productViewModel.prices);
         repository.SaveProduct(product);
         TempData["message"] = string.Format("{0} has been saved", product.Title);
         return(RedirectToAction("Index"));
     }
     else
     {
         // there is something wrong with the data values
         return(View(productViewModel.product));
     }
 }
Ejemplo n.º 20
0
        public IActionResult AdminDisplay()
        {
            //call service
            IEnumerable <Product>  list = _productService.GetAll();
            IEnumerable <Category> cat  = _categoryService.GetAll();


            //vm
            ProductAdminViewModel vm = new ProductAdminViewModel
            {
                Products   = list,
                Categories = cat
            };

            //pass to view
            return(View(vm));
        }
Ejemplo n.º 21
0
        private void CreateProduct(ProductAdminViewModel model)
        {
            var validImageTypes = new string[]
            {
                "image/gif",
                "image/jpeg",
                "image/pjpeg",
                "image/png"
            };

            if (model.ImageUpload == null || model.ImageUpload.ContentLength == 0)
            {
                ModelState.AddModelError("ImageUpload", "This field is required");
            }
            else if (!validImageTypes.Contains(model.ImageUpload.ContentType))
            {
                ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image.");
            }


            if (ModelState.IsValid)
            {
                var product = new Product
                {
                    Name          = model.Name,
                    Price         = model.Price,
                    CategoryID    = model.CategoryID,
                    BrandID       = model.BrandID,
                    DescriptionEN = model.DescriptionEN,
                    DescriptionFR = model.DescriptionFR,
                    discontinued  = false
                };

                if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0)
                {
                    var uploadDir = "~/Images/Products/";
                    var imagePath = Path.Combine(Server.MapPath(uploadDir), Path.GetFileName(model.ImageUpload.FileName));
                    var imageUrl  = Path.Combine(uploadDir, Path.GetFileName(model.ImageUpload.FileName));
                    model.ImageUpload.SaveAs(imagePath);
                    product.PictureURL = imageUrl;
                    db.Products.Add(product);
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 22
0
        public ActionResult Index(int?page, int?ProductState, int?ProductCatalogry, string FillterSKU, string FillterProductCD, string FillterProductName)
        {
            int pageNum = (page ?? 1);
            ProductAdminViewModel model = new ProductAdminViewModel();
            IQueryable <Product>  tmp   = cms_db.GetlstProduct().Where(s => (s.MicrositeID == null || s.MicrositeID == 0) && s.StateId != (int)EnumCore.StateType.da_xoa);

            if (ProductCatalogry.HasValue && ProductCatalogry.Value != 0)
            {
                tmp = tmp.Where(s => s.CategoryId == ProductCatalogry);
                model.ProductCatalogry = ProductCatalogry.Value;
            }

            if (ProductState.HasValue && ProductState.Value != 0)
            {
                tmp = tmp.Where(s => s.StateId == ProductState);
                model.ProductState = ProductState.Value;
            }
            if (!String.IsNullOrEmpty(FillterSKU))
            {
                tmp = tmp.Where(s => s.SKUCode == FillterSKU);
                model.FillterSKU = FillterSKU;
            }
            if (!String.IsNullOrEmpty(FillterProductCD))
            {
                tmp = tmp.Where(s => s.ProductCD == FillterProductCD);
                model.FillterProductCD = FillterProductCD;
            }

            if (!String.IsNullOrEmpty(FillterProductName))
            {
                tmp = tmp.Where(s => s.ProductName.ToLower().Contains(FillterProductName.ToLower()));
                model.FillterProductCD = FillterProductCD;
            }

            if (tmp.Count() < (int)EnumCore.BackendConst.page_size)
            {
                pageNum = 1;
            }
            model.pageNum             = pageNum;
            model.lstMainProduct      = tmp.OrderByDescending(c => c.ProductId).ToPagedList(pageNum, (int)EnumCore.BackendConst.page_size);
            model.lstProductState     = new SelectList(cms_db.Getclasscatagory((int)EnumCore.ClassificationScheme.state_type), "value", "text");
            model.lstProductCatalogry = new SelectList(cms_db.Getclasscatagory((int)EnumCore.ClassificationScheme.san_pham), "value", "text");

            return(View(model));
        }
Ejemplo n.º 23
0
        public override void Setup()
        {
            base.Setup();
            _model                 = new ProductAdminViewModel();
            _productRepository     = new Mock <IProductRepository>();
            _categoryRepository    = new Mock <IRepository <Category> >();
            _subcategoryRepository = new Mock <IRepository <Subcategory> >();
            _controller            = new ProductAdminController(
                _productRepository.Object,
                _categoryRepository.Object,
                _subcategoryRepository.Object,
                _unitOfWork.Object,
                _userManager.Object,
                _mapper.Object
                );

            MockHttpContext();
        }
Ejemplo n.º 24
0
        public void Cannot_Save_Invalid_Changes()
        {
            // Arrange - create mock repository
            Mock <IProductRepository> mock = new Mock <IProductRepository>();
            // Arrange - create the controller
            AdminController target = new AdminController(mock.Object);
            // Arrange - create a product
            Product product = new Product {
                Title = "Test"
            };

            // Arrange - add an error to the model state
            target.ModelState.AddModelError("error", "error");

            PriceInfo[] sizePrices = new PriceInfo[3]
            {
                new PriceInfo {
                    Size = "S", Price = 10, Stock = "In Stock"
                },
                new PriceInfo {
                    Size = "M", Price = 20, Stock = "In Stock"
                },
                new PriceInfo {
                    Size = "L", Price = 30, Stock = "In Stock"
                }
            };
            // Act - try to save the product
            ProductAdminViewModel productViewModel = new ProductAdminViewModel()
            {
                product = product, prices = sizePrices
            };
            ActionResult result = target.Edit(productViewModel);

            // Assert - check that the repository was not called
            mock.Verify(m => m.SaveProduct(It.IsAny <Product>()), Times.Never());
            // Assert - check the method result type
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> AddProduct(ProductAdminViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var item = new Product()
                {
                    ProductId                = Guid.NewGuid(),
                    Category                 = viewModel.Category,
                    DiscountPercentage       = viewModel.DiscountPercentage,
                    Comments                 = viewModel.Comments,
                    ImgSource                = viewModel.ImgSource,
                    HtmlProductDemonstration = viewModel.HtmlProductDemonstration,
                    Name        = viewModel.Name,
                    Price       = viewModel.Price,
                    ReleaseDate = DateTime.UtcNow,
                    Slogan      = viewModel.Slogan
                };
                await _adminRepository.AddProduct(item);

                return(View());
            }
            return(View(viewModel));
        }
Ejemplo n.º 26
0
        public void Can_Save_Valid_Changes()
        {
            // Arrange - create mock repository
            Mock <IProductRepository> mock = new Mock <IProductRepository>();
            // Arrange - create the controller
            AdminController target = new AdminController(mock.Object);
            // Arrange - create a product
            Product product = new Product {
                ID = 0, Title = "Test"
            };

            PriceInfo[] sizePrices = new PriceInfo[3]
            {
                new PriceInfo {
                    Size = "S", Price = 10, Stock = "In Stock"
                },
                new PriceInfo {
                    Size = "M", Price = 20, Stock = "In Stock"
                },
                new PriceInfo {
                    Size = "L", Price = 30, Stock = "In Stock"
                }
            };

            // Act - try to save the product
            ProductAdminViewModel productViewModel = new ProductAdminViewModel()
            {
                product = product, prices = sizePrices
            };
            ActionResult result = target.Edit(productViewModel);

            // Assert - check that the repository was called
            mock.Verify(m => m.SaveProduct(product));
            // Assert - check the method result type
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }
Ejemplo n.º 27
0
        public async Task <IActionResult> ChangeOrRemoveProduct([FromRoute] Guid guid, [FromBody] ProductAdminViewModel viewModel)
        {
            if (viewModel.Name != null && viewModel.Category != 0 && viewModel.Price != 0)
            {
                var changedItem = new Product()
                {
                    ProductId                = Guid.NewGuid(),
                    Category                 = viewModel.Category,
                    DiscountPercentage       = viewModel.DiscountPercentage,
                    Comments                 = viewModel.Comments,
                    ImgSource                = viewModel.ImgSource,
                    HtmlProductDemonstration = viewModel.HtmlProductDemonstration,
                    Name        = viewModel.Name,
                    Price       = viewModel.Price,
                    ReleaseDate = DateTime.UtcNow,
                    Slogan      = viewModel.Slogan
                };
                await _adminRepository.DeleteProduct(guid);

                await _adminRepository.AddProduct(changedItem);

                return(View("ChangeOrRemove/GetId"));
            }

            ModelState.AddModelError("", "فیلد نام و دسته بندی و قیمت اجباری است");
            return(View("ChangeOrRemove/ChangeOrRemoveProduct", viewModel));
        }
Ejemplo n.º 28
0
        public ActionResult ProductsDestroy([DataSourceRequest] DataSourceRequest request, ProductAdminViewModel model)
        {
            if (ModelState.IsValid && model != null)
            {
                this.productsService.DeleteProduct(model.Id);
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
Ejemplo n.º 29
0
        public ActionResult ProductsUpdate([DataSourceRequest] DataSourceRequest request, ProductAdminViewModel model)
        {
            if (ModelState.IsValid && model != null)
            {
                var updated = AutoMapper.Mapper.Map <Product>(model);

                updated.UserId = this.CurrentUser.Id;
                var updatedmodel = this.productsService
                                   .UpdateProduct(updated)
                                   .ProjectTo <ProductAdminViewModel>()
                                   .FirstOrDefault();
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
Ejemplo n.º 30
0
        public ActionResult ProductsCreate([DataSourceRequest] DataSourceRequest request, ProductAdminViewModel model)
        {
            if (ModelState.IsValid && model != null)
            {
                var newProduct = Mapper.Map <Product>(model);

                newProduct.UserId = this.CurrentUser.Id;

                var result = this.productsService.AddProduct(newProduct);

                Mapper.Map(result, model);
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }