public ActionResult Profile(AspNetUserModel profileViewModel)
        {
            AspNetUser result = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(User.Identity.GetUserId());

            //Updating Data
            try
            {
                result.FirstName = profileViewModel.FirstName;
                result.LastName = profileViewModel.LastName;
                result.Telephone = profileViewModel.Telephone;
                result.Address = profileViewModel.Address;
                var updationResult = UserManager.Update(result);
                updateSessionValues(result);
                TempData["message"] = new MessageViewModel { Message = "Profile has been updated", IsUpdated = true };
            }
            catch (Exception e)
            {
            }
            return RedirectToAction("Profile");
        }
 public async Task<ActionResult> ResetPassword(ResetPasswordViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var user = await UserManager.FindByNameAsync(model.Email);
     if (user == null)
     {
         // Don't reveal that the user does not exist
         return RedirectToAction("Login", "Account");
     }
     var result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password);
     if (result.Succeeded)
     {
         TempData["message"] = new MessageViewModel { Message = "Password has been updated.", IsUpdated = true };
         return RedirectToAction("Login", "Account");
     }
     AddErrors(result);
     return View();
 }
        public async Task<ActionResult> Create(AspNetUsersViewModel model)
        {
            model.AspNetUserModel.UserName = model.AspNetUserModel.Email;
            #region Update
            if (!string.IsNullOrEmpty(model.AspNetUserModel.Id))
            {
                //Means Update

                // Get role
                var roleName = RoleManager.FindById(model.AspNetUserModel.RoleId).Name;
                AspNetUser userResult = UserManager.FindById(model.AspNetUserModel.Id);
                string userrRoleID = userResult.AspNetRoles.ToList()[0].Id;
                string userRoleName = RoleManager.FindById(userrRoleID).Name;

                // Check if role has been changed
               /************** DISABLING CHANGE ROLE IMPLEMENTATION/ UNCOMMENT TO RUN 
               if (userrRoleID != model.AspNetUserModel.RoleId)
                {
                    // Update User Role
                    UserManager.RemoveFromRole(model.AspNetUserModel.Id, userRoleName);
                    UserManager.AddToRole(model.AspNetUserModel.Id, roleName);
                    TempData["message"] = new MessageViewModel { Message = "Role has been updated", IsUpdated = true };
                }************************/
                // Password Reset
                if (!String.IsNullOrEmpty(model.AspNetUserModel.Password))
                {
                    var token = await UserManager.GeneratePasswordResetTokenAsync(model.AspNetUserModel.Id);
                    var resetPwdResults = await UserManager.ResetPasswordAsync(model.AspNetUserModel.Id, token, model.AspNetUserModel.Password);

                    if (resetPwdResults.Succeeded)
                    {
                        var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
                        if (user != null)
                        {
                            await SignInAsync(user, isPersistent: false);
                        }
                        TempData["message"] = new MessageViewModel
                        {
                            Message = TMD.Web.Resources.HR.Account.UpdatePass,
                            IsUpdated = true
                        };
                    }
                }
                // Get user by UserId to Update User
                AspNetUser userToUpdate = UserManager.FindById(model.AspNetUserModel.Id);
                //if (userToUpdate.Email != model.AspNetUserModel.Email)
                //{
                    
                    if (userToUpdate != null)
                    {
                        userToUpdate.UpdateUserTo(model.AspNetUserModel);
                    }
                    var updateUserResult = await UserManager.UpdateAsync(userToUpdate);
                    if (updateUserResult.Succeeded)
                    {
                        TempData["message"] = new MessageViewModel
                        {
                            Message = "User has been Updated",
                            IsUpdated = true
                        };
                    }
                //}

                return RedirectToAction("Users");
            }
            #endregion
            // Add new User
            if (ModelState.IsValid)
            {
                // TODO:Check # of Users that Admin can create
                var user = new AspNetUser
                {
                    UserName = model.AspNetUserModel.UserName,
                    Email = model.AspNetUserModel.Email,
                    Address = model.AspNetUserModel.Address, 
                    Telephone = model.AspNetUserModel.Telephone,FirstName = model.AspNetUserModel.FirstName,LastName = model.AspNetUserModel.LastName, LockoutEnabled = false,
                    RegisterPayPalDate = null
                };
                user.EmailConfirmed = true;
                if (!String.IsNullOrEmpty(model.AspNetUserModel.Password))
                {
                    var result = await UserManager.CreateAsync(user, model.AspNetUserModel.Password);
                    if (result.Succeeded)
                    {
                        //Setting role
                        var roleManager = HttpContext.GetOwinContext().Get<ApplicationRoleManager>();
                        var roleName = roleManager.FindById(model.AspNetUserModel.RoleId).Name;
                        UserManager.AddToRole(user.Id, roleName);
                        // Add User Preferences for Dashboards Widgets

                        TempData["message"] = new MessageViewModel
                        {
                            Message = "Employee has been created",
                            IsSaved = true
                        };
                        return RedirectToAction("Users");
                    }
                    else
                    {
                        var resultStr = "";
                        if (result.Errors.Count() > 0)
                            resultStr = result.Errors.ToList()[0].ToString();
                        TempData["message"] = new MessageViewModel
                        {
                            Message = resultStr,
                            IsError = true
                        };
                        ViewBag.MessageVM = TempData["message"] as MessageViewModel;
                    }
                }
            }
            // If we got this far, something failed, redisplay form
            model.Roles = HttpContext.GetOwinContext().Get<ApplicationRoleManager>().Roles.ToList();
            //TempData["message"] = new MessageViewModel { Message = TMD.Web.Resources.HR.Account.ChkFields, IsError = true };
            return View(model);
        }
        public async Task<ActionResult> Subscribe(SignupViewModel signupViewModel)
        {
            // Add new User
                // Check if User already exists
                var usernames = AspNetUserService.GetAllUsers().Select(x => x.UserName);
                if (usernames.Contains(signupViewModel.UserName))
                {
                    // it means username is already taken
                    TempData["message"] = new MessageViewModel { Message = TMD.Web.Resources.HR.Account.EmpError, IsError = true };
                    return View(signupViewModel);
                }

                var user = new AspNetUser { UserName = signupViewModel.UserName, Email = signupViewModel.Email };
                user.EmailConfirmed = true;
                if (!String.IsNullOrEmpty(signupViewModel.Password))
                {
                    var result = await UserManager.CreateAsync(user, signupViewModel.Password);
                    if (result.Succeeded)
                    {
                        return RedirectToAction("Index","Home");
                    }
                }
            return View(signupViewModel);
        }
        public ActionResult EbayItemImportDetail(StagingEbayItemModel item)
        {
            try
            {
                if (StagingEbayLoadService.UpdateEbayItemImportDetail(item.EbayItemtId, item.AFASerial, User.Identity.GetUserId()))
                {
                    TempData["message"] = new MessageViewModel
                    {
                        IsUpdated = true,
                        Message = "Item has been updated."
                    };
                    return RedirectToAction("EbayItemImportLV");
                }
            }
            catch (Exception)
            {

                throw;
            }
            return View(item);
        }