public ActionResult Edit(ProfileVM profileVM) { try { using (DMSDBContext dc = new DMSDBContext()) { string message = ""; var validate = dc.Departments.Where(a => a.DeptName == profileVM.DeptName).FirstOrDefault(); if (validate == null) { var data = dc.Departments.Where(x => x.DeptId == profileVM.DeptId).FirstOrDefault(); data.DeptName = profileVM.DeptName; data.DeptId = profileVM.DeptId; dc.Entry(data).State = EntityState.Modified; dc.SaveChanges(); message = "Department Edited Successfully"; TempData["Message"] = message; return(RedirectToAction("Index", "Department")); } else { message = "This Department is already created. Please use another!!"; TempData["Message"] = message; return(RedirectToAction("Create", "Department")); } } } catch { return(View()); } }
public ActionResult Delete(int id, ProfileVM profileVM) { try { using (DMSDBContext dc = new DMSDBContext()) { int uid = Convert.ToInt32(Session["id"]); var data = dc.Documents.Where(x => x.DocumentId == id).FirstOrDefault(); string strPhysicalFolder = Server.MapPath("//Documents/" + data.Category.CategoryName + "/"); string strFileFullPath = strPhysicalFolder + data.DocumentName; if (System.IO.File.Exists(strFileFullPath)) { System.IO.File.Delete(strFileFullPath); dc.Documents.Remove(data); dc.SaveChanges(); } string message = "Document Deleted Successfully"; TempData["Message"] = message; return(RedirectToAction("Index", "Document")); } } catch { return(View()); } }
public ActionResult Index(string str) { using (DMSDBContext dc = new DMSDBContext()) { List <ProfileVM> profileVM = new List <ProfileVM>(); profileVM = dc.Users.Select(x => new ProfileVM { FirstName = x.FirstName, LastName = x.LastName, Email = x.Email, DeptName = x.Department.DeptName, UserId = x.UserId }).ToList(); if (!string.IsNullOrEmpty(str)) { var searcheditems = from x in profileVM.Where(x => x.FirstName.Contains(str) || x.LastName.Contains(str) || x.Email.Contains(str) || x.DeptName.Contains(str)) select new ProfileVM { FirstName = x.FirstName, LastName = x.LastName, Email = x.Email, DeptName = x.DeptName, UserId = x.UserId }; return(View(searcheditems)); } return(View(profileVM)); } }
public ActionResult Index(string str) { using (DMSDBContext dc = new DMSDBContext()) { List <ProfileVM> profileVM = new List <ProfileVM>(); profileVM = dc.Categories.Select(x => new ProfileVM { CategoryName = x.CategoryName, CategoryId = x.CategoryId, Email = x.User.Email }).ToList(); if (!string.IsNullOrEmpty(str)) { var searcheditems = from x in profileVM.Where(x => x.CategoryName.Contains(str) || x.Email.Contains(str)) select new ProfileVM { CategoryName = x.CategoryName, CategoryId = x.CategoryId, Email = x.Email }; return(View(searcheditems)); } return(View(profileVM)); } }
public ActionResult Create() { DMSDBContext dc = new DMSDBContext(); TempData["Departments"] = new SelectList(dc.Departments, "DeptId", "DeptName"); return(View()); }
public ActionResult ChangePassword(ProfileVM profileVM) { try { using (DMSDBContext dc = new DMSDBContext()) { string message = ""; var validate = dc.Users.Where(a => a.Password == profileVM.Password).FirstOrDefault(); if (validate != null) { validate.Password = profileVM.NewPassword; dc.Entry(validate).State = EntityState.Modified; dc.SaveChanges(); message = "Password Changed Successfully"; TempData["Message"] = message; return(RedirectToAction("Index", "Profile")); } else { message = "Input Valid Current Password"; } ViewBag.Message = message; return(View()); } } catch { return(View()); } }
public ActionResult Create(ProfileVM profileVM) { try { using (DMSDBContext dc = new DMSDBContext()) { string message = ""; var validate = dc.Departments.Where(a => a.DeptName == profileVM.DeptName).FirstOrDefault(); if (validate == null) { Department department = new Department(); department.DeptName = profileVM.DeptName; dc.Departments.Add(department); dc.SaveChanges(); message = "Department Created Successfully"; TempData["Message"] = message; return(RedirectToAction("Index", "Department")); } else { message = "This Department is already created. Please use another!!"; TempData["Message"] = message; return(RedirectToAction("Create", "Department")); } } } catch { return(View()); } }
public ActionResult Index() { using (DMSDBContext dc = new DMSDBContext()) { var user = dc.Users.Count(); var department = dc.Departments.Count(); var category = dc.Categories.Count(); if (User.IsInRole("Admin")) { var document = dc.Documents.Count(); ViewBag.document = document; } else { int id = Convert.ToInt32(Session["id"]); var document = dc.Documents.Where(x => x.UserId == id).Count(); ViewBag.document = document; } ViewBag.user = user; ViewBag.department = department; ViewBag.category = category; return(View()); } }
public ActionResult Download(int id) { using (DMSDBContext dc = new DMSDBContext()) { var data = dc.Documents.Where(x => x.DocumentId == id).FirstOrDefault(); string strPhysicalFolder = Server.MapPath("//Documents/" + data.Category.CategoryName + "/"); string strFileFullPath = strPhysicalFolder + data.DocumentName; return(File(strFileFullPath, System.Net.Mime.MediaTypeNames.Application.Octet, data.DocumentName)); } }
public ActionResult Edit(int id) { using (DMSDBContext dc = new DMSDBContext()) { var profile = dc.Departments.Where(x => x.DeptId == id).FirstOrDefault(); ProfileVM profileVM = new ProfileVM() { DeptId = profile.DeptId, DeptName = profile.DeptName, }; return(View(profileVM)); } }
public ActionResult Edit(int id) { using (DMSDBContext dc = new DMSDBContext()) { var data = dc.Categories.Where(x => x.CategoryId == id).FirstOrDefault(); ProfileVM profileVM = new ProfileVM() { CategoryId = data.CategoryId, CategoryName = data.CategoryName, }; return(View(profileVM)); } }
public ActionResult ChangePassword() { string email = User.Identity.Name; using (DMSDBContext dc = new DMSDBContext()) { var profile = dc.Users.FirstOrDefault(c => c.Email == email); ProfileVM profileVM = new ProfileVM() { UserId = profile.UserId, }; return(View(profileVM)); } }
public ActionResult Index(string str) { using (DMSDBContext dc = new DMSDBContext()) { List <ProfileVM> profileVM = new List <ProfileVM>(); if (User.IsInRole("Admin")) { profileVM = dc.Documents.Select(x => new ProfileVM { DocumentId = x.DocumentId, DocumentName = x.DocumentName, DocumentPath = x.DocumentPath, DocumentDetails = x.DocumentDetails, CategoryName = x.Category.CategoryName, Email = x.User.Email }).ToList(); } else { int id = Convert.ToInt32(Session["id"]); profileVM = dc.Documents.Where(x => x.UserId == id).Select(x => new ProfileVM { DocumentId = x.DocumentId, DocumentName = x.DocumentName, DocumentPath = x.DocumentPath, DocumentDetails = x.DocumentDetails, CategoryName = x.Category.CategoryName, Email = x.User.Email }).ToList(); } if (!string.IsNullOrEmpty(str)) { var searcheditems = from x in profileVM.Where(x => x.DocumentName.Contains(str) || x.DocumentName.Contains(str) || x.CategoryName.Contains(str) || x.Email.Contains(str)) select new ProfileVM { DocumentId = x.DocumentId, DocumentName = x.DocumentName, DocumentPath = x.DocumentPath, DocumentDetails = x.DocumentDetails, CategoryName = x.CategoryName, Email = x.Email }; return(View(searcheditems)); } return(View(profileVM)); } }
public ActionResult DocView(int id) { using (DMSDBContext dc = new DMSDBContext()) { var data = dc.Documents.Where(x => x.DocumentId == id).FirstOrDefault(); Gnostice.Documents.WebHandler.ViewerController viewerController = new Gnostice.Documents.WebHandler.ViewerController(); // Load the file present under App_Data folder String filenameWithPath = Server.MapPath("//Documents/" + data.Category.CategoryName + "/" + data.DocumentName); // Load the server-side document using the document URI ViewBag.docURI = viewerController.LoadDocument(filenameWithPath); return(View()); } }
public ActionResult Create(HttpPostedFileBase file, ProfileVM profileVM) { try { using (DMSDBContext dc = new DMSDBContext()) { string message = ""; int id = Convert.ToInt32(Session["id"]); string fileName = Path.GetFileName(file.FileName).Replace(" ", ""); var validate = (from p in dc.Documents where (p.DocumentName == fileName) && (p.CategoryId == profileVM.CategoryId) select p ).FirstOrDefault(); if (file.ContentLength > 0 && validate == null) { var category = dc.Categories.Where(a => a.CategoryId == profileVM.CategoryId).FirstOrDefault(); string path = Path.Combine(Server.MapPath("//Documents/" + category.CategoryName)); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string paths = Path.Combine(Server.MapPath("//Documents/" + category.CategoryName), fileName); Document document = new Document(); document.DocumentName = fileName; document.DocumentPath = path.ToString(); document.DocumentDetails = profileVM.DocumentDetails; document.CategoryId = profileVM.CategoryId; document.UserId = id; dc.Documents.Add(document); dc.SaveChanges(); file.SaveAs(paths); message = "Document Uploaded Successfully"; TempData["Message"] = message; return(RedirectToAction("Index", "Document")); } else { message = "Document size is zero OR same file name already present!!"; TempData["Message"] = message; return(RedirectToAction("Create", "Document")); } } } catch { return(View()); } }
public ActionResult Edit(int id) { DMSDBContext dc = new DMSDBContext(); var profile = dc.Users.Where(x => x.UserId == id).FirstOrDefault(); ProfileVM profileVM = new ProfileVM() { UserId = profile.UserId, FirstName = profile.FirstName, LastName = profile.LastName, Email = profile.Email, DeptId = profile.DeptId, DeptName = profile.Department.DeptName }; TempData["Departments"] = new SelectList(dc.Departments, "DeptId", "DeptName"); return(View(profileVM)); }
public ActionResult Index() { string email = User.Identity.Name; using (DMSDBContext dc = new DMSDBContext()) { var profile = dc.Users.FirstOrDefault(c => c.Email == email); ProfileVM profileVM = new ProfileVM() { UserId = profile.UserId, FirstName = profile.FirstName, LastName = profile.LastName, Email = profile.Email, DeptName = profile.Department.DeptName }; return(View(profileVM)); } }
public ActionResult Create() { using (DMSDBContext dc = new DMSDBContext()) { var data = dc.Categories.ToList(); var result = new List <SelectListItem>(); foreach (var item in data) { result.Add(new SelectListItem { Value = item.CategoryId.ToString(), Text = item.CategoryName, }); } TempData["category"] = new SelectList(result, "Value", "Text"); return(View()); } }
public ActionResult Delete(int id, ProfileVM profileVM) { try { using (DMSDBContext dc = new DMSDBContext()) { var data = dc.Categories.Where(x => x.CategoryId == id).FirstOrDefault(); dc.Categories.Remove(data); dc.SaveChanges(); string message = "Category Deleted Successfully"; TempData["Message"] = message; return(RedirectToAction("Index", "Category")); } } catch { string message = "You are trying to delete category which is currently used by users"; TempData["Message"] = message; return(RedirectToAction("Index", "Category"));; } }
public ActionResult Delete(int id, ProfileVM profileVM) { try { using (DMSDBContext dc = new DMSDBContext()) { var data = dc.Users.Where(x => x.UserId == id).FirstOrDefault(); dc.Users.Remove(data); dc.SaveChanges(); string message = "User Deleted Successfully"; TempData["Message"] = message; return(RedirectToAction("Index", "User")); } } catch { string message = "You are trying to delete User who have file!!"; TempData["Message"] = message; return(RedirectToAction("Index", "User")); } }
public ActionResult Login(ProfileVM loginVM) { using (DMSDBContext dc = new DMSDBContext()) { string message = ""; var validate = dc.Users.FirstOrDefault(x => x.Email == loginVM.Email && x.Password == loginVM.Password); if (validate != null) { var data = dc.Users.FirstOrDefault(a => a.Email == loginVM.Email); FormsAuthentication.SetAuthCookie(data.Email, false); Session["id"] = data.UserId; return(RedirectToAction("Index", "Home")); } else { message = "Invalid credential provided"; } ViewBag.Message = message; return(View()); } }
public ActionResult Delete(int id, ProfileVM profileVM) { try { using (DMSDBContext dc = new DMSDBContext()) { var data = dc.Departments.Where(x => x.DeptId == id).FirstOrDefault(); dc.Departments.Remove(data); dc.SaveChanges(); string message = "Department Deleted Successfully"; TempData["Message"] = message; return(RedirectToAction("Index", "Department")); } } catch { string message = "You are trying to delete department which is currently assigned to users"; TempData["Message"] = message; return(RedirectToAction("Index", "Department")); } }
public ActionResult Create(ProfileVM profileVM) { try { using (DMSDBContext dc = new DMSDBContext()) { string message = ""; var validate = dc.Users.Where(a => a.Email == profileVM.Email).FirstOrDefault(); if (validate == null) { User user = new User(); user.FirstName = profileVM.FirstName; user.LastName = profileVM.LastName; user.Email = profileVM.Email; user.Password = profileVM.NewPassword; user.DeptId = profileVM.DeptId; dc.Users.Add(user); dc.SaveChanges(); SendEmail(user.Email, user.Password); message = "User Created Successfully"; TempData["Message"] = message; return(RedirectToAction("Index", "User")); } else { message = "This Email address is already Used. Please use another!!"; TempData["Message"] = message; return(RedirectToAction("Create", "User")); } } } catch { return(View()); } }
public ActionResult Create(ProfileVM profileVM) { try { using (DMSDBContext dc = new DMSDBContext()) { string message = ""; var validate = dc.Categories.Where(a => a.CategoryName == profileVM.CategoryName).FirstOrDefault(); if (validate == null) { int id = Convert.ToInt32(Session["id"]); Category category = new Category(); category.CategoryName = profileVM.CategoryName; category.UserId = id; dc.Categories.Add(category); dc.SaveChanges(); message = "Category Created Successfully"; TempData["Message"] = message; if (User.IsInRole("Admin")) { return(RedirectToAction("Index", "Category")); } return(RedirectToAction("Create", "Category")); } else { message = "This Category is already created. Please use another!!"; TempData["Message"] = message; return(RedirectToAction("Create", "Category")); } } } catch { return(View()); } }
public ActionResult Edit(ProfileVM profileVM) { string message = ""; try { using (DMSDBContext dc = new DMSDBContext()) { var user = dc.Users.Where(x => x.UserId == profileVM.UserId).FirstOrDefault(); user.FirstName = profileVM.FirstName; user.LastName = profileVM.LastName; user.DeptId = profileVM.DeptId; dc.Entry(user).State = EntityState.Modified; dc.SaveChanges(); message = "User Edited Successfully"; TempData["Message"] = message; return(RedirectToAction("Index", "User")); } } catch { return(View()); } }