Пример #1
0
        public void Add_NewProduct_Success()
        {
            // Arrange
            var product = new Product {
                Sku = 1, Name = "Nome teste", Inventory = new Inventory()
            };

            // Act
            productDao.Add(product);

            // Assert
            Assert.Contains(product, products);
        }
Пример #2
0
 public void AddProduct(Order order, Product product)
 {
     // The way this method works seems like it should be in a ProductService
     // rather than in the OrderService.
     product.OrderId = _order.Id;
     ProductDao.Add(product);
 }
Пример #3
0
        public ActionResult Add(string MLLK, string MLM, string TLK, string TSKT, string MT, HttpPostedFileBase photo)
        {
            ViewBag.Title = "Thêm sản phẩm mới";
            var product = new Product();

            product.ID         = int.Parse(MLLK);
            product.CategoryID = int.Parse(MLM);

            product.Name   = TLK;
            product.Detail = TSKT;

            product.Description = MT;
            if (ModelState.IsValid)
            {
                if (photo != null && photo.ContentLength > 0)
                {
                    var path = Path.Combine(Server.MapPath("~/Areas/Admin/Content/Photo/"),
                                            System.IO.Path.GetFileName(photo.FileName));
                    photo.SaveAs(path);
                    product.Image = photo.FileName;
                    var dao = new ProductDao();
                    dao.Add(product);
                }
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(product));
            }
        }
Пример #4
0
 public ActionResult Add(ProductModel model, HttpPostedFileBase imgfile)
 {
     if (ModelState.IsValid)
     {
         var check = new ProductDao().CheckName(model.Name);
         if (check == null)
         {
             var imgPath = Encryption.SaveImg(imgfile);
             var imgsrc  = "/Content/images/hoaqua/" + imgPath;
             var dao     = new ProductDao();
             var prod    = new Product();
             prod.Name          = model.Name;
             prod.CategoryID    = model.CategoryID;
             prod.Price         = model.Price;
             prod.PromotionPice = model.PromotionPice;
             prod.Quantity      = model.Quantity;
             prod.ViewCount     = 0;
             prod.Image         = imgsrc;
             dao.Add(prod);
             return(Json(new { isok = true, message = "Thêm thành công !" }));
         }
         else
         {
             return(Json(new { isok = false, message = "Sản phẩm đã tồn tại." }));
         }
     }
     else
     {
         return(Json(new { isok = false, message = "Your Message" }));
     }
 }
Пример #5
0
        public ActionResult Add(string idcategories, string idtrademark, string name, string transport, string oldprice, string newprice, string number, string Levelsong, string Unit, HttpPostedFileBase photo)
        {
            Product product = new Product();


            product.name         = name;
            product.transport    = transport;
            product.oldprice     = Int32.Parse(oldprice);
            product.newprice     = Int32.Parse(newprice);
            product.number       = Int32.Parse(number);
            product.Levelsong    = Levelsong;
            product.idcategories = Int32.Parse(idcategories);
            product.idtrademark  = Int32.Parse(idtrademark);
            if (ModelState.IsValid)
            {
                if (photo != null && photo.ContentLength > 0)
                {
                    var path = Path.Combine(Server.MapPath("~/Areas/Admin/Content/photo/"),
                                            System.IO.Path.GetFileName(photo.FileName));
                    photo.SaveAs(path);
                    product.picture = photo.FileName;
                    ProductDao dao = new ProductDao();
                    dao.Add(product);
                }
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(product));
            }
        }
        public ActionResult Create(string name, string description, string information, string review, string availability, string price, string salePercent, string salePrice, string rate, HttpPostedFileBase mainPhoto, HttpPostedFileBase photo1, HttpPostedFileBase photo2, HttpPostedFileBase photo3, HttpPostedFileBase photo4, string updated, string id_category)
        {
            Product product = new Product();

            product.name         = name;
            product.description  = description;
            product.information  = information;
            product.review       = Convert.ToInt32(review);
            product.availability = Convert.ToBoolean(availability);
            product.price        = Convert.ToDecimal(price);
            product.salePercent  = Convert.ToInt32(salePercent);
            product.salePrice    = Convert.ToDecimal(salePrice);
            product.rate         = float.Parse(rate);
            product.updated      = DateTime.Parse(updated);
            product.id_category  = Convert.ToInt32(id_category);

            if (ModelState.IsValid)
            {
                if (mainPhoto != null && mainPhoto.ContentLength > 0)
                {
                    var path = Path.Combine(Server.MapPath("~/Areas/Admin/Content/Photos/"), System.IO.Path.GetFileName(mainPhoto.FileName));
                    mainPhoto.SaveAs(path);
                    product.mainPhoto = mainPhoto.FileName;
                }
                if (photo1 != null && photo1.ContentLength > 0)
                {
                    var path = Path.Combine(Server.MapPath("~/Areas/Admin/Content/Photos/"), System.IO.Path.GetFileName(photo1.FileName));
                    photo1.SaveAs(path);
                    product.photo1 = photo1.FileName;
                }
                if (photo2 != null && photo2.ContentLength > 0)
                {
                    var path = Path.Combine(Server.MapPath("~/Areas/Admin/Content/Photos/"), System.IO.Path.GetFileName(photo2.FileName));
                    photo2.SaveAs(path);
                    product.photo2 = photo2.FileName;
                }
                if (photo3 != null && photo3.ContentLength > 0)
                {
                    var path = Path.Combine(Server.MapPath("~/Areas/Admin/Content/Photos/"), System.IO.Path.GetFileName(photo3.FileName));
                    photo3.SaveAs(path);
                    product.photo3 = photo3.FileName;
                }
                if (photo4 != null && photo4.ContentLength > 0)
                {
                    var path = Path.Combine(Server.MapPath("~/Areas/Admin/Content/Photos/"), System.IO.Path.GetFileName(photo4.FileName));
                    photo4.SaveAs(path);
                    product.photo4 = photo4.FileName;
                }
                Pdao.Add(product);
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(product));
            }
        }
Пример #7
0
        public ActionResult About()
        {
            Category category = new Category {
                Id = 23, Name = "TabletPc"
            };
            Product product = new Product {
                Name = "Apple", Discontinued = "true", Category = category
            };
            ProductDao productDao = ProductDao.GetInstance();

            productDao.Add(product);



            return(View());
        }
Пример #8
0
        public ActionResult Salvar(Product product)
        {
            ProductDao productDao = ProductDao.GetInstance();

            product.Category = CategoryDao.GetInstance().GetById(product.Category.Id);
            /* cadastrar */
            if (product.Id == 0)
            {
                productDao.Add(product);
                return(RedirectToAction("Index", "Product"));
            }
            /* Editar */
            else
            {
                productDao.Update(product);
                return(RedirectToAction("Index", "Product"));
            }
        }
Пример #9
0
        public ActionResult Edit(int id, string MLLK, string MLM, string MNCC, string TLK, string TSKT, string TGBH, string MT, HttpPostedFileBase photo, string photos)
        {
            ViewBag.Title = "Cập nhật giá trị mới cho sản phẩm";
            ProductDao dao     = new ProductDao();
            var        product = dao.getById(id);

            if (ModelState.IsValid)
            {
                if (photo != null && photo.ContentLength > 0)
                {
                    var path = Path.Combine(Server.MapPath("~/Areas/Admin/Content/Photo/"),
                                            System.IO.Path.GetFileName(photo.FileName));
                    photo.SaveAs(path);

                    product.Image = photo.FileName;
                }
                dao.Add(product);
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(product));
            }
        }
Пример #10
0
        public ActionResult Create(ProductsView product, string saveclose, string savenew)
        {
            var actionStatus = new ActionResultHelper();

            actionStatus.ActionStatus = ResultSubmit.failed;
            string errorString = "";
            bool   IsValid     = true;

            if (ModelState.IsValid)
            {
                var DAO = new ProductDao();
                product.CatalogueId = SiteConfiguration.CatalogueId;
                //product.CatalogueId = SiteConfiguration.CatalogueId;
                product.CreatedBy = CurrentUser.UserID;

                if (product.Images != null && !String.IsNullOrWhiteSpace(product.Images.FileName))
                {
                    string path = Path.Combine(Server.MapPath("~/Images/Products/large"), Path.GetFileName(product.MetaTitle + "_" + product.Images.FileName));
                    product.Images.SaveAs(path);
                    //resize cho vao tung thu muc
                    ImageHelper.CreateThumbnail(150, 150, path, Server.MapPath("~/Images/Products/small/"));
                    ImageHelper.CreateThumbnail(80, 80, path, Server.MapPath("~/Images/Products/min/"));
                    ImageHelper.CreateThumbnail(500, 500, path, Server.MapPath("~/Images/Products/medium/"));
                }

                var result = DAO.Add(product);

                if (result != null && result.Id > 0)
                {
                    actionStatus.ErrorReason  = String.Format(SiteResource.HTML_ALERT_SUCCESS, SiteResource.MSG_THE_PRODUCT_HAS_BEEN_CREATED);
                    actionStatus.ActionStatus = ResultSubmit.success;
                    //Session[SessionName.ActionStatusLog] = actionStatus;
                    //return RedirectToAction("Index");
                    Session[SessionName.ActionStatusLog] = actionStatus;
                    if (!String.IsNullOrEmpty(saveclose))
                    {
                        return(RedirectToAction("Index"));
                    }
                    else if (!String.IsNullOrWhiteSpace(savenew))
                    {
                        return(RedirectToAction("Create"));
                    }
                    else
                    {
                        return(RedirectToAction("Edit", new { Id = result.Id }));
                    }
                }
                else
                {
                    actionStatus.ErrorStrings.Add(SiteResource.MSG_THE_PRODUCT_HAS_NOT_BEEN_CREATED);
                    goto actionError;
                }
            }
            else
            {
                IsValid = false;
                foreach (var item in ModelState.Values)
                {
                    if (item.Errors.Count() > 0)
                    {
                        var errorItems = item.Errors.Where(f => !String.IsNullOrWhiteSpace(f.ErrorMessage)).ToList();
                        foreach (var erroritem in errorItems)
                        {
                            errorString += "<br />" + erroritem.ErrorMessage;
                        }
                    }
                }
                goto actionError;
            }

actionError:
            if (!IsValid)
            {
                actionStatus.ErrorReason = String.Format(SiteResource.HTML_ALERT_WARNING, SiteResource.MSG_ERROR_ENTER_DATA_FOR_FORM + errorString);
                Session["ACTION_STATUS"] = actionStatus;
            }
            return(RedirectToAction("Index"));
        }
Пример #11
0
        public ActionResult ImportProduct()
        {
            List <ProductsView> products = new List <ProductsView>();

            try
            {
                //Read the contents of CSV file.
                string filePath = string.Empty;
                string path     = Server.MapPath("~/App_Data/");

                filePath = path + Path.GetFileName("thuc-pham-chay-truyen-thong.csv");

                string csvData = System.IO.File.ReadAllText(filePath);
                var    DAO     = new ProductDao();

                //Execute a loop over the rows.
                foreach (string row in csvData.Split('\n'))
                {
                    if (!string.IsNullOrEmpty(row))
                    {
                        string productName = row.Split(',')[0];
                        double price       = Convert.ToInt64(row.Split(',')[1]);
                        double weight      = Convert.ToInt32(row.Split(',')[3]);

                        var proDetails = new List <ProductDetailModel>();
                        proDetails.Add(new ProductDetailModel()
                        {
                            ProductPrice = price, ProductWeight = weight, PriceTypeId = 1
                        });

                        products.Add(new ProductsView
                        {
                            Name          = productName,
                            MetaTitle     = StringHelper.ToUnsignString(productName.Trim().ToLower()),
                            ProductDetail = proDetails,
                            CategoryID    = Convert.ToInt32(row.Split(',')[2]),
                            CatalogueId   = SiteConfiguration.CatalogueId,
                            Language      = Session[CommonConstants.CurrentCulture].ToString(),
                            Description   = "",
                            Detail        = "",
                            Status        = nameof(StatusEntity.Active),
                            CreatedBy     = 2,
                            CreatedDate   = DateTime.Now,
                            ModifiedBy    = 2,
                            ModifiedDate  = DateTime.Now,
                            ViewCount     = 0,
                        });
                    }
                }

                bool isTesing = false;
                if (products.Count > 0 && !isTesing)
                {
                    foreach (var item in products)
                    {
                        var result = DAO.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
            }

            //return View(products);

            return(RedirectToAction("Index"));
        }