Пример #1
0
        public ActionResult Register(user_login user_Login)
        {
            try
            {
                using (var db = new HRISContext())
                {
                    var chkUser = (from s in db.user_login where s.user_id == user_Login.user_id select s).FirstOrDefault();
                    if (chkUser == null)
                    {
                        var keyNew = PasswordHashHelper.GeneratePassword(10);
                        var pass   = PasswordHashHelper.EncodePassword(user_Login.password, keyNew);

                        user_Login.password = pass;
                        user_Login.vcode    = keyNew;

                        db.user_login.Add(user_Login);
                        db.SaveChanges();
                        ModelState.Clear();

                        return(RedirectToAction("LogIn", "Login"));
                    }
                    ViewBag.ErrorMessage = "User Already Exixts!";
                    return(View());
                }
            }
            catch (Exception e)
            {
                ViewBag.ErrorMessage = "Some exception occured" + e;
                return(View());
            }
        }
Пример #2
0
        public ActionResult Create(user_login user_Login)
        {
            try
            {
                var check = (from s in db.user_login where s.user_id == user_Login.user_id select s).FirstOrDefault();
                if (check == null)
                {
                    var keyNew = PasswordHashHelper.GeneratePassword(10);
                    var pass   = PasswordHashHelper.EncodePassword(user_Login.user_id + DateTime.Now.Year.ToString(), keyNew);

                    user_login _Login = new user_login
                    {
                        user_id      = user_Login.user_id,
                        password     = pass,
                        vcode        = keyNew,
                        role         = user_Login.role,
                        status       = user_Login.status,
                        date_created = DateTime.Now
                    };

                    karyawan karyawan = new karyawan
                    {
                        user_id = _Login.user_id
                    };

                    db.user_login.Add(_Login);
                    db.karyawan.Add(karyawan);
                    db.SaveChanges();

                    ModelState.Clear();

                    return(Json("0", JsonRequestBehavior.AllowGet));
                }

                return(Json("1", JsonRequestBehavior.AllowGet));
            }
            catch (DbEntityValidationException e)
            {
                return(Json("2", JsonRequestBehavior.AllowGet));
            }
        }