示例#1
0
 public ActionResult Edit([Bind(Include = "Id,Searchname")] Search search)
 {
     if (ModelState.IsValid)
     {
         db.Entry(search).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(search));
 }
 public ActionResult Edit([Bind(Include = "Id,UserName,Company,Contact,Password,ConfirmPassword")] Register register)
 {
     if (ModelState.IsValid)
     {
         db.Entry(register).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(register));
 }
示例#3
0
 public ActionResult Edit(int id, Product p)//Edit Product(Post Method)
 {
     try
     {
         string oldpath1 = Session["imgpath1"].ToString();
         string oldpath2 = Session["imgpath2"].ToString();
         //If conditions for optional image as well as compulsory image.
         if (p.SmallImage != null && p.LargeImage != null)
         {
             String filename  = Path.GetFileNameWithoutExtension(p.ImageFile.FileName);
             String extension = Path.GetExtension(p.ImageFile.FileName);
             filename     = filename + DateTime.Now.ToString("yymmssfff") + extension;
             p.SmallImage = "~/Images/Small/" + filename;
             filename     = Path.Combine(Server.MapPath("~/Images/Small/"), filename);
             p.ImageFile.SaveAs(filename);
             if (p.SmallImage != oldpath1)
             {
                 string p1 = Request.MapPath(oldpath1);
                 if (System.IO.File.Exists(p1))
                 {
                     System.IO.File.Delete(p1);
                 }
             }
             String filename1  = Path.GetFileNameWithoutExtension(p.ImageFile1.FileName);
             String extension1 = Path.GetExtension(p.ImageFile1.FileName);
             filename1    = filename1 + DateTime.Now.ToString("yymmssfff") + extension1;
             p.LargeImage = "~/Images/Large/" + filename1;
             filename1    = Path.Combine(Server.MapPath("~/Images/Large/"), filename1);
             p.ImageFile1.SaveAs(filename1);
             if (p.LargeImage != oldpath2)
             {
                 string p2 = Request.MapPath(oldpath2);
                 if (System.IO.File.Exists(p2))
                 {
                     System.IO.File.Delete(p2);
                 }
             }
         }
         if (p.ImageFile != null)
         {
             String filename  = Path.GetFileNameWithoutExtension(p.ImageFile.FileName);
             String extension = Path.GetExtension(p.ImageFile.FileName);
             filename     = filename + DateTime.Now.ToString("yymmssfff") + extension;
             p.SmallImage = "~/Images/Small/" + filename;
             filename     = Path.Combine(Server.MapPath("~/Images/Small/"), filename);
             p.ImageFile.SaveAs(filename);
             if (p.LargeImage == null)
             {
                 p.LargeImage = oldpath2;
             }
             if (p.SmallImage != oldpath1)
             {
                 string p1 = Request.MapPath(oldpath1);
                 if (System.IO.File.Exists(p1))
                 {
                     System.IO.File.Delete(p1);
                 }
             }
         }
         if (p.ImageFile1 != null)
         {
             String filename1  = Path.GetFileNameWithoutExtension(p.ImageFile1.FileName);
             String extension1 = Path.GetExtension(p.ImageFile1.FileName);
             filename1    = filename1 + DateTime.Now.ToString("yymmssfff") + extension1;
             p.LargeImage = "~/Images/Large/" + filename1;
             filename1    = Path.Combine(Server.MapPath("~/Images/Large/"), filename1);
             p.ImageFile1.SaveAs(filename1);
             if (p.SmallImage == null)
             {
                 p.SmallImage = oldpath1;
             }
             if (p.LargeImage != oldpath2)
             {
                 string p2 = Request.MapPath(oldpath2);
                 if (System.IO.File.Exists(p2))
                 {
                     System.IO.File.Delete(p2);
                 }
             }
         }
         if (p.SmallImage == null && p.LargeImage == null)
         {
             p.SmallImage = oldpath1;
             p.LargeImage = oldpath2;
         }
         if (p.LongDescription == null)
         {
             p.LongDescription = "NA";
         }
         UserEntities1 db = new UserEntities1();
         db.Entry(p).State = EntityState.Modified;//Modify The Data
         db.SaveChanges();
         //Toster Message For Edit Product.
         HttpCookie cookie2 = new HttpCookie("CookieEdit");
         cookie2.Value = "Edit";
         Response.Cookies.Add(cookie2);
         cookie2.Expires = DateTime.Now.AddSeconds(5);
         return(RedirectToAction("Display"));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
     return(View());
 }