Beispiel #1
0
 public ActionResult AddProduct(tbl_products tblprod, HttpPostedFileBase[] pic, string code, int quantity)
 {
     //string pass = RandomPassword(quantity);                       // getting random password
     try
     {
         if (db.tbl_products.Any(p => p.code == code))
         {
             Response.Write("<script>alert('Your code is already exists try another one')</script>");
         }
         else
         {
             tbl_pic tblpic = new tbl_pic();
             //ensure model state is valid
             if (ModelState.IsValid)
             {
                 //iterating through multiple file collection
                 string[] picarray = new string[4];
                 int      i        = 0;
                 foreach (HttpPostedFileBase file in pic)
                 {
                     //Checking file is available to save.
                     if (file != null)
                     {
                         string randomname     = Path.GetRandomFileName();
                         var    InputFileName  = randomname + Path.GetFileName(file.FileName);
                         var    ServerSavePath = Path.Combine(Server.MapPath("~/Content/productimg/") + InputFileName);
                         //Save file to server folder
                         file.SaveAs(ServerSavePath);
                         picarray[i] = InputFileName;
                         i++;
                     }
                 }
                 db.tbl_products.Add(tblprod);
                 db.SaveChanges();
                 tblpic.pic1        = picarray[0];
                 tblpic.pic2        = picarray[1];
                 tblpic.pic3        = picarray[2];
                 tblpic.pic4        = picarray[3];
                 tblpic.subcategory = tblprod.subcategory;
                 tblpic.code        = tblprod.subcategory;
                 db.tbl_pic.Add(tblpic);
                 db.SaveChanges();
                 //assigning file uploaded status to ViewBag for showing message to user.
                 ViewBag.msg = " Items uploaded successfully.";
             }
             else
             {
                 ViewBag.msg = "Please upload only 4 images";
             }
         }
     }
     catch (Exception e)
     {
         ViewBag.msg = "something went wrong please try again later";
     }
     return(View());
 }
Beispiel #2
0
        public ActionResult loadproduct(int id)
        {
            List <tbl_products> prodmarbles = db.tbl_products.Where(p => p.category == "Marble").ToList();

            ViewData["prodmarbles"] = prodmarbles;
            List <tbl_products> prodtiles = db.tbl_products.Where(p => p.category == "Tiles").ToList();

            ViewData["prodtiles"] = prodtiles;
            List <tbl_products> prodstones = db.tbl_products.Where(p => p.category == "Stones").ToList();

            ViewData["prodstones"] = prodstones;

            tbl_pic prodpic = db.tbl_pic.SingleOrDefault(p => p.picid == id);

            ViewData["prodpic"] = prodpic;
            tbl_products proddetail = db.tbl_products.SingleOrDefault(u => u.productid == id);

            ViewData["proddetail"] = proddetail;
            return(View());
        }