Exemplo n.º 1
0
        public IActionResult UpdateProfile(User user)
        {
            var msg       = "Successfully updated";
            var status    = true;
            var userEmail = HttpContext.Session.GetString("userEmail");

            if (user.user_email.Equals(userEmail))
            {
                _userDB.updateUser(user);
                logActivity("Update profile", "Email = " + userEmail + ", First name = " + user.user_first_name + ", Last name = " + user.user_last_name);
            }
            else
            {
                if (!_userDB.checkUserExist(user))
                {
                    _userDB.updateUserWithEmail(user, userEmail);
                    logActivity("Update profile", "Email = " + userEmail + ", First name = " + user.user_first_name + ", Last name = " + user.user_last_name);
                    HttpContext.Session.SetString("userEmail", user.user_email);
                }
                else
                {
                    // Return Error
                    msg    = "Email has already existed. Please choose another email.";
                    status = false;
                }
            }
            HttpContext.Session.SetString("firstName", user.user_first_name);
            HttpContext.Session.SetString("lastName", user.user_last_name);
            return(Ok(new
            {
                status = status,
                message = msg,
                userEmail = user.user_email,
                userFirstName = user.user_first_name,
                userLastName = user.user_last_name
            }));
        }