public ActionResult UpdateBaseQuota(string state) { using (var db = new EchoContext()) { IEnumerable <Quota> quotas = db.Quotas.Where(x => x.Quota_Type_Cd.Equals("B")); string user_no = Session["User_No"].ToString(); foreach (var item in quotas) { string fv = Request.Form["Quota_Freq_Val_" + item.Quota_Cd]; string dv = Request.Form["Quota_Dur_Val_" + item.Quota_Cd]; try { item.Quota_Freq_Val = Convert.ToByte(fv); item.Quota_Dur_Val = Convert.ToByte(dv); item.Updated_By = user_no; item.Updated_Dttm = DateTime.Now; db.Entry(item).State = EntityState.Modified; } catch { return(View(quotas)); } } db.SaveChanges(); FreebieEvent.UserUpdateEvent(Permission.base_quota_page_id, "A04"); return(RedirectToAction("BaseQuota")); } }
public ActionResult UpdateStaffAcct(int?user_id, string state) { if (user_id == null) { return(HttpNotFound()); } user_id = Convert.ToInt32(user_id); User user = db.Users.SingleOrDefault(x => x.User_Id == user_id); if (user == null) { return(HttpNotFound()); } if (string.IsNullOrWhiteSpace(Request.Form["First_Name"])) { ModelState.AddModelError("First_Name", "กรุณาระบุชื่อ"); } if (string.IsNullOrWhiteSpace(Request.Form["Last_Name"])) { ModelState.AddModelError("Last_Name", "กรุณาระบุนามสกุล"); } bool can_crud_this_user = Permission.can_update_this_staff(user); if (!can_crud_this_user) { return(HttpNotFound()); } user.First_Name = Request.Form["First_Name"]; user.Last_Name = Request.Form["Last_Name"]; user.Dept_Cd = Request.Form["Dept_Cd"]; user.Group_Id = Convert.ToByte(Request.Form["Group_Id"]); user.Status_Cd = Request.Form["Status_Cd"]; if (!string.IsNullOrWhiteSpace(Request.Form["PlainPwd"])) { string pwd = Request.Form["PlainPwd"]; user.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "SHA1"); } if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); FreebieEvent.UserUpdateEvent(Permission.staff_acct_page_id, "A04"); //init_dropdown(user); return(View("ViewStaffAcct", user)); } else { init_dropdown(user); return(View(user)); } }
public ActionResult UpdateStaffPwd(string status) { string current_pwd = Request.Form["CurrentPassword"]; string new_pwd = Request.Form["NewPassword"]; string confirm_pwd = Request.Form["ConfirmNewPassword"]; if (string.IsNullOrEmpty(current_pwd) || string.IsNullOrEmpty(new_pwd) || string.IsNullOrEmpty(confirm_pwd)) { ViewBag.Error = System.Configuration.ConfigurationManager.AppSettings["STAFF_PWD"]; return(View()); } if (new_pwd.Length < 6 || new_pwd.Length > 15) { ViewBag.Error = System.Configuration.ConfigurationManager.AppSettings["Validate008"]; return(View()); } if (new_pwd != confirm_pwd) { ViewBag.Error = System.Configuration.ConfigurationManager.AppSettings["Validate006"]; return(View()); } var enc = FormsAuthentication.HashPasswordForStoringInConfigFile(current_pwd, "SHA1"); string user_no = Session["User_No"].ToString(); User user = db.Users.SingleOrDefault(x => x.User_No.Equals(user_no)); if (user != null) { if (!user.Password.Equals(enc)) { ViewBag.Error = System.Configuration.ConfigurationManager.AppSettings["Validate007"]; return(View()); } var new_pwd_enc = FormsAuthentication.HashPasswordForStoringInConfigFile(new_pwd, "SHA1"); user.Password = new_pwd_enc; UpdateModel(user); db.SaveChanges(); FreebieEvent.UserUpdateEvent(Permission.staff_profile_page_id, "A04"); } return(RedirectToAction("StaffProfile")); }
public ActionResult UpdateActivationLimit(ActivationLimit al) { using (var db = new EchoContext()) { AdminConfiguration ac = db.AdminConfigurations.SingleOrDefault(); string user_no = Session["User_No"].ToString(); ac.No_Activation_Limit_Total = Convert.ToInt32(al.no_activation_limit_total); ac.No_Activation_Limit_Daily = Convert.ToInt32(al.no_activation_limit_daily); ac.Updated_By = user_no; ac.Updated_Dttm = DateTime.Now; db.Entry(ac).State = EntityState.Modified; db.SaveChanges(); FreebieEvent.UserUpdateEvent(Permission.activation_page_id, "A04"); return(RedirectToAction("ActivationLimit")); } }
public ActionResult UpdateFreeTrialQuota(TrialQuota tq) { using (var db = new EchoContext()) { AdminConfiguration ac = db.AdminConfigurations.SingleOrDefault(); string user_no = Session["User_No"].ToString(); ac.Trial_Limit_Total = Convert.ToInt32(tq.trial_limit_total); ac.Trial_Dur_Val = Convert.ToInt32(tq.trial_dur_val); ac.Trial_Enable_Flag = Convert.ToBoolean(tq.trial_enable_flag); ac.Updated_By = user_no; ac.Updated_Dttm = DateTime.Now; db.Entry(ac).State = EntityState.Modified; db.SaveChanges(); FreebieEvent.UserUpdateEvent(Permission.free_trial_page_id, "A04"); return(RedirectToAction("FreeTrialQuota")); } }
public ActionResult RemoveStaff(int?user_id) { if (user_id == null) { return(HttpNotFound()); } user_id = Convert.ToInt32(user_id); User u = db.Users.SingleOrDefault(x => x.User_Id == user_id); if (u == null) { return(HttpNotFound()); } bool can_crud_this_user = Permission.can_update_this_staff(u); if (!can_crud_this_user) { return(HttpNotFound()); } bool is_sup = false; if (u.Role_Cd.Equals("SU")) { is_sup = true; } db.Users.Remove(u); db.SaveChanges(); if (is_sup) { FreebieEvent.UserUpdateEvent(Permission.sup_acct_page_id, "A05"); return(RedirectToAction("SupervisorAcct")); } FreebieEvent.UserUpdateEvent(Permission.staff_acct_page_id, "A05"); return(RedirectToAction("StaffAcct")); }
public ActionResult UpdateSupervisorAcct(int?user_id, string state) { if (user_id == null) { return(HttpNotFound()); } user_id = Convert.ToInt32(user_id); User user = db.Users.SingleOrDefault(x => x.User_Id == user_id); if (user == null) { return(HttpNotFound()); } if (string.IsNullOrWhiteSpace(Request.Form["First_Name"])) { ModelState.AddModelError("First_Name", "กรุณาระบุชื่อ"); } if (string.IsNullOrWhiteSpace(Request.Form["Last_Name"])) { ModelState.AddModelError("Last_Name", "กรุณาระบุนามสกุล"); } bool can_crud_this_user = Permission.can_update_this_staff(user); if (!can_crud_this_user) { return(HttpNotFound()); } int group_id = Convert.ToByte(Request.Form["Group_Id"]); string dept_cd = Request.Form["Dept_Cd"]; User check_existing = db.Users.Where(x => x.Dept_Cd.Equals(dept_cd)).Where(x => x.Group_Id == group_id).Where(x => x.Role_Cd.Equals("SU")).SingleOrDefault(); user.First_Name = Request.Form["First_Name"]; user.Last_Name = Request.Form["Last_Name"]; user.Dept_Cd = Request.Form["Dept_Cd"]; user.Group_Id = Convert.ToByte(Request.Form["Group_Id"]); user.Status_Cd = Request.Form["Status_Cd"]; if (!string.IsNullOrWhiteSpace(Request.Form["PlainPwd"])) { string pwd = Request.Form["PlainPwd"]; user.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "SHA1"); } if (check_existing != null && check_existing.User_Id != user.User_Id) { ModelState.AddModelError("User_Name", System.Configuration.ConfigurationManager.AppSettings["SU_EXISTS"]); init_dropdown(user); return(View(user)); } if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); FreebieEvent.UserUpdateEvent(Permission.sup_acct_page_id, "A04"); return(View("ViewSupervisorAcct", user)); } else { init_dropdown(user); return(View(user)); } }