public async Task <ActionResult> Index(ProfileViewModels model) { Account acc = new Account() { Email = model.EmailAddress, FirstName = model.FirstName, LastName = model.LastName, Id = current_UserID }; string url = _appSettings.ApiUrl + "/Profile/UpdateProfile"; client = new HttpClient(); HttpResponseMessage responseMessage = await client.PostAsJsonAsync(url, acc); var responseData = new ResponseData <Account>(); if (responseMessage.IsSuccessStatusCode) { responseData = responseMessage.Content.ReadAsAsync <ResponseData <Account> >().Result; if (responseData != null && responseData.Data != null) { model.EmailAddress = responseData.Data.Email; model.FirstName = responseData.Data.FirstName; model.LastName = responseData.Data.LastName; model.PhoneNumber = responseData.Data.PhoneNumber; } } return(View(model)); }
public async Task <ActionResult> ChangePassword(ProfileViewModels model) { Account acc = new Account() { LastPasswords = model.ExistingPassword, Password = model.NewPassword, Id = current_UserID }; string url = _appSettings.ApiUrl + "/Profile/ChangePassword"; client = new HttpClient(); HttpResponseMessage responseMessage = await client.PostAsJsonAsync(url, acc); var responseData = new ResponseData <Account>(); if (responseMessage.IsSuccessStatusCode) { responseData = responseMessage.Content.ReadAsAsync <ResponseData <Account> >().Result; if (responseData != null && responseData.Data != null) { return(RedirectToAction("Index", "Profile", new { success = true })); } } return(RedirectToAction("Index", "Profile", new { success = false })); }
public ActionResult UsersProfile() { var id = User.Identity.GetUserId(); var user = context.Users.FirstOrDefault(u => u.Id == id); var empl = context.Employee.FirstOrDefault(u => u.UserId == id); if (user == null) { return(RedirectToAction("Login", "Account")); } ProfileViewModels model = new ProfileViewModels { UserId = id, Name = empl?.Name ?? "", Patronymic = empl?.Patronymic ?? "", Surname = empl?.Surname ?? "", Birthday = empl?.Birthday ?? DateTime.Now, PhoneNumber = user.PhoneNumber, Email = user.Email, Nickname = empl?.Nickname ?? "", Introduction = empl?.Introduction ?? "", Description = empl?.Description ?? "", TwoFactorEnabled = user.TwoFactorEnabled, EmailConfirmed = user.EmailConfirmed, PhoneNumberConfirmed = user.PhoneNumberConfirmed }; return(View(model)); }
// GET: Profile public ActionResult ProfileOverview() { ProfileViewModels model = new ProfileViewModels() { }; return(View(model)); }
public async Task <ActionResult> ChangeInformation(ProfileViewModels model) { Account user = await _accountService.FindByIdAsync(User.Identity.GetUserId()); user.FullName = model.Fullname; user.Email = model.EmailAddress; user.PhoneNumber = model.PhoneNumber; await _accountService.UpdateAsync(user); return(RedirectToAction($"{nameof(UserProfile)}")); }
public ActionResult UsersProfile(ProfileViewModels model) { string patternText = @"(^[\w\s-+_.,;:?()]*$)"; string patternPhone = @"(\+?[0-9]{3}-*[0-9]{2}-*[0-9]{3}-*[0-9]{2}-*[0-9]{2})"; //string patternEmail = @"(^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,4})$)"; var id = User.Identity.GetUserId(); if (!string.IsNullOrEmpty(id)) { model.UserId = id; } var user = context.Users.FirstOrDefault(u => u.Id == id); var empl = context.Employee.FirstOrDefault(u => u.UserId == id); model.Email = model.Email; model.PhoneNumber = Regex.Match(model.PhoneNumber, patternText).Value; model.EmailConfirmed = user.EmailConfirmed; if (model.Birthday == new DateTime()) { model.Birthday = DateTime.Today.AddYears(-100); } if (user.EmailConfirmed && empl != null) { empl.Birthday = model.Birthday; empl.Name = model.Name; empl.Patronymic = model.Patronymic; empl.Surname = model.Surname; empl.Nickname = model.Nickname; empl.Introduction = model.Introduction; empl.Description = model.Description; model.TwoFactorEnabled = user.TwoFactorEnabled; model.PhoneNumberConfirmed = user.PhoneNumberConfirmed; } verificationOfUserData(model, patternText, patternPhone); if (ModelState.IsValid) { context.SaveChanges(); TempData["Message"] = string.Format($"Changes saved."); } else { //return RedirectToAction("UsersProfile", model); return(View(model)); } return(RedirectToAction("UsersProfile")); }
public async Task <IActionResult> Index(bool?success) { if (success != null && success.HasValue && success.Value) { ViewBag.ChangePassSuccessfull = true; } if (success != null && success.HasValue && !success.Value) { ViewBag.PasswordIsNotCorrect = true; } ViewBag.ActiveMenu = "profile"; ProfileViewModels profile = null; if (current_UserID <= 0) { return(RedirectToAction("Signin", "Login")); } else if (current_ApplianceId <= 0) { return(RedirectToAction("Index", "Setup")); } else { string url = _appSettings.ApiUrl + "/Profile/GetProfile"; client.BaseAddress = new Uri(url); HttpResponseMessage responseMessage = await client.GetAsync(url + "?accountid=" + current_UserID); var responseData = new ResponseData <Account>(); if (responseMessage.IsSuccessStatusCode) { responseData = responseMessage.Content.ReadAsAsync <ResponseData <Account> >().Result; if (responseData != null && responseData.Data != null) { profile = new ProfileViewModels { EmailAddress = responseData.Data.Email, FirstName = responseData.Data.FirstName, LastName = responseData.Data.LastName, PhoneNumber = responseData.Data.PhoneNumber }; } } } return(View(profile)); }
public ActionResult ProfilePage() { ViewBag.imgExist = false; ProfileViewModels model = new ProfileViewModels(); ApplicationDbContext context = new ApplicationDbContext(); var getcurrentUsername = HttpContext.User.Identity.Name; var user = context.Users.Include(c => c.SchoolDetails).Include(d => d.NyscDetails).Include(p => p.PostedImageTable) .Where(m => m.UserName == getcurrentUsername).FirstOrDefault(); if (user.SchoolDetails == null && user.NyscDetails == null && user.PostedImageTable == null) { return(Redirect("/Dashboard/EditProfile")); } else { model.Address = user.Address; model.Name = user.Name; model.Username = user.UserName; model.Age = user.Age; if (user.SchoolDetails != null && user.NyscDetails != null && user.PostedImageTable != null) { foreach (var i in user.SchoolDetails) { model.Department = i.Department; model.Faculty = i.Faculty; model.University = i.University; } foreach (var c in user.NyscDetails) { model.RegDate = c.RegDate; model.StateChoice1 = c.StateChoice1; model.StateChoice2 = c.StateChoice2; model.StateChoice3 = c.StateChoice3; model.DeployDate = c.DeployDate; } foreach (var img in user.PostedImageTable) { model.ImgId = img.Id.ToString(); } ViewBag.imgExist = true; } return(View(model)); } }
public async Task <ActionResult> EditProfile() { ViewBag.imgExist = false; ProfileViewModels model = new ProfileViewModels(); ApplicationDbContext context = new ApplicationDbContext(); var currentUsername = HttpContext.User.Identity.Name; var user = await context.Users.Include(c => c.SchoolDetails).Include(d => d.NyscDetails) .Where(m => m.UserName == currentUsername).FirstOrDefaultAsync(); model.Address = user.Address; model.Name = user.Name; model.Username = user.UserName; model.Age = user.Age; if (user.SchoolDetails != null && user.PostedImageTable != null && user.NyscDetails != null) { foreach (SchoolDetails s in user.SchoolDetails) { model.Department = s.Department; model.Faculty = s.Faculty; model.University = s.University; } foreach (var img in user.PostedImageTable) { model.ImgId = img.Id.ToString(); ViewBag.imgExist = true; } foreach (NyscDetails c in user.NyscDetails) { model.RegDate = c.RegDate; model.StateChoice1 = c.StateChoice1; model.StateChoice2 = c.StateChoice2; model.StateChoice3 = c.StateChoice3; model.DeployDate = c.DeployDate; } } return(View(model)); }
public ActionResult Update(ProfileViewModels model) { //Vi kontrollerar att födelsedatumet ligger inom spannet 1900 till i år. if (model.BirthDate.Year < 1900 || model.BirthDate.Year > DateTime.Now.Year) { ModelState.AddModelError("BirthDate", "Date not valid"); return(View(model)); } var profileContext = new ProfileDbContext(); var userId = User.Identity.GetUserId(); var currentProfile = profileContext.Profiles.FirstOrDefault(p => p.UserID == userId); currentProfile.FirstName = model.FirstName; currentProfile.LastName = model.LastName; currentProfile.BirthDate = model.BirthDate; currentProfile.Description = model.Description; currentProfile.Location = model.Location; profileContext.SaveChanges(); return(RedirectToAction("ShowProfile", "Profile", new { showID = userId })); }
public ActionResult Edit(ProfileViewModels.EditModel model) { return this.View(model); }
public async Task <ActionResult> EditProfile(ProfileViewModels model, HttpPostedFileBase img) { ViewBag.imgExist = false; string imgId = string.Empty; ApplicationDbContext context = new ApplicationDbContext(); var currentUsername = HttpContext.User.Identity.Name; var user = await context.Users .Where(m => m.UserName == currentUsername).FirstOrDefaultAsync(); user.Address = model.Address; user.Name = model.Name; user.UserName = model.Username; user.Age = model.Age; //if an image already exist for the user then just update the image if (user.PostedImageTable == null) { if (img != null) { imgId = await this.saveImage.SaveImageAsync(img, user.Id); model.ImgId = imgId; ViewBag.imgExist = true; } else { ViewBag.imgExist = false; } } else { if (img != null) { imgId = await this.saveImage.UpdateImageAsync(img, user.Id); model.ImgId = imgId; ViewBag.imgExist = true; } else { ViewBag.imgExist = false; } } if (user.SchoolDetails == null) { user.SchoolDetails.Add(new SchoolDetails { Department = model.Department, Faculty = model.Faculty, University = model.University }); user.NyscDetails.Add(new NyscDetails { RegDate = model.RegDate, StateChoice1 = model.StateChoice1, StateChoice2 = model.StateChoice2, StateChoice3 = model.StateChoice3, DeployDate = model.DeployDate }); ViewBag.result = "user created"; } else { foreach (var s in user.SchoolDetails) { s.Department = model.Department; s.Faculty = model.Faculty; s.University = model.University; } foreach (var n in user.NyscDetails) { n.RegDate = model.RegDate; n.StateChoice1 = model.StateChoice1; n.StateChoice2 = model.StateChoice2; n.StateChoice3 = model.StateChoice3; n.DeployDate = model.DeployDate; } ViewBag.result = "update successful"; } await context.SaveChangesAsync(); return(View(model)); }
bool verificationOfUserData(ProfileViewModels model, string patternText, string patternPhone) { //string patternEmail = @"(^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,4})$)"; bool result = true; if (model.Name != null && (!Regex.IsMatch(model.Name, patternText) //|| Regex.Matches(model.Name, patternText).Count < 2) //|| Regex.Matches(model.Name, patternText).Count > 2 )) { ModelState.AddModelError("Name", "Field \"Name\" must include only letter, number and symbols: \"-+_.,;:?()\""); result = result && false; } if (model.Patronymic != null && Regex.Matches(model.Patronymic, patternText).Count != 2) { ModelState.AddModelError("Patronymic", "Field \"Patronymic\" must include only letter, number and symbols: \"-+_.,;:?()\""); result = result && false; } if (model.Surname != null && Regex.Matches(model.Surname, patternText).Count != 2) { ModelState.AddModelError("Surname", "Field \"Surname\" must include only letter, number and symbols: \"-+_.,;:?()\""); result = result && false; } if (model.Nickname != null && Regex.Matches(model.Nickname, patternText).Count != 2) { ModelState.AddModelError("Nickname", "Field \"Nickname\" must include only letter, number and symbols: \"-+_.,;:?()\""); result = result && false; } if (model.Introduction != null && Regex.Matches(model.Introduction, patternText).Count != 2) { ModelState.AddModelError("Introduction", "Field \"Introduction\" must include only letter, number and symbols: \"-+_.,;:?()\""); result = result && false; } if (model.Description != null && Regex.Matches(model.Description, patternText).Count != 2) { ModelState.AddModelError("Description", "Field \"Description\" must include only letter, number and symbols: \"-+_.,;:?()\""); result = result && false; } //if (model.Email != null // && !Regex.IsMatch(model.Email, patternEmail, RegexOptions.IgnoreCase)) //{ // ModelState.AddModelError("Email", ""); // result = result && false; //} if (model.PhoneNumber != null && !Regex.IsMatch(model.PhoneNumber, patternPhone, RegexOptions.IgnoreCase)) { ModelState.AddModelError("PhoneNumber", "Not correct phone number"); result = result && false; } if (model.UserId != null && !Regex.IsMatch(model.UserId, patternPhone, RegexOptions.IgnoreCase)) { ModelState.AddModelError("UserId", "User error!"); result = result && false; } if (model.Birthday > DateTime.Today.AddYears(-14) || model.Birthday < DateTime.Today.AddYears(-120) || model.Birthday != new DateTime()) { ModelState.AddModelError("Birthday", "Not correct birthday"); result = result && false; } return(result); }