public ActionResult Edit(int id, GalleryViewModel objEntity) { var objStudentRepository = new GalleryRepository(); string fileName = string.Empty; objEntity.Id = id; objEntity.DeleteFileName = objEntity.FileName; if (!string.IsNullOrEmpty(objEntity.UpFile.FileName)) { fileName = Guid.NewGuid().ToString() + Path.GetExtension(objEntity.UpFile.FileName); objEntity.FileName = fileName; } objEntity = objStudentRepository.Edit(GalleryFlags.UpdateByID.GetHashCode(), objEntity); if (objEntity.Result == ResultFlags.Success.GetHashCode()) { if ((objEntity.DeleteFileName != null || objEntity.DeleteFileName != string.Empty) && !string.IsNullOrEmpty(objEntity.UpFile.FileName)) { FileInfo file = new FileInfo(Server.MapPath(ApplicationConstant.UPLOADED_EMPLOYER_GALLERY_PATH + objEntity.DeleteFileName)); if (file.Exists) { file.Delete(); } string path = Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_EMPLOYER_GALLERY_PATH), fileName); // WebImage.Save() objEntity.UpFile.SaveAs(path); } this.Flash("success", "Student Details updated successfully"); return(RedirectToAction("Index")); } else if (objEntity.Result == ResultFlags.Failure.GetHashCode()) { this.Flash("error", "Student Details failed to Update"); } else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode()) { this.Flash("warning", "Student Name is Already Exist"); } return(View(objEntity)); }