public ActionResult SaveCompanyProduct(SA_Product model)
        {
            if (!ModelState.IsValid)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ChemAnalystContext _context = new ChemAnalystContext();
            var companyProductInDb      = _context.SA_Product.SingleOrDefault(p => p.id == model.id);

            if (companyProductInDb == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            companyProductInDb.ProductName        = model.ProductName;
            companyProductInDb.ProductDiscription = model.ProductDiscription;
            companyProductInDb.Meta            = model.Meta;
            companyProductInDb.MetaDiscription = model.MetaDiscription;
            companyProductInDb.status          = model.status;
            companyProductInDb.CreatedTime     = model.CreatedTime;
            companyProductInDb.ProductImg      = model.ProductImg;
            companyProductInDb.Category        = model.Category;

            _context.SaveChanges();

            return(RedirectToAction("AllCompanyProducts"));
        }
        public ActionResult SaveProduct(SA_Product UserProduct)
        {
            for (int i = 0; i < Request.Files.Count; i++)
            {
                var file = Request.Files[i];

                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);

                    var path = Path.Combine(Server.MapPath("~/ProductImages"), fileName);
                    file.SaveAs(path);
                    UserProduct.ProductImg = fileName;
                }
            }
            UserProduct.CreatedTime = DateTime.Now;
            ProductDataStore Obj = new ProductDataStore();

            if (UserProduct.id == 0)
            {
                Obj.AddProduct(UserProduct);
            }
            else
            {
                Obj.EditProduct(UserProduct);
            }
            return(RedirectToAction("Product"));
        }
示例#3
0
        public bool UpdateStatus(int productId)
        {
            //  Product.CreatedDate = DateTime.Now;
            SA_Product EditProduct = _context.SA_Product.Where(Cat => Cat.id == productId).FirstOrDefault();

            if (EditProduct.status.HasValue)
            {
                if (EditProduct.status.Value == 1)
                {
                    EditProduct.status = 2;
                }
                else
                {
                    EditProduct.status = 1;
                }
            }
            else
            {
                EditProduct.status = 1;
            }
            _context.Entry(EditProduct).State = EntityState.Modified;
            int x = _context.SaveChanges();

            return(x == 0 ? false : true);
        }
示例#4
0
        public async Task <bool> UpdateProduct(SA_Product Product)
        {
            _context.Entry(Product).State = EntityState.Modified;
            //  Product.ModeifiedDate = DateTime.Now;
            int x = await _context.SaveChangesAsync();

            return(x == 0 ? false : true);
        }
示例#5
0
        public async Task <bool> AddProduct(SA_Product Product)
        {
            //  Product.CreatedDate = DateTime.Now;
            _context.SA_Product.Add(Product);
            int x = await _context.SaveChangesAsync();

            return(x == 0 ? false : true);
        }
示例#6
0
        public bool DeleteProduct(int ProductId)
        {
            //  Product.CreatedDate = DateTime.Now;
            SA_Product EditProduct = _context.SA_Product.Where(Product => Product.id == ProductId).FirstOrDefault();

            _context.Entry(EditProduct).State = EntityState.Deleted;
            int x = _context.SaveChanges();

            return(x == 0 ? false : true);
        }
        public int GetctegotyBYproduct(int ProductId)
        {
            SA_Product obj = _context.SA_Product.Where(product => product.id == ProductId).FirstOrDefault();

            if (ProductId > 0)
            {
                return((int)obj.Category);
            }
            else
            {
                return(0);
            }
        }
        public ActionResult EditProduct(int id)
        {
            ProductDataStore Obj = new ProductDataStore();
            SA_Product       obj = Obj.GetProductByid(id);

            CategoryDataStore     Objcat       = new CategoryDataStore();
            List <SelectListItem> CategoryList = Objcat.CategoryList();
            SA_ProductViewModel   objSaCatV    = new SA_ProductViewModel();

            objSaCatV.id                 = obj.id;
            objSaCatV.ProductName        = obj.ProductName;
            objSaCatV.ProductDiscription = obj.ProductDiscription;
            objSaCatV.Meta               = obj.Meta;
            objSaCatV.MetaDiscription    = obj.MetaDiscription;
            objSaCatV.CategoryList       = CategoryList;
            objSaCatV.Category           = obj.Category.ToString();

            return(View("add-Product", objSaCatV));
        }
示例#9
0
        public bool EditProduct(SA_Product Product)
        {
            //  Product.CreatedDate = DateTime.Now;
            SA_Product EditProduct = _context.SA_Product.Where(Cat => Cat.id == Product.id).FirstOrDefault();

            EditProduct.ProductName        = Product.ProductName;
            EditProduct.ProductDiscription = Product.ProductDiscription;
            EditProduct.Meta            = Product.Meta;
            EditProduct.MetaDiscription = Product.MetaDiscription;
            EditProduct.Category        = Product.Category;
            if (Product.ProductImg != null)
            {
                EditProduct.ProductImg = Product.ProductName;
            }
            _context.Entry(EditProduct).State = EntityState.Modified;
            int x = _context.SaveChanges();

            return(x == 0 ? false : true);
        }
        public ActionResult Import(CompanyProductFormViewModel viewModel)
        {
            if (viewModel.excelFile == null || viewModel.excelFile.ContentLength == 0)
            {
                //handel error
                ViewBag.ErrorMessage = "This field is required";
                return(View("Index"));
            }
            else
            {
                ChemAnalystContext _context = new ChemAnalystContext();

                string FileExtension = Path.GetExtension(viewModel.excelFile.FileName);
                string FileName      = Path.GetFileName(viewModel.excelFile.FileName);
                if (FileExtension.ToLower() == ".xls")
                {
                    viewModel.excelFile.SaveAs(Server.MapPath("~/ExcelFiles/") + FileName);
                    string FilePath = Server.MapPath("~/ExcelFiles/" + FileName);

                    OleDbConnection OleConn = null;
                    OleConn = new OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath + ";Extended Properties=Excel 8.0;");
                    OleConn.Open();
                    DataTable        DT = OleConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                    string           GetExcelSheetName = DT.Rows[0]["Table_Name"].ToString();
                    OleDbDataAdapter DA = new OleDbDataAdapter("SELECT * FROM [" + GetExcelSheetName + "]", OleConn);
                    DataSet          DS = new DataSet();
                    DA.Fill(DS);

                    //foreach (DataRow DR in DS.Tables[0].Rows)
                    //{
                    //    CompanyProduct companyProduct = new CompanyProduct();
                    //    companyProduct.ProductName = DR[0].ToString();
                    //    companyProduct.Segment = DR[1].ToString();
                    //    companyProduct.IsSelected = false;
                    //    _context.CompanyProducts.Add(companyProduct);
                    //}
                    //_context.SaveChanges();

                    foreach (DataRow DR in DS.Tables[0].Rows)
                    {
                        SA_Product companyProduct = new SA_Product();

                        companyProduct.ProductName        = DR[0].ToString();
                        companyProduct.ProductDiscription = DR[1].ToString();
                        companyProduct.Meta            = DR[2].ToString();
                        companyProduct.MetaDiscription = DR[3].ToString();
                        companyProduct.status          = Convert.ToInt32(DR[4].ToString());
                        companyProduct.CreatedTime     = Convert.ToDateTime(DR[5]);
                        companyProduct.ProductImg      = DR[6].ToString();
                        companyProduct.Category        = Convert.ToInt32(DR[7].ToString());
                        companyProduct.IsSelected      = false;
                        _context.SA_Product.Add(companyProduct);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    ViewBag.ErrorMessage = "Only .xls file allowed";
                    return(View("Index"));
                }
            }
            return(RedirectToAction("AllCompanyProducts"));
        }