Exemplo n.º 1
0
 public ActionResult DeleteAll(string[] id) //id is an array for choosing multiple product to delete.
 {
     int[] getid = null;                    //initialize getid as null.
     if (id != null)
     {
         getid = new int[id.Length];     //if getid is not null
         int j = 0;                      //initialize j
         foreach (string i in id)        //perform following for every i in id.
         {
             int.TryParse(i, out getid[j++]);
         }
         using (DBProduct2 db = new DBProduct2())
         {
             List <ProductManage> pids = new List <ProductManage>(); //pids is variable of Table ProductManage.
             pids = db.ProductManages.Where(x => getid.Contains(x.ID)).ToList();
             foreach (var s in pids)                                 //it will delete all the selected products form the list.
             {
                 db.ProductManages.Remove(s);
             }
             db.SaveChanges();    //following code is for toaster message for 5 second.
             HttpCookie cookie3 = new HttpCookie("CookieDeleteAll");
             cookie3.Value = "DeleteAll";
             Response.Cookies.Add(cookie3);
             cookie3.Expires = DateTime.Now.AddSeconds(5);
             return(RedirectToAction("Index"));
         }
     }
     return(RedirectToAction("Index"));
 }
Exemplo n.º 2
0
        public ActionResult Create(HttpPostedFileBase file1, HttpPostedFileBase file2, ProductManage emp)                                                  //Argument for HttpPostBase Files.
        {
            string filename1 = Path.GetFileName(file1.FileName);                                                                                           //filename1 variable is created for Small image.

            if (file2 != null)                                                                                                                             //if Large image is not null then following code will execute.
            {
                string filename2  = Path.GetFileName(file2.FileName);                                                                                      //filename2 is variable for large image.
                string _filename2 = DateTime.Now.ToString("yymmssfff") + filename2;                                                                        //Append Date Time to filename2.
                string extension2 = Path.GetExtension(file2.FileName);                                                                                     //Extension for filename2.
                string path2      = Path.Combine(Server.MapPath("~/Images/"), _filename2);                                                                 //Create path for Large image.
                emp.Large_Image = "~/Images/" + _filename2;                                                                                                //Table Object emp will stores the Large image path in Images folder.
                if (extension2.ToLower() == ".jpg" || extension2.ToLower() == ".jpeg" || extension2.ToLower() == ".png" && file2.ContentLength <= 1000000) //validation for extension and size of image.
                {
                    file2.SaveAs(path2);                                                                                                                   //save file if validation is true.
                }
            }
            string _filename1 = DateTime.Now.ToString("yymmssfff") + filename1;                                                                        //Append Date and time for small image.
            string extension1 = Path.GetExtension(file1.FileName);                                                                                     //get extension for small image.
            string path1      = Path.Combine(Server.MapPath("~/Images/"), _filename1);                                                                 //Create path for Small image.

            emp.Small_Image = "~/Images/" + _filename1;                                                                                                //Table Object emp will stores the Small image path in Images folder.

            if (extension1.ToLower() == ".jpg" || extension1.ToLower() == ".jpeg" || extension1.ToLower() == ".png" && file1.ContentLength <= 1000000) //validation for extension and size of file.
            {
                db.ProductManages.Add(emp);
                if (db.SaveChanges() > 0)
                {
                    file1.SaveAs(path1);
                    ViewBag.msg = "Record Added";
                    ModelState.Clear();
                }
            }
            else
            {
                ViewBag.msg = "Size is too Large!";
            }
            db.Entry(emp).State = EntityState.Modified;
            db.SaveChanges();                                 //save changes in database.
            HttpCookie cookie1 = new HttpCookie("CookieAdd"); //cookie is created for Toaster message.

            cookie1.Value = "Add";                            //add value to cookie.
            Response.Cookies.Add(cookie1);                    //response is stored in cookie.
            cookie1.Expires = DateTime.Now.AddSeconds(5);     // cookie will expire in 5 seconds.
            return(RedirectToAction("Index"));
        }