Пример #1
0
        public HttpResponseMessage AddProduct(Product product)
        {
            ResponseMessage <Product> objResponseData = new ResponseMessage <Product>();

            try
            {
                DataTable  tempProductImages = new DataTable();
                DataColumn dc = new DataColumn("TempId", typeof(int));   //creating first column of datatable
                tempProductImages.Columns.Add(dc);
                dc = new DataColumn("ImageUrl", typeof(String));         //creating second column of datatable
                tempProductImages.Columns.Add(dc);

                int result = objProductDAL.AddProduct(product, tempProductImages);
                if (result != 0)
                {
                    objResponseData = ResponseHandler <Product> .CreateResponse(objResponseData, "Successfully Added A New Product.", product, HttpStatusCode.OK);
                }
                else
                {
                    objResponseData = ResponseHandler <Product> .CreateResponse(objResponseData, "Can't Add This Product.", HttpStatusCode.Conflict);
                }
            }
            catch (System.Exception ex)
            {
                objErrorLogger.ErrorLog(ex);
                objResponseData = ResponseHandler <Product> .CreateErrorResponse(objResponseData);
            }
            return(Request.CreateResponse(objResponseData.StatusCode, objResponseData));
        }
Пример #2
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            ConfigurationData config = GetConfigurationDetails();

            // Uncomment following to get Customer records
            CustomerDAL.AddCustomer(config);
            ProductDAL.AddProduct(config);
            //CoverKingDAL.SaveBaseVehicleAppData(config.ConnectionString);
            //CoverKingDAL.SaveItemVariantImages(config.ConnectionString);
            CsvFilebase baseCSBV = new CsvFilebase();
            string      filePath =
                Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string coverkingPath = Path.Combine(filePath, "../../CoverKingData/");

            /*
             * DirectoryInfo dirApp = new DirectoryInfo(Path.Combine(coverkingPath, "AppData/Incoming/"));
             * foreach (var file in dirApp.GetFiles())
             * {
             *  var aData = baseCSBV.Read<DownloadVariant>(file.FullName, true);
             *  CoverKingDAL.Save(config.ConnectionString, aData);
             *  file.MoveTo(Path.Combine(coverkingPath, "AppData/Processed/" + file.Name));
             * }
             */
            DirectoryInfo dirJobber = new DirectoryInfo(Path.Combine(coverkingPath, "Jobber/Incoming/"));

            foreach (var file in dirJobber.GetFiles())
            {
                var jData = baseCSBV.Read <DownloadedItem>(file.FullName, true, new Dictionary <string, string>()
                {
                    { "ItemOrSKU", "Item/SKU" },
                    { "UPC_Code", "UPC Code" },
                    { "Gross_Weight", "Gross Weight" },
                    { "Product_Family_ID", "ProductFamily ID" },
                    { "Product_Family_Description", "Product Family Description" },
                });
                CoverKingDAL.Save(config.ConnectionString, jData);
                file.MoveTo(Path.Combine(coverkingPath, "Jobber/Processed/" + file.Name));
            }

            DirectoryInfo dirAmazon = new DirectoryInfo(Path.Combine(coverkingPath, "AmazonVariant/Incoming/"));

            foreach (var file in dirAmazon.GetFiles())
            {
                var amazonVariantData = baseCSBV.Read <AmazonVariant>(file.FullName, true,
                                                                      new Dictionary <string, string>()
                {
                    { "SKUOrUPC", "SKU/UPC" },
                });
                CoverKingDAL.Save(config.ConnectionString, amazonVariantData);
                file.MoveTo(Path.Combine(coverkingPath, "Jobber/Processed/" + file.Name));
            }
            CoverKingDAL.SaveProductOnJobber(config.ConnectionString);

            //OrderDAL.PlaceOrder(config, true, true, true);
        }
Пример #3
0
 public bool AddProduct(Product sp)
 {
     if (sp != null)
     {
         pdal.AddProduct(sp);//gọi phương thức từ DAL
         return(true);
     }
     return(false);
 }
Пример #4
0
 public ActionResult NewProduct(ProductModel model)
 {
     if (ModelState.IsValid)
     {
         model.ProductImageAddress = "/Images/" + Guid.NewGuid() + ".jpg";
         model.ProductImageFile.SaveAs(Server.MapPath(model.ProductImageAddress));
         ProductDAL dal = new ProductDAL();
         int        id  = dal.AddProduct(model);
         ViewBag.msg = "Product Added : " + id;
         ModelState.Clear();
         ViewBag.category = dal.GetCategory();
         return(RedirectToAction("Index", "Product"));
     }
     else
     {
         ProductDAL dal = new ProductDAL();
         ViewBag.category = dal.GetCategory();
         return(View());
     }
 }
Пример #5
0
        public async Task <IActionResult> Create(Product product)
        {
            product.UserId = Convert.ToInt32(HttpContext.Session.GetInt32("UserId"));

            // Find the filename extension of the file to be uploaded.
            string fileExt = Path.GetExtension(product.Image.FileName);

            int    productId    = productContext.GetAllProducts().Count + 1;
            string uploadedFile = "Product" + productId + fileExt;
            string savePath     = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images", uploadedFile);

            // Upload the file to server
            using (var fileSteam = new FileStream(savePath, FileMode.Create))
            {
                await product.Image.CopyToAsync(fileSteam);
            }
            product.ImageUrl = uploadedFile;
            productContext.AddProduct(product);

            TempData["product_success"] = "Succussfully Created Product";
            return(View());
        }
Пример #6
0
        public ActionResult Add(Product objProduct, HttpPostedFileBase images)
        {
            if (images != null)
            {
                string path = Path.Combine(Server.MapPath("~/UploadedFiles/"), Path.GetFileName(images.FileName));
                images.SaveAs(path);
                ViewBag.path = "~/UploadedFiles/" + Path.GetFileName(images.FileName);
            }
            objProduct.AddedBy = "Admin";
            objProduct.AddedOn = DateTime.Now;

            objProduct.images   = Path.GetFileName(images.FileName);
            objProduct.ImageURL = ViewBag.path;
            int i = pDAL.AddProduct(objProduct);

            if (i == 0)
            {
                ViewBag.Message = "Data Added Sucessfully";
            }
            //return View(objProduct);
            return(RedirectToAction("Add"));
        }
Пример #7
0
        public bool AddProduct(Product p)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            var      lstImages = serializer.Deserialize <List <string> >(p.MoreImages);
            XElement element   = new XElement("Images");

            foreach (var item in lstImages)
            {
                element.Add(new XElement("Image", item));
            }
            p.Alias      = Tools.GetAlias(p.Name);
            p.MoreImages = element.ToString();
            if (!string.IsNullOrEmpty(p.CreatedDate.ToString()))
            {
                p.CreatedDate = DateTime.ParseExact(p.CreatedDate.ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            else
            {
                p.CreatedDate = DateTime.Now;
            }
            p.ViewCount = 0;
            return(productDAL.AddProduct(p));
        }
Пример #8
0
        public ActionResult AddToCart(int id, int Qty)
        {
            TempData["Qty"] = Qty;
            double amount = Convert.ToInt32(TempData["Qty"]) * Convert.ToDouble(TempData["UnitPrice"]);

            ViewBag.Amount = amount;
            ProductModel prodData   = new ProductModel();
            ProductDAL   productDAL = new ProductDAL();
            Products     prod       = new Products();

            prod = productDAL.GetProduct(id);

            prodData.ProductID   = prod.ProductID;
            prodData.ProductName = prod.ProductName;
            prodData.UnitPrice   = prod.UnitPrice;
            prodData.Quantity    = Convert.ToInt32(TempData["Qty"]);

            prod.ProductID   = id;
            prod.ProductName = prodData.ProductName;
            prod.UnitPrice   = prodData.UnitPrice;
            prod.Quantity    = prodData.Quantity;
            productDAL.AddProduct(prod);
            return(View(prodData));
        }
Пример #9
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Product product = null;
            int     id      = -1;

            int.TryParse(Request.QueryString["id"], out id);
            bool isExists = new ProductDAL().Exists(txtProductCode.Text,
                                                    txtHuangliaoCode.Text,
                                                    txtJiaCode.Text,
                                                    txtPianCode.Text,
                                                    id
                                                    );

            if (isExists)
            {
                Page.RegisterClientScriptBlock("product", "<script language='javascript'>alert('已经有相同的产品!');</script>");
                return;
            }
            if (string.Equals(ViewType, "edit", StringComparison.OrdinalIgnoreCase))
            {
                ProductDAL dal = new ProductDAL();

                product = dal.GetProductById(ProductId);
                product.Product_Code  = txtProductCode.Text;
                product.Product_Name  = txtProductName.Text;
                product.HuangliaoCode = txtHuangliaoCode.Text;
                product.JiaCode       = txtJiaCode.Text;
                product.PianCode      = txtPianCode.Text;
                product.SampleCodes   = txtSampleList.Text;
                product.Texure        = Utility.GetSelectedText(ddlTexure);
                product.Long          = !string.IsNullOrEmpty(txtLong.Text) ? int.Parse(txtLong.Text) : new Nullable <int>();
                product.Width         = !string.IsNullOrEmpty(txtWidth.Text) ? int.Parse(txtWidth.Text) : new Nullable <int>();
                product.Deep          = !string.IsNullOrEmpty(txtDeepth.Text) ? int.Parse(txtDeepth.Text) : new Nullable <int>();
                product.Color         = Utility.GetSelectedText(ddlColor);
                product.Location      = Utility.GetSelectedText(ddlLocation);
                product.QuantityM2    = !string.IsNullOrEmpty(lblSquare.Text) ? float.Parse(lblSquare.Text) : new Nullable <float>();
                product.SupplierName  = Utility.GetSelectedText(ddlSupplier);
                product.PurchasePrice = !string.IsNullOrEmpty(txtPriceInM2.Text) ? double.Parse(txtPriceInM2.Text) : new Nullable <double>();
                product.PriceM        = !string.IsNullOrEmpty(txtPriceM.Text) ? float.Parse(txtPriceM.Text) : new Nullable <float>();
                product.PriceM2       = !string.IsNullOrEmpty(txtPriceM2.Text) ? float.Parse(txtPriceM2.Text) : new Nullable <float>();
                product.PriceOther    = !string.IsNullOrEmpty(txtPriceOther.Text) ? float.Parse(txtPriceOther.Text) : new Nullable <float>();
                product.Alias1        = txtAlias1.Text;
                product.Alias2        = txtAlias2.Text;
                product.Intro         = txtIntro.Text;
                if (!string.IsNullOrEmpty(filePic.FileName))
                {
                    string serverFilePath = string.Empty;
                    Utility.UploadFile(filePic, "ProductImage", SourceNo, ref serverFilePath);
                    product.ImgPath = serverFilePath;
                }
                dal.Save();
            }
            else if (string.Equals(ViewType, "create", StringComparison.OrdinalIgnoreCase))
            {
                ProductDAL dal = new ProductDAL();
                product = new Product();
                product.Product_Code  = txtProductCode.Text;
                product.Product_Name  = txtProductName.Text;
                product.HuangliaoCode = txtHuangliaoCode.Text;
                product.JiaCode       = txtJiaCode.Text;
                product.PianCode      = txtPianCode.Text;
                product.SampleCodes   = txtSampleList.Text;
                product.Texure        = Utility.GetSelectedText(ddlTexure);
                product.Long          = !string.IsNullOrEmpty(txtLong.Text) ? int.Parse(txtLong.Text) : new Nullable <int>();
                product.Width         = !string.IsNullOrEmpty(txtWidth.Text) ? int.Parse(txtWidth.Text) : new Nullable <int>();
                product.Deep          = !string.IsNullOrEmpty(txtDeepth.Text) ? int.Parse(txtDeepth.Text) : new Nullable <int>();
                product.Color         = Utility.GetSelectedText(ddlColor);
                product.Location      = Utility.GetSelectedText(ddlLocation);
                product.QuantityM2    = !string.IsNullOrEmpty(lblSquare.Text) ? float.Parse(lblSquare.Text) : new Nullable <float>();
                product.SupplierName  = Utility.GetSelectedText(ddlSupplier);
                product.PurchasePrice = !string.IsNullOrEmpty(txtPriceInM2.Text) ? double.Parse(txtPriceInM2.Text) : new Nullable <double>();
                product.PriceM        = !string.IsNullOrEmpty(txtPriceM.Text) ? float.Parse(txtPriceM.Text) : new Nullable <float>();
                product.PriceM2       = !string.IsNullOrEmpty(txtPriceM2.Text) ? float.Parse(txtPriceM2.Text) : new Nullable <float>();
                product.PriceOther    = !string.IsNullOrEmpty(txtPriceOther.Text) ? float.Parse(txtPriceOther.Text) : new Nullable <float>();
                product.Alias1        = txtAlias1.Text;
                product.Alias2        = txtAlias2.Text;
                product.Intro         = txtIntro.Text;
                if (!string.IsNullOrEmpty(filePic.FileName))
                {
                    string serverFilePath = string.Empty;
                    Utility.UploadFile(filePic, "ProductImage", SourceNo, ref serverFilePath);
                    product.ImgPath = serverFilePath;
                }
                dal.AddProduct(product);
                dal.Save();
            }
            if (string.IsNullOrEmpty(CloseAfter))
            {
                Response.Redirect(string.Format("productform.aspx?type=p&id={0}&viewtype=edit", product.Product_Id));
            }
            else
            {
                Page.RegisterStartupScript("closepopup", "<script language='javascript'>document.getElementById('btnClose').click();</script>");
            }
        }
Пример #10
0
 /// <summary>
 /// insert
 /// </summary>
 /// <param name="Obejto"></param>
 public void AddProduct(Product Obejto)
 {
     ProdDAL.AddProduct(Obejto);
 }
Пример #11
0
 public static bool AddProduct(product Product)
 {
     return(ProductDAL.AddProduct(Product));
 }
Пример #12
0
 public bool AddProduct(ProductDTO product)
 {
     return(data.AddProduct(product));
 }
Пример #13
0
 public void AddProduct(Product newProduct)
 {
     productDAL.AddProduct(newProduct);
 }