public async Task <IActionResult> Create([Bind("TitleOfUserId,TitleOfUserName")] TitleOfUser titleOfUser) { /*Check Session */ var page = "43"; var typeofuser = ""; var PermisionAction = ""; // CheckSession if (string.IsNullOrEmpty(HttpContext.Session.GetString("Username"))) { Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error); return(RedirectToAction("Index", "Home")); } else { typeofuser = HttpContext.Session.GetString("TypeOfUserId"); PermisionAction = HttpContext.Session.GetString("PermisionAction"); if (PermisionHelper.CheckPermision(typeofuser, PermisionAction, page) == false) { Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error); return(RedirectToAction("Index", "Home")); } } /*Check Session */ if (ModelState.IsValid) { _context.Add(titleOfUser); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(titleOfUser)); }
public async Task <IActionResult> Edit([Bind("TitleOfUserId,TitleOfUserName")] TitleOfUser titleOfUser) { /*Check Session */ var page = "44"; var typeofuser = ""; var PermisionAction = ""; // CheckSession if (string.IsNullOrEmpty(HttpContext.Session.GetString("Username"))) { Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error); return(RedirectToAction("Index", "Home")); } else { typeofuser = HttpContext.Session.GetString("TypeOfUserId"); PermisionAction = HttpContext.Session.GetString("PermisionAction"); if (PermisionHelper.CheckPermision(typeofuser, PermisionAction, page) == false) { Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error); return(RedirectToAction("Index", "Home")); } } /*Check Session */ if (ModelState.IsValid) { try { //ViewData["TitleOfUserId"] = titleOfUser.TitleOfUserId; //ViewData["TitleOfUserName"] = titleOfUser.TitleOfUserName; _context.Update(titleOfUser); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TitleOfUserExists(titleOfUser.TitleOfUserId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(RedirectToAction("Index", "Home")); }