Ejemplo n.º 1
0
        private bool updateNewUser(RegisterViewModel model)
        {
            bool validUser = false;

            try
            {
                using (var context = new ResumeModel())
                {
                    var chkUser = context.Emails.Where(s => s.Email1 == model.Email).FirstOrDefault();
                    if (chkUser == null)
                    {
                        User  newuser      = new User();
                        Email newUserEmail = new Email();
                        var   keynew       = Helper.GeneratePassword(10);
                        var   password     = Helper.EncodePassword(model.Password, keynew);
                        newuser.RoleID              = 2;
                        newuser.SaltHash            = keynew;
                        newuser.DateCreated         = DateTime.Today;
                        newuser.UserHash            = password;
                        newuser.DatePasswordChanged = DateTime.Today;
                        newuser.Active              = true;

                        context.Users.Add(newuser);
                        context.SaveChanges();
                        context.Entry(newuser).GetDatabaseValues();
                        Guid mykey = newuser.UserID;

                        newUserEmail.Email1        = model.Email;
                        newUserEmail.UserID        = mykey;
                        newUserEmail.DateEmailSent = DateTime.Now;
                        context.Emails.Attach(newUserEmail);
                        context.SaveChanges();

                        ModelState.Clear();
                        validUser = true;
                    }
                }
            }
            catch (Exception e)
            {
                ViewBag.ErrorMessage = "User already Exist";
                validUser            = false;
            }
            return(validUser);
        }
Ejemplo n.º 2
0
        public ActionResult UpdateUser([Bind(Exclude = "last_update_date")] Table_User user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (var context = new ResumeModel())
                    {
                        context.Entry(user).State = EntityState.Modified;
                        user.last_update_date     = DateTime.Now;
                        context.SaveChanges();
                    }
                    ViewBag.Message = "Profile updated successfully/ 賬號修改成功";
                }
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Error in updating profile";
            }

            return(View("Home"));
        }