public ActionResult Login(LoginViewModel model, string ReturnUrl = "") { string EncryptionKey = "SHA512"; string message = ""; if (ModelState.IsValid) { using (EastMedDB db = new EastMedDB()) { var userexist = db.user.Where(a => a.UNI_ID == model.UNI_ID && a.IsActive == true).FirstOrDefault(); if (userexist != null) { if (string.Compare((model.Password.Trim()), CustomDecrypt.passwordDecrypt(userexist.PASSWORD, EncryptionKey)) == 0) { // In here 2 method has been used to save user login atraction to specific pages // Sessions and cookies give as to control menus and specification for each user. // Cookies to used authorized the application and protect to anonymous enter // Cookies are encrypted in client site the avoid from the cookie attacks. Session["RoleID"] = userexist.FK_PRIVILEGE_ID; Session["UserName"] = userexist.FIRST_NAME + " " + userexist.LAST_NAME; Session["UserID"] = userexist.UNI_ID; Session["UserDatabaseID"] = userexist.ID; int timeout = model.RememberMe ? 525600 : 30; // 30 min to expire the cookie. var ticket = new FormsAuthenticationTicket(model.UNI_ID, model.RememberMe, timeout); string encrypted = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted); cookie.Expires = DateTime.Now.AddMinutes(timeout); cookie.HttpOnly = true; Response.Cookies.Add(cookie); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { userexist.LAST_LOGINDATE = DateTime.Now; db.user.Attach(userexist); var entry = db.Entry(userexist); entry.Property(x => x.LAST_LOGINDATE).IsModified = true; db.SaveChanges(); return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Invalid user/pass"); return(View()); } } else { ModelState.AddModelError("", "Invalid user/pass"); return(View()); } } } ViewBag.Message = message; return(View()); }
// GET: Complaint/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } complaint complaint = db.complaint.Find(id); var queryComplaint = (from comp in db.complaint join u in db.user on comp.FK_USER_ID equals u.ID join cate in db.category on comp.FK_CATEGORY_ID equals cate.ID join loc in db.location on comp.FK_Location_ID equals loc.ID join i in db.item on comp.FK_ITEM_ID equals i.ID join it in db.itemtype on i.ID equals it.ID orderby(cate.CATEGORY_NAME) where comp.ID == id select new ComplaintModel { STATUS = comp.STATUS, COMMENT = comp.COMMENT, UserName = u.FIRST_NAME + " " + u.LAST_NAME, ITEM_ID = comp.ITEM_ID, IsActive = comp.IsActive, ComplaintId = comp.ID, CategoryName = cate.CATEGORY_NAME, PRIORITY = comp.PRIORITY, STARTDATE = comp.START_DATE, itemName = i.ITEM_NAME, RoomNo = loc.ROOM_ID, ImgUrl = comp.ImgURL }); if (queryComplaint == null) { return(HttpNotFound()); } var SessionControl = Convert.ToInt32(HttpContext.Session["RoleID"]); if (complaint.STATUS.Trim().ToUpper() == "NEW" & SessionControl == 7) { complaint.STATUS = "SEEN".Trim().ToUpper(); db.complaint.Attach(complaint); var entry = db.Entry(complaint); entry.Property(x => x.STATUS).IsModified = true; db.SaveChanges(); } return(View(complaint)); //Instead of using single return value it is faster and reliable to use it "singleordefault". }
public ActionResult Edit([Bind(Include = "ID,CATEGORY_NAME,DESCRIPTION,FK_USER_ID,IsActive")] category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); TempData["info"] = "Category Editing Succesfully"; return(RedirectToAction("Index")); } ViewBag.FK_USER_ID = new SelectList(db.user, "ID", "FIRST_NAME", category.FK_USER_ID); return(View(category)); }
public ActionResult Edit(location location) { var SessionControl = Convert.ToInt32(HttpContext.Session["RoleID"]); if (SessionControl != 5) { return(HttpNotFound()); } if (location == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (db.location.Any(x => x.ROOM_ID.Trim().ToUpper() == location.ROOM_ID.Trim().ToUpper())) { TempData["info"] = location.ROOM_ID + " " + " Location already created!"; return(RedirectToAction("Create", "Location")); } if (ModelState.IsValid) { location.UPDATED_DATE = DateTime.Now; db.location.Attach(location); var entry = db.Entry(location); entry.Property(x => x.ROOM_ID).IsModified = true; entry.Property(x => x.UPDATED_DATE).IsModified = true; entry.Property(x => x.TYPE).IsModified = true; entry.Property(x => x.FK_DEPT_ID).IsModified = true; db.SaveChanges(); //db.Entry(location).State = EntityState.Modified; //db.SaveChanges(); //_locationRepository.Update(location); //_locationRepository.Save(); TempData["Msg"] = "Location has been updated succeessfully"; return(RedirectToAction("Index")); } ViewBag.FK_DEPT_ID = new SelectList(db.departmant, "ID", "DEPT_NAME", location.FK_DEPT_ID); return(View(location)); }
public ActionResult Edit([Bind(Include = "ID,COMMENT,STATUS,START_DATE,PRIORITY,FK_USER_ID,FK_CATEGORY_ID,IsActive,FK_Location_ID,FK_ITEM_ID,ITEM_ID")] complaint complaint) { if (ModelState.IsValid) { db.complaint.Attach(complaint); var entry = db.Entry(complaint); entry.Property(x => x.COMMENT).IsModified = true; entry.Property(x => x.START_DATE).IsModified = true; entry.Property(x => x.PRIORITY).IsModified = true; entry.Property(x => x.FK_USER_ID).IsModified = true; entry.Property(x => x.IsActive).IsModified = true; entry.Property(x => x.FK_Location_ID).IsModified = true; entry.Property(x => x.FK_ITEM_ID).IsModified = true; entry.Property(x => x.ITEM_ID).IsModified = true; db.Entry(complaint).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } SetCategory(); //ViewBag.Itemlist = new SelectList(GetItemType(), "ID", "Item_Type"); ViewBag.DepartmentList = new SelectList(GetDepartmentList(), "ID", "DEPT_NAME"); return(View(complaint)); }
[ValidateAntiForgeryToken] // for avoid the anti forgery keys attacks. public ActionResult Edit([Bind(Include = "ID,DEPT_NAME,DEPT_ID,IsActive")] departmant departmant) { var SessionControl = Convert.ToInt32(HttpContext.Session["RoleID"]); if (SessionControl != 5) { return(RedirectToAction("Index", "Home")); } //Check if model state which is department model from requested result and validations are true then edit else return the current page if (ModelState.IsValid) { db.Entry(departmant).State = EntityState.Modified; db.SaveChanges(); TempData["info"] = "Department Edit Succesfully"; return(RedirectToAction("Index", "Location")); } return(View(departmant)); }
public ActionResult Edit(UserVM User, int?id) { try { ViewBag.Role = db.user.Where(x => x.ID == id).Include(x => x.privilege).SingleOrDefault().privilege.ROLE; if (ModelState.IsValid) { var dbUser = db.user.Where(x => x.ID == id).SingleOrDefault(); dbUser.UPDATED_DATE = DateTime.Now; dbUser.PASSWORD = CustomEncrypt.passwordEncrypt(User.PASSWORD, EncryptionKey); dbUser.PHONE = User.PHONE; dbUser.EMAIL = User.EMAIL; db.user.Attach(dbUser); var entry = db.Entry(dbUser); entry.Property(x => x.UPDATED_DATE).IsModified = true; entry.Property(x => x.PASSWORD).IsModified = true; entry.Property(x => x.PHONE).IsModified = true; entry.Property(x => x.EMAIL).IsModified = true; db.SaveChanges(); TempData["info"] = "Profile Edit Succesfully"; return(Json(new ResultJson { Success = false, Message = "Edit User Succesfull!" })); } else { //ModelState.AddModelError() return(Json(new ResultJson { Success = false, Message = "User Does not find!" })); } } catch (Exception ex) { return(Json(new ResultJson { Success = false, Message = "Error Occured while Editing User!" })); } }
public ActionResult Create(ComplaintHistoryModel model, int?id) { // complaint status string statusc = ""; int sessionControl = Convert.ToInt32(HttpContext.Session["UserDatabaseID"]); complaint_history comphist = new complaint_history(); int quote = (int)id; complaint complaint = db.complaint.Find(id); if (model != null) { try { if (Convert.ToInt32(model.Status) == 0) { comphist.STATUS = statusc = "On Progress".Trim().ToUpper(); } if (Convert.ToInt32(model.Status) == 1) { comphist.STATUS = statusc = "SOLVED".Trim().ToUpper(); } else if (Convert.ToInt32(model.Status) == 2) { comphist.STATUS = statusc = "UNSOLVED".Trim().ToUpper(); } comphist.MODIFIED_TIME = DateTime.Now; comphist.COMMENT = model.Comment; comphist.FK_CATEGORYUSER_ID = sessionControl; comphist.FK_COMPLAINT_ID = quote; comphist.FK_CATEGORY_ID = model.CategoryID; db.complaint_history.Add(comphist); db.SaveChanges(); if (Convert.ToInt32(model.Status) == 0) { complaint.STATUS = statusc = "ON PROGRESS".Trim().ToUpper(); } if (Convert.ToInt32(model.Status) == 1) { complaint.STATUS = statusc = "SOLVED".Trim().ToUpper(); } else if (Convert.ToInt32(model.Status) == 2) { complaint.STATUS = statusc = "UNSOLVED".Trim().ToUpper(); } db.complaint.Attach(complaint); var entry = db.Entry(complaint); entry.Property(x => x.STATUS).IsModified = true; db.SaveChanges(); TempData["Info"] = "Complaint " + comphist.ID + " of status successfuly changed to " + comphist.STATUS; return(RedirectToAction("Index")); } catch { TempData["error"] = "Error occured while modifying complaint"; return(View(model)); } } var types = new List <ComplaintHistoryStatus>(); types.Add(new ComplaintHistoryStatus() { Id = 0, ComplaintStatus = "On Progress" }); types.Add(new ComplaintHistoryStatus() { Id = 1, ComplaintStatus = "Solved" }); types.Add(new ComplaintHistoryStatus() { Id = 2, ComplaintStatus = "UnSolved" }); ViewBag.PartialTypes = types; ViewBag.FK_CATEGORY_ID = new SelectList(db.category, "ID", "CATEGORY_NAME", complaint.FK_CATEGORY_ID); return(View(model)); }
// Delete user will show up the sweet alert messegae to confirm from client side // will return to json to Delete user View // User cannot delete if he/she already login. public JsonResult Delete(user User) { user dbUser = db.user.Find(User.ID); var currentSessionUser = Convert.ToString(HttpContext.Session["UserID"]); if (dbUser == null) { return(Json(new ResultJson { Success = false, Message = "User Bulunamadı !" })); } try { if (currentSessionUser == dbUser.UNI_ID) { return(Json(new ResultJson { Success = false, Message = "Cannot delete current already Login User !" })); } if (dbUser.FK_PRIVILEGE_ID == 5 & currentSessionUser != "1000000000") { return(Json(new ResultJson { Success = false, Message = "You Do not have permission to delete any other admin User !" })); } if (currentSessionUser == "1000000000" & User.FK_PRIVILEGE_ID == 5) { _userRepository.Delete(User.ID); _userRepository.Save(); return(Json(new ResultJson { Success = true, Message = "Admin User Has been Deleted" })); } var CategoryExist = db.category.Where(x => x.FK_USER_ID == User.ID); if (CategoryExist.Any()) { return(Json(new ResultJson { Success = false, Message = "You Can not delete maintanence officers who still registered on a category!" })); } if (dbUser.complaint.Any()) { dbUser.IsActive = false; dbUser.UPDATED_DATE = DateTime.Now; db.user.Attach(dbUser); var entry = db.Entry(dbUser); entry.Property(x => x.UPDATED_DATE).IsModified = true; entry.Property(x => x.IsActive).IsModified = true; db.SaveChanges(); return(Json(new ResultJson { Success = true, Message = "User has already complaint. User IsActive status changed to False!" })); } else { _userRepository.Delete(User.ID); _userRepository.Save(); return(Json(new ResultJson { Success = true, Message = "User Has been Deleted" })); } } catch (Exception ex) { return(Json(new ResultJson { Success = false, Message = "Error Occured please Try Again!" })); } }