Ejemplo n.º 1
0
        public ActionResult Edit(ProjectGallery projectGallery, HttpPostedFileBase Image)
        {
            if (ModelState.IsValid)
            {
                #region Upload Image
                if (Image != null)
                {
                    if (System.IO.File.Exists(Server.MapPath("/Files/ProjectImages/ProjectGallery/" + projectGallery.Image)))
                    {
                        System.IO.File.Delete(Server.MapPath("/Files/ProjectImages/ProjectGallery/" + projectGallery.Image));
                    }
                    // Saving Temp Image
                    var newFileName = Guid.NewGuid() + Path.GetExtension(Image.FileName);
                    Image.SaveAs(Server.MapPath("/Files/ProjectImages/Temp/" + newFileName));
                    // Resize Image
                    ImageResizer image = new ImageResizer(900, 500, true);
                    image.Resize(Server.MapPath("/Files/ProjectImages/Temp/" + newFileName),
                                 Server.MapPath("//Files/ProjectImages/ProjectGallery/" + newFileName));

                    // Deleting Temp Image
                    System.IO.File.Delete(Server.MapPath("/Files/ProjectImages/Temp/" + newFileName));

                    projectGallery.Image = newFileName;
                }
                #endregion
                _repo.Update(projectGallery);
                return(RedirectToAction("Index", new { projectId = projectGallery.ProjectId }));
            }
            return(View(projectGallery));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProjectGallery projectGallery = _repo.Get(id.Value);

            if (projectGallery == null)
            {
                return(HttpNotFound());
            }
            return(PartialView(projectGallery));
        }