示例#1
0
 public ActionResult CreateStaffAcct(User u)
 {
     if (string.IsNullOrWhiteSpace(u.First_Name))
     {
         ModelState.AddModelError("First_Name", "กรุณาระบุชื่อ");
     }
     if (string.IsNullOrWhiteSpace(u.Last_Name))
     {
         ModelState.AddModelError("Last_Name", "กรุณาระบุนามสกุล");
     }
     if (ModelState.IsValid)
     {
         string pwd = PasswordGenerator.Get();
         u.Role_Cd      = "ST";
         u.Password     = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "SHA1");
         u.Created_By   = System.Configuration.ConfigurationManager.AppSettings["SystemUsername"];
         u.Updated_By   = System.Configuration.ConfigurationManager.AppSettings["SystemUsername"];
         u.Created_Dttm = DateTime.Now;
         u.Updated_Dttm = DateTime.Now;
         db.Users.Add(u);
         db.SaveChanges();
         FreebieEvent.UserCreateEvent(Permission.staff_acct_page_id);
         return(RedirectToAction("AssignUserName", new { user_id = u.User_Id, pwd = pwd }));
     }
     else
     {
         init_dropdown(u);
         return(View(u));
     }
 }
示例#2
0
        public ActionResult CreateSupervisorAcct(User u)
        {
            int    group_id = Convert.ToInt16(u.Group_Id);
            string dept_cd  = u.Dept_Cd;

            if (string.IsNullOrWhiteSpace(u.First_Name))
            {
                ModelState.AddModelError("First_Name", "กรุณาระบุชื่อ");
            }
            if (string.IsNullOrWhiteSpace(u.Last_Name))
            {
                ModelState.AddModelError("Last_Name", "กรุณาระบุนามสกุล");
            }

            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();

            if (check_existing != null)
            {
                ModelState.AddModelError("User_Name", System.Configuration.ConfigurationManager.AppSettings["SU_EXISTS"]);
            }
            if (ModelState.IsValid)
            {
                string pwd = PasswordGenerator.Get();
                u.Role_Cd      = "SU";
                u.Password     = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "SHA1");
                u.Created_By   = System.Configuration.ConfigurationManager.AppSettings["SystemUsername"];
                u.Updated_By   = System.Configuration.ConfigurationManager.AppSettings["SystemUsername"];
                u.Created_Dttm = DateTime.Now;
                u.Updated_Dttm = DateTime.Now;
                db.Users.Add(u);
                db.SaveChanges();
                FreebieEvent.UserCreateEvent(Permission.sup_acct_page_id);
                return(RedirectToAction("AssignUserName", new { user_id = u.User_Id, pwd = pwd }));
            }
            else
            {
                init_dropdown(u);
                return(View(u));
            }
        }