示例#1
0
        public async Task <IActionResult> Create(RequestProductBanner productBanner)
        {
            if (productBanner.file != null)
            {
                var savePath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\Upload", productBanner.file.FileName);
                using (var stream = new FileStream(savePath, FileMode.Create))
                {
                    await productBanner.file.CopyToAsync(stream);
                }
                productBanner.ImgUrl = "/Upload/" + productBanner.file.FileName;
            }

            try
            {
                var targer = new ProductBanners()
                {
                    ImgUrl      = productBanner.ImgUrl,
                    PublishDate = productBanner.PublishDate,
                    Url         = productBanner.Url,
                    DownDate    = productBanner.DownDate,
                    Title       = productBanner.Title
                };
                _context.ProductBanners.Add(targer);
                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(Status400BadRequest, new ResponseMessage {
                    Message = "查無資訊"
                }));
            }
        }
        protected void btnProceedToSubmit_Click(object sender, EventArgs e)
        {
            int            AdminId = Convert.ToInt32(Session[ConfigurationSettings.AppSettings["AdminSession"].ToString()].ToString());
            Administrators _admin  = bAdministrator.List().Where(m => m.Administrators_Id == AdminId).FirstOrDefault();

            Product Product = new Product()
            {
                Store_Id               = _admin.Store_Id,
                Product_Title          = txtTitle.Text,
                Product_Description    = txtDescription.Content,
                Product_Specification  = txtSpecification.Content,
                Administrators_Id      = _admin.Administrators_Id,
                Product_Qty            = Convert.ToInt32(txtQuantity.Text),
                Product_Qty_Alert      = Convert.ToInt32(txtAlert.Text),
                Product_Delivery_Time  = Convert.ToInt32(txtProductDelieveredIn.Text),
                Product_Max_Purchase   = Convert.ToInt32(txtMaxPurchase.Text),
                Product_Mkt_Price      = Convert.ToDecimal(txtMarketPrice.Text),
                Product_Our_Price      = Convert.ToDecimal(txtOurPrice.Text),
                Product_ShippingCharge = Convert.ToDecimal(txtShippingCharge.Text),
                Product_Has_Size       = (rdbHasSize.SelectedValue == "Yes") ? true : false,
                Product_Size           = (rdbHasSize.SelectedValue == "Yes") ? txtSize.Text : "No Size",
                Product_Avail_ZipCode  = (txtZipcode.Text != "") ? txtZipcode.Text : "0",
                Product_Discount       = Convert.ToDecimal(txtDiscount.Text),
                SubCategory_Id         = Convert.ToInt32(ddlCategory.SelectedValue),
                Product_CreatedDate    = DateTime.Now,
                Product_UpdatedDate    = DateTime.Now,
                Product_Status         = eProductStatus.ReviewPending.ToString(),
                Store_Rating           = (txtRating.Text != "") ? Convert.ToInt32(txtRating.Text) : 1
            };

            bProduct.Create(Product);

            if (string.IsNullOrEmpty(Product.ErrorMessage))
            {
                ProductHelper.CreateProductFlow(Product.Product_Id, Product.Product_Title, _admin.Administrators_Id, _admin.FullName, "New Product Created and Pending for Review", Product.Product_Status);

                ProductBanners ProductBanner = new ProductBanners()
                {
                    Product_Id                 = Product.Product_Id,
                    Administrators_Id          = Convert.ToInt32(Session[ConfigurationSettings.AppSettings["AdminSession"].ToString()].ToString()),
                    Product_Banner_Default     = 1,
                    Product_Banner_Photo       = "content/noimage.png",
                    Product_Banner_CreatedDate = DateTime.Now,
                    Product_Banner_UpdatedDate = DateTime.Now
                };

                bProduct.CreateProductBanner(ProductBanner);

                Response.Redirect("/administration/product/productsdetailstatic.aspx?SavePrdId=1000&Productid=" + Product.Product_Id);
            }
            else
            {
                pnlErrorMessage.Attributes.Remove("class");
                pnlErrorMessage.Attributes["class"] = "alert alert-danger alert-dismissable";
                pnlErrorMessage.Visible             = true;
                lblMessage.Text = "Product cannot be created. " + Product.ErrorMessage;
            }
        }
示例#3
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string result = Upload(hdnProdId.Value);

            if (result == "100")
            {
                int            prdId         = Convert.ToInt32(hdnProdId.Value);
                ProductBanners currentBanner = context.ProductBanner.Where(m => m.Product_Id == prdId).FirstOrDefault();
                ProductBanners Product       = new ProductBanners()
                {
                    Product_Id                 = Convert.ToInt32(hdnProdId.Value),
                    Product_Banner_Photo       = "files/product/" + hdnProdId.Value + "/" + hdnProdId.Value + "_" + imgInp.FileName,
                    Administrators_Id          = Convert.ToInt32(Session[ConfigurationSettings.AppSettings["AdminSession"].ToString()].ToString()),
                    Product_Banner_Default     = Convert.ToInt32(ddlStatus.SelectedValue),
                    Product_Banner_CreatedDate = DateTime.Now,
                    Product_Banner_UpdatedDate = DateTime.Now
                };

                if (Product.Product_Banner_Default == 1)
                {
                    List <ProductBanners> Productbnrs = context.ProductBanner.Where(m => m.Product_Id == prdId).ToList();
                    foreach (var item in Productbnrs)
                    {
                        item.Product_Banner_Default = 0;
                        context.Entry(item).State   = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                    }
                }
                else
                {
                    if (currentBanner == null)
                    {
                        Product.Product_Banner_Default = 1;
                    }
                }

                int maxBnrAdminId = 1;
                if (context.ProductBanner.ToList().Count > 0)
                {
                    maxBnrAdminId = context.ProductBanner.Max(m => m.Product_Id);
                }
                maxBnrAdminId = (maxBnrAdminId == 1 && context.ProductBanner.ToList().Count > 0) ? (maxBnrAdminId + 1) : maxBnrAdminId;
                Product.Product_BannerCode = "PRDBNRTRACH" + maxBnrAdminId + "TERA" + (maxBnrAdminId + 1);
                context.ProductBanner.Add(Product);
                context.SaveChanges();

                LoadGrid();
                pnlErrorMessage.Attributes.Remove("class");
                pnlErrorMessage.Attributes["class"] = "alert alert-success alert-dismissable";
                pnlErrorMessage.Visible             = true;
                lblMessage.Text         = "Success!!! Banner Created Successfully.";
                ddlStatus.SelectedIndex = 0;
            }
        }
        public static ProductBanners CreateProductBanner(ProductBanners ProductBanner)
        {
            dProduct _dProduct = new dProduct();

            if (Convert.ToBoolean(ConfigurationSettings.AppSettings["IsEmailEnable"]))
            {
                string mailBody = MailHelper.ActivityMail("Product", "New Product Banner " +
                                                          "( " + ProductBanner.Product_Banner_Id + "  and " + ProductBanner.Product_BannerCode + " ) created successfully.",
                                                          ProductBanner.Administrators_Id, DateTime.Now.ToString());

                MailHelper.SendEmail(MailHelper.EmailToSend(), "New Product Banner Created", mailBody, "Rachna Teracotta : Activity Admin");
            }
            return(_dProduct.CreateProductBanner(ProductBanner));
        }
示例#5
0
        protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                using (var ctx = new RachnaDBContext())
                {
                    ProductBanners _banner  = ctx.ProductBanner.ToList().Where(m => m.Product_Banner_Id == Convert.ToInt32(e.Values[0].ToString())).FirstOrDefault();
                    string         filePath = Server.MapPath("~/" + _banner.Product_Banner_Photo);
                    if (!filePath.Contains("noimage.png"))
                    {
                        FileInfo file = new FileInfo(filePath);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                    }
                    ctx.Entry(_banner).State = EntityState.Deleted;
                    ctx.SaveChanges();

                    ProductBanners currentBanner = ctx.ProductBanner.ToList().Where(m => m.Product_Id == Convert.ToInt32(hdnProductId.Value)).FirstOrDefault();
                    if (currentBanner != null)
                    {
                        currentBanner.Product_Banner_Default = 1;
                        ctx.Entry(currentBanner).State       = System.Data.Entity.EntityState.Modified;
                        ctx.SaveChanges();
                    }
                    pnlErrorMessage.Attributes.Remove("class");
                    pnlErrorMessage.Attributes["class"] = "alert alert-success alert-dismissable";
                    pnlErrorMessage.Visible             = true;
                    lblMessage.Text = "Product Slider Deleted Successfully.";
                    LoadGrid();
                }
            }
            catch (Exception ex)
            {
                pnlErrorMessage.Attributes.Remove("class");
                pnlErrorMessage.Attributes["class"] = "alert alert-danger alert-dismissable";
                pnlErrorMessage.Visible             = true;
                lblMessage.Text = "Oops!! Server error occured, please contact administrator.";
            }
        }
 internal ProductBanners CreateProductBanner(ProductBanners ProductBanner)
 {
     try
     {
         int maxProductId = 1;
         if (context.ProductBanner.ToList().Count > 0)
         {
             maxProductId = context.ProductBanner.Max(m => m.Product_Banner_Id);
         }
         maxProductId = (context.ProductBanner.ToList().Count > 0) ? (maxProductId + 1) : maxProductId;
         ProductBanner.Product_BannerCode = "RT" + maxProductId + "PRDBNRCODE" + (maxProductId + 1);
         context.ProductBanner.Add(ProductBanner);
         context.SaveChanges();
         return(ProductBanner);
     }
     catch (Exception ex)
     {
         ProductBanner.ErrorMessage = ex.Message;
         return(ProductBanner);
     }
 }
示例#7
0
        public string SetDefaultImage(string id)
        {
            using (var ctx = new RachnaDBContext())
            {
                List <ProductBanners> Productbnrs = ctx.ProductBanner.ToList().Where(f => f.Product_Id == Convert.ToInt32(hdnProductId.Value)).ToList();
                foreach (var item in Productbnrs)
                {
                    item.Product_Banner_Default = 0;
                    ctx.Entry(item).State       = System.Data.Entity.EntityState.Modified;
                    ctx.SaveChanges();
                }

                ProductBanners _banner = ctx.ProductBanner.ToList().Where(m => m.Product_Banner_Id == Convert.ToInt32(id)).FirstOrDefault();
                _banner.Product_Banner_Default = 1;
                ctx.Entry(_banner).State       = System.Data.Entity.EntityState.Modified;
                ctx.SaveChanges();
                pnlErrorMessage.Attributes.Remove("class");
                pnlErrorMessage.Attributes["class"] = "alert alert-success alert-dismissable";
                pnlErrorMessage.Visible             = true;
                lblMessage.Text = "Banner Updated Successfully.";
            }
            LoadGrid();
            return("");
        }
示例#8
0
        private void InsertExcelRecords(string FilePath)
        {
            List <Product> _products   = new List <Product>();
            var            csvData     = System.IO.File.ReadAllLines(FilePath).Skip(1);
            int            insertCount = 0;
            int            updateCount = 0;

            try
            {
                //Execute a loop over the rows.
                foreach (string row in csvData)
                {
                    if (!string.IsNullOrEmpty(row))
                    {
                        if (row != ",,,,,,,,,,,,,,,,")
                        {
                            _products.Add(new Product
                            {
                                Product_Id             = Convert.ToInt32(row.Split(',')[0]),
                                SubCategory_Id         = Convert.ToInt32(row.Split(',')[1]),
                                Product_Title          = row.Split(',')[2],
                                Product_Description    = row.Split(',')[3],
                                Product_Specification  = row.Split(',')[4],
                                Product_Qty            = Convert.ToInt32(row.Split(',')[5]),
                                Product_Qty_Alert      = Convert.ToInt32(row.Split(',')[6]),
                                Product_Delivery_Time  = Convert.ToInt32(row.Split(',')[7]),
                                Product_Max_Purchase   = Convert.ToInt32(row.Split(',')[8]),
                                Product_Mkt_Price      = Convert.ToDecimal(row.Split(',')[9]),
                                Product_Our_Price      = Convert.ToDecimal(row.Split(',')[10]),
                                Product_ShippingCharge = Convert.ToDecimal(row.Split(',')[11]),
                                Product_Has_Size       = Convert.ToBoolean(row.Split(',')[12].ToLower()),
                                Product_Size           = row.Split(',')[13],
                                Product_Avail_ZipCode  = row.Split(',')[14],
                                Product_Discount       = Convert.ToDecimal(row.Split(',')[15]),
                                Product_CreatedDate    = DateTime.Now,
                                Product_UpdatedDate    = DateTime.Now,
                                Product_Status         = eProductStatus.ReviewPending.ToString()
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            int            AdminId = Convert.ToInt32(Session[ConfigurationSettings.AppSettings["AdminSession"].ToString()].ToString());
            Administrators _admin  = context.Administrator.ToList().Where(m => m.Administrators_Id == AdminId).FirstOrDefault();

            foreach (var item in _products)
            {
                SubCategories _subCategory = context.SubCategory.Where(m => m.SubCategory_Id == item.SubCategory_Id).FirstOrDefault();
                item.Administrators_Id = _admin.Administrators_Id;
                item.Store_Id          = _admin.Store_Id;
                if (_subCategory != null)
                {
                    if (item.Product_Id == 0)
                    {
                        Product Product = new Product()
                        {
                            Store_Id               = _admin.Store_Id,
                            Product_Title          = item.Product_Title,
                            Product_Description    = item.Product_Description,
                            Product_Specification  = item.Product_Specification,
                            Administrators_Id      = _admin.Administrators_Id,
                            Product_Qty            = item.Product_Qty,
                            Product_Qty_Alert      = item.Product_Qty_Alert,
                            Product_Delivery_Time  = item.Product_Delivery_Time,
                            Product_Max_Purchase   = item.Product_Max_Purchase,
                            Product_Mkt_Price      = item.Product_Mkt_Price,
                            Product_Our_Price      = item.Product_Our_Price,
                            Product_ShippingCharge = item.Product_ShippingCharge,
                            Product_Has_Size       = item.Product_Has_Size,
                            Product_Size           = (item.Product_Has_Size == true) ? item.Product_Size : "No Size",
                            Product_Avail_ZipCode  = item.Product_Avail_ZipCode,
                            Product_Discount       = item.Product_Discount,
                            SubCategory_Id         = item.SubCategory_Id,
                            Product_CreatedDate    = item.Product_CreatedDate,
                            Product_UpdatedDate    = item.Product_UpdatedDate,
                            Product_Status         = item.Product_Status
                        };
                        try
                        {
                            int maxAdminId = 1;
                            if (context.Product.ToList().Count > 0)
                            {
                                maxAdminId = context.Product.Max(m => m.Product_Id);
                            }
                            maxAdminId          = (maxAdminId == 1 && context.Product.ToList().Count > 0) ? (maxAdminId + 1) : maxAdminId;
                            Product.ProductCode = "PRDTRACH" + maxAdminId + "TERA" + (maxAdminId + 1);
                            context.Product.Add(Product);
                            context.SaveChanges();

                            ProductHelper.CreateProductFlow(Product.Product_Id, Product.Product_Title, _admin.Administrators_Id, _admin.FullName, "New Product Created", Product.Product_Status);

                            item.Product_Id = Product.Product_Id;
                            insertCount     = insertCount + 1;
                            ProductBanners ProductBanner = new ProductBanners()
                            {
                                Product_Id                 = Product.Product_Id,
                                Administrators_Id          = Convert.ToInt32(Session[ConfigurationSettings.AppSettings["AdminSession"].ToString()].ToString()),
                                Product_Banner_Default     = 1,
                                Product_Banner_Photo       = "content/noimage.png",
                                Product_Banner_CreatedDate = DateTime.Now,
                                Product_Banner_UpdatedDate = DateTime.Now
                            };

                            int maxBnrAdminId = 1;
                            if (context.ProductBanner.ToList().Count > 0)
                            {
                                maxBnrAdminId = context.ProductBanner.Max(m => m.Product_Id);
                            }
                            maxBnrAdminId = (maxBnrAdminId == 1 && context.ProductBanner.ToList().Count > 0) ? (maxBnrAdminId + 1) : maxBnrAdminId;
                            ProductBanner.Product_BannerCode = "PRDBNRTRACH" + maxBnrAdminId + "TERA" + (maxBnrAdminId + 1);
                            context.ProductBanner.Add(ProductBanner);
                            context.SaveChanges();
                        }
                        catch
                        {
                        }
                    }
                    else
                    {
                        Product _product = context.Product.ToList().Where(m => m.Product_Id == item.Product_Id).FirstOrDefault();
                        if (_product != null)
                        {
                            _product.Store_Id               = _admin.Store_Id;
                            _product.Product_Title          = item.Product_Title;
                            _product.Product_Description    = item.Product_Description;
                            _product.Product_Specification  = item.Product_Specification;
                            _product.Administrators_Id      = _admin.Administrators_Id;
                            _product.Product_Qty            = item.Product_Qty;
                            _product.Product_Qty_Alert      = item.Product_Qty_Alert;
                            _product.Product_Delivery_Time  = item.Product_Delivery_Time;
                            _product.Product_Max_Purchase   = item.Product_Max_Purchase;
                            _product.Product_Mkt_Price      = item.Product_Mkt_Price;
                            _product.Product_Our_Price      = item.Product_Our_Price;
                            _product.Product_ShippingCharge = item.Product_ShippingCharge;
                            _product.Product_Size           = item.Product_Size;
                            _product.Product_Avail_ZipCode  = item.Product_Title;
                            _product.Product_Discount       = item.Product_Discount;
                            _product.SubCategory_Id         = item.SubCategory_Id;
                            _product.Product_UpdatedDate    = item.Product_UpdatedDate;
                            _product.Product_Status         = item.Product_Status;

                            try
                            {
                                updateCount = updateCount + 1;
                                context.Entry(_product).State = System.Data.Entity.EntityState.Modified;
                                context.SaveChanges();
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            item.Product_Status = "Invalid Product Id";
                        }
                    }
                }
                else
                {
                    item.Product_Status = "Invalid Sub Category Id";
                }
            }
            pnlErrorMessage.Attributes.Remove("class");
            pnlErrorMessage.Attributes["class"] = "alert alert-success alert-dismissable";
            pnlErrorMessage.Visible             = true;
            lblMessage.Text = "We are done!! " + insertCount + " Products Inserted and " + updateCount + " Products Updated Successfully also we have dowloaded the updated excel. Please check your download folder.";

            DataTable dt = ConvertToDataTable(_products);

            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Products.xls"));
            Response.ContentType = "application/ms-excel";
            string str = string.Empty;

            foreach (DataColumn dtcol in dt.Columns)
            {
                Response.Write(str + dtcol.ColumnName);
                str = "\t";
            }
            Response.Write("\n");
            foreach (DataRow dr in dt.Rows)
            {
                str = "";
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    Response.Write(str + Convert.ToString(dr[j]));
                    str = "\t";
                }
                Response.Write("\n");
            }
            Response.End();
        }