public ActionResult Edit(NewsEvent newsEvent, List <HttpPostedFileBase> Images)
        {
            if (ModelState.IsValid)
            {
                newsEvent.UpdatedAt       = DateTime.Now;
                newsEvent.UpdatedBy       = User.Identity.Name;
                db.Entry(newsEvent).State = EntityState.Modified;
                db.SaveChanges();
                if (!Directory.Exists(Path.Combine(Server.MapPath("~/Admin/Images/News/" + newsEvent.Id))))
                {
                    Directory.CreateDirectory(Server.MapPath("~/Admin/Images/News/" + newsEvent.Id));
                }

                if (Images.Count > 0)
                {
                    foreach (HttpPostedFileBase fi in Images)
                    {
                        //Checking file is available to save.
                        if (fi != null)
                        {
                            var InputFileName = Path.GetFileName(fi.FileName);
                            int size          = fi.ContentLength / 1000000;

                            string regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
                            Regex  r           = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
                            InputFileName = r.Replace(InputFileName, "");

                            string extension = Path.GetExtension(fi.FileName);
                            if (ImageExt.Contains(extension.ToUpper()))
                            {
                                string path           = Server.MapPath("~/Admin/Images/News/") + newsEvent.Id + "/" + InputFileName;
                                var    ServerSavePath = Path.Combine(path);
                                //Save file to server folder
                                fi.SaveAs(ServerSavePath);
                                if (System.IO.File.Exists(path))
                                {
                                    ImageFile file = new ImageFile
                                    {
                                        Name         = InputFileName,
                                        Size         = size,
                                        path         = "~/Admin/Images/News/" + newsEvent.Id + "/" + InputFileName,
                                        Type         = "Image",
                                        UploadedBy   = "Admin",
                                        UploadedDate = DateTime.Now
                                    };
                                    db.ImageFile.Add(file);
                                    db.SaveChanges();

                                    ImageFile image = db.ImageFile.OrderByDescending(m => m.Id).FirstOrDefault();
                                    newsEvent.Files.Add(image);
                                    db.SaveChanges();
                                }
                            }
                        }
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(newsEvent));
        }
 public ActionResult Edit(Queries queries)
 {
     if (ModelState.IsValid)
     {
         db.Entry(queries).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(queries));
 }
Example #3
0
 public ActionResult Edit(Posture posture)
 {
     if (ModelState.IsValid)
     {
         posture.UpdatedAt       = DateTime.Now;
         posture.UpdatedBy       = User.Identity.Name;
         db.Entry(posture).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(posture));
 }
Example #4
0
 public ActionResult Edit(Category category)
 {
     if (ModelState.IsValid)
     {
         category.UpdatedAt       = DateTime.Now;
         category.UpdatedBy       = User.Identity.Name;
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.LocationId = new SelectList(db.Locations, "Id", "Name", category.LocationId != null ? category.Id : 0);
     return(View(category));
 }
        public ActionResult Edit(AboutUs aboutUs, HttpPostedFileBase Image)
        {
            if (ModelState.IsValid)
            {
                if (Image != null)
                {
                    if (!Directory.Exists(Server.MapPath("~/Admin/Images/AboutUs")))
                    {
                        Directory.CreateDirectory(Server.MapPath("~/Admin/Images/AboutUs"));
                    }
                    if (aboutUs.File != null)
                    {
                        db.ImageFile.Remove(aboutUs.File);
                        db.SaveChanges();

                        System.IO.File.Delete(Server.MapPath(aboutUs.File.path));
                    }

                    ImageFile file = new ImageFile
                    {
                        Name         = Image.FileName,
                        Size         = Image.ContentLength / 10000,
                        path         = "~/Admin/Images/AboutUs/" + Image.FileName,
                        Type         = "Image",
                        UploadedBy   = "Admin",
                        UploadedDate = DateTime.Now
                    };
                    db.ImageFile.Add(file);
                    db.SaveChanges();

                    ImageFile image = db.ImageFile.OrderByDescending(m => m.Id).FirstOrDefault();
                    aboutUs.File = image;
                }


                db.Entry(aboutUs).State = EntityState.Modified;
                db.SaveChanges();


                return(RedirectToAction("Index"));
            }
            return(View(aboutUs));
        }
Example #6
0
      public ActionResult Edit(Location location, HttpPostedFileBase file)
      {
          if (ModelState.IsValid)
          {
              location.UpdatedAt       = DateTime.Now;
              location.UpdatedBy       = User.Identity.Name;
              db.Entry(location).State = EntityState.Modified;
              db.SaveChanges();


              if (!Directory.Exists(Server.MapPath("~/Admin/Images/Location/")))
              {
                  Directory.CreateDirectory(Server.MapPath("~/Admin/Images/Location/"));
              }
              file.SaveAs(Server.MapPath("~/Admin/Images/Location/" + location.Id.ToString() + ".jpg"));

              return(RedirectToAction("Index"));
          }
          return(View(location));
      }
Example #7
0
 public void Update(T Model)
 {
     db.Entry(Model).State = EntityState.Modified;
     Save();
 }