Example #1
0
        public void adduser(userinfo eh)
        {
            var      uid = db.Usrs.Max(v => v.ID) + 1;
            Usr      ei  = new Usr();
            Secur    sr  = new Secur();
            UserRole ur  = new UserRole();

            ei.UserID = uid;
            ei.EmpID  = eh.EmpID;
            var emp = db.EmpInfoes.Where(x => x.ID == eh.EmpID).FirstOrDefault();

            emp.Usr        = eh.UserName.Trim();
            ei.UserName    = eh.UserName.Trim();
            ei.UserKey     = sr.Encrypt(eh.UserKey.Trim());
            ei.EntryKey    = "000";
            ei.Role        = eh.Role;
            ei.Email       = eh.Email;
            ei.Telephone   = eh.Telephone;
            ei.IsActive    = eh.IsActive;
            ei.ValidFrom   = eh.ValidFrom;
            ei.CreatedBy   = eh.Createby;
            ei.CreatedDate = DateTime.Today;
            ei.CreatedTime = DateTime.Now.TimeOfDay;
            ur.UserID      = uid;
            ur.RoleID      = eh.Role;
            ur.IsActive    = eh.IsActive;
            ur.ValidFrom   = DateTime.Today;
            ur.CreatedBy   = eh.Createby;
            ur.CreatedDate = DateTime.Today;
            ur.CreatedTime = DateTime.Now.TimeOfDay;
            db.Usrs.Add(ei);
            db.SaveChanges();
            db.UserRoles.Add(ur);
            db.SaveChanges();
        }
Example #2
0
        public JsonResult pwUpdat(int id, string pw, string npw)
        {
            Secur sr    = new Secur();
            var   udept = am.Usrs.SingleOrDefault(v => v.UserID == id);

            if (pw == sr.Decrypt(udept.UserKey))
            {
                udept.UserKey = sr.Encrypt(npw);
                am.SaveChanges();
                return(Json(new { Success = true }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var result = new { Success = false };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }