Ejemplo n.º 1
0
 public ActionResult AddProduct(ProductUpload upload)
 {
     try
     {
         HttpPostedFileBase file = upload.imageFile;
         if (file.ContentLength > 0)
         {
             Product product = GetProductFromUpload(upload);
             productDAO.Add(product);
             string path = Server.MapPath("~/images/item/") + file.FileName;
             file.SaveAs(path);
             return(RedirectToAction("Index"));
         }
         else
         {
             ViewBag.Error = "Thêm sản phẩm thất bại!";
             return(View("Error"));
         }
     }
     catch
     {
         ViewBag.Error = "Thêm sản phẩm thất bại!";
         return(View("Error"));
     }
 }
Ejemplo n.º 2
0
        public ActionResult CreateProduct(Product product)
        {
            ProductDAO productDAO = new ProductDAO();

            productDAO.Add(product);
            return(View());
        }
Ejemplo n.º 3
0
        public static bool WriteStringToDB(string Line)
        {
            string[] Objects = Line.Split(SEPARATOR);
            //Description; Ref; Marque; Famille; Sous - Famille; Prix H.T.
            string Description = Objects[0];
            string Ref         = Objects[1];
            Brand  Brand       = new Brand(Objects[2]);

            Brand = BrandDAO.Add(Brand);

            Category Category = new Category(Objects[3]);

            Category = CategoryDAO.Add(Category);

            SubCategory SubCategory = new SubCategory(Objects[4], Category);

            SubCategory = SubCategoryDAO.Add(SubCategory);

            float Price = 0;

            Objects[5] = Objects[5].Replace(',', '.');
            Price      = float.Parse(Objects[5], CultureInfo.InvariantCulture.NumberFormat);
            Product Product = new Product(Description, Ref, Brand, SubCategory, Price, 0);



            if (ProductDAO.Add(Product) != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
 public int Add(Product product)
 {
     try
     {
         return(productDAO.Add(product));
     }
     catch (SqlException ex) {
         throw ex;
     }
 }
Ejemplo n.º 5
0
 public HttpResponseMessage Post([FromBody] Product product)
 {
     try
     {
         ProductDAO productDAO = new ProductDAO();
         productDAO.Add(product);
         return(Request.CreateResponse(HttpStatusCode.OK, $"{product.nameProduct} added successfully"));
     }
     catch (Exception)
     {
         return(Request.CreateResponse(HttpStatusCode.NotFound));
     }
 }
Ejemplo n.º 6
0
        // ============= Modified Data =============
        //Product Attribute
        public ProductDTO AddAttrDTOs(string productId, ProductDTO productDTO)
        {
            Product prod = ObjectMapperTo <ProductDTO, Product>(productDTO);

            if (prod == null)
            {
                return(null);
            }
            var detailId = DataHelper.GetDetailId(productId);

            prod.ProductDetailId = detailId;
            prod.Id     = detailId + "A" + DateTime.Now.Second;
            prod.isShow = true;
            using (ProductDAO db = new ProductDAO(_context))
                return(ObjectMapperTo <Product, ProductDTO>(db.Add(prod)));
        }
Ejemplo n.º 7
0
 public void InsertProduct(string name, float price, int quantity, int cateId)
 {
     if (string.IsNullOrWhiteSpace(name))
     {
         throw new Exception("Have null or White Space on text name!");
     }
     else
     {
         ProductDTO dto = new ProductDTO(0, name, price, quantity, cateId);
         if (productDAO.Add(dto))
         {
             //do not thing
         }
         else
         {
             throw new Exception("Insert Fail!");
         }
     }
 }
Ejemplo n.º 8
0
        public ActionResult addProduct()
        {
            Database db;
            int      typeID = Int32.Parse(Request.Params["protype_id"]);

            string[] brandID = Request.Form.GetValues("probrand_id");

            ProductTypeModel ptModel = new ProductTypeModel();

            ptModel.PRO_TYP_ID = typeID;

            for (int i = 0; i < brandID.Length; i++)
            {
                ProductBrandModel pbModel = new ProductBrandModel();
                pbModel.PRO_BRAND_ID = Int32.Parse(brandID[i]);

                ProductModel pModel = new ProductModel();
                pModel.BANRD = pbModel;
                pModel.TYPE  = ptModel;

                // ค้นข้อมูลมา ตรวจสอบค่าก่อนจะเพิ่มลงฐานข้อมูล
                db = new Database();
                ProductDAO pDAO = new ProductDAO(db);
                bool       tf   = pDAO.HasField(pModel);        // ค้นหาจาก Type and brand
                db.Close();

                // ถ้าไม่มีให้เพิ่มได้ ถ้ามีไม่ต้องทำอะไร
                if (!tf)
                {
                    db   = new Database();
                    pDAO = new ProductDAO(db);
                    pDAO.Add(pModel);
                    db.Close();
                }
            }

            return(RedirectToAction("ManageProduct", "Product"));
        }
Ejemplo n.º 9
0
 public bool Add(Product product)
 {
     return(dao.Add(product));
 }
Ejemplo n.º 10
0
 public void CreateProduct(Product product)
 {
     productRepo.Add(product);
 }
Ejemplo n.º 11
0
 public void Add(Product t)
 {
     ProductDAO.Add(t);
 }