示例#1
0
        public async Task <IActionResult> ChangePasswordEmployer(EditEmployerViewModel model)
        {
            ModelState.ClearValidationState("Employer");
            if (ModelState.IsValid)
            {
                var user = await signInManager.UserManager.GetUserAsync(this.User);

                if (user == null)
                {
                    return(RedirectToAction("Login", "Account"));
                }
                var reuslt = await signInManager.UserManager.ChangePasswordAsync(user, model.CurrentPassword, model.NewPassword);

                if (!reuslt.Succeeded)
                {
                    foreach (var error in reuslt.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                    return(View("EditEmployerProfile"));
                }
                await signInManager.RefreshSignInAsync(user);

                toastNotification.AddSuccessToastMessage("Password Updated !", new NotyOptions
                {
                    Theme   = "metroui",
                    Timeout = 1500,
                    Layout  = "topCenter"
                });
                return(RedirectToAction("EditEmployerProfile"));
            }
            return(View("EditEmployerProfile", model));
        }
示例#2
0
        public async Task <IActionResult> EditEmployerProfile(EditEmployerViewModel model)
        {
            var currentUser = this.User;
            var user        = await signInManager.UserManager.GetUserAsync(currentUser);

            if (user == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            if (model.ImageFile == null)
            {
                model.Employer.Picture = user.Picture;
            }
            if (ModelState.IsValid)
            {
                try
                {
                    if (model.ImageFile != null)
                    {
                        string imageFileName = new string(Path.GetFileNameWithoutExtension(model.ImageFile.FileName).Take(10).ToArray()).Replace(' ', '-');
                        string newFileName   = imageFileName + '-' + Guid.NewGuid().ToString() + '.' + Path.GetExtension(model.ImageFile.FileName);
                        string destination   = Path.Combine(hostEnvironment.WebRootPath, "uploads/UserImages");
                        destination = Path.Combine(destination, newFileName);
                        using (var fileStream = new FileStream(destination, FileMode.Create))
                        {
                            model.ImageFile.CopyTo(fileStream);
                        }
                        user.Picture = newFileName;
                    }
                    user.CompanyName = model.Employer.CompanyName;
                    user.Email       = model.Employer.Email;
                    user.PhoneNumber = model.Employer.PhoneNumber;
                    user.AboutMe     = model.Employer.AboutMe;
                    user.SocialMedia = new SocialMedia
                    {
                        Facebook = model.social.Facebook,
                        Youtube  = model.social.Youtube,
                        Linkedin = model.social.Linkedin,
                        Twitter  = model.social.Twitter
                    };
                    db.Update <User>(user);
                    await db.SaveChangesAsync();

                    toastNotification.AddSuccessToastMessage("User Updated !", new NotyOptions
                    {
                        Theme   = "metroui",
                        Timeout = 1500,
                        Layout  = "topCenter"
                    });
                    return(RedirectToAction("EditCandidateProfile"));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            return(View(model));
        }
示例#3
0
        public async Task <IActionResult> EditEmployerProfile()
        {
            User user = await signInManager.UserManager.GetUserAsync(this.User);

            EditEmployerViewModel model = new EditEmployerViewModel
            {
                Employer = user,
                social   = user.SocialMedia
            };

            return(View(model));
        }