public ActionResult ManageProfile(ManageProfileModel model) { using (var ctxt = new UsersContext()) { var userProfile = ctxt.UserProfiles.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); if (ModelState.IsValid) { try { userProfile.DisplayName = model.DisplayName; userProfile.Email = model.Email; userProfile.HasEmailReminder = model.HasEmailReminder; ctxt.SaveChanges(); ViewBag.StatusMessage = "User data successfully changed."; } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } return(View(model)); } }
public ActionResult Profile() { var manageProfile = new ManageProfileModel(); manageProfile.CurrentUser = _readOnlyRepository.FirstOrDefault <AccountLogin>(z => z.Email == HttpContext.User.Identity.Name); return(View(manageProfile)); }
public ActionResult Profile(ManageProfileModel model) { model.CurrentUser = _readOnlyRepository.FirstOrDefault <AccountLogin>(z => z.Email == HttpContext.User.Identity.Name); if (ModelState.IsValid) { if (model.CurrentUser.Name != model.Name || model.Name.Trim() == "") { model.CurrentUser.Name = model.Name; } if (model.CurrentUser.UserInfo.Blog != model.Blog || model.Blog.Trim() == "") { model.CurrentUser.UserInfo.Blog = model.Blog; } if (model.CurrentUser.UserInfo.Cellphone != model.Cellphone || model.Cellphone.Trim() == "") { model.CurrentUser.UserInfo.Cellphone = model.Cellphone; } if (model.CurrentUser.UserInfo.OfficePhone != model.OfficePhone || model.OfficePhone.Trim() == "") { model.CurrentUser.UserInfo.OfficePhone = model.OfficePhone; } if (model.CurrentUser.UserInfo.Cellphone != model.Description || model.Description.Trim() == "") { model.CurrentUser.UserInfo.Description = model.Description; } model.CurrentUser.UserInfo.Country = model.Country; if (model.CurrentUser.UserInfo.Gender != model.Gender) { model.CurrentUser.UserInfo.Gender = model.Gender; } if (model.CurrentUser.UserInfo.ProfileImg != model.ProfileImg || model.ProfileImg.Trim() == "") { model.CurrentUser.UserInfo.ProfileImg = model.ProfileImg; } _writeOnlyRepository.Update(model.CurrentUser); } ModelState.AddModelError("", "Something went wrong."); return(View(model)); }
public ActionResult ManageProfile() { using (var userCtxt = new UsersContext()) { var p = (from u in userCtxt.UserProfiles where u.UserName == User.Identity.Name select u) .FirstOrDefault(); var m = new ManageProfileModel() { DisplayName = p.DisplayName, Email = p.Email, HasEmailReminder = p.HasEmailReminder.HasValue ? true : false }; return(View(m)); } }
public IActionResult Manage() { if (HttpContext.User.Identities.Any(u => u.IsAuthenticated)) { Member m = _context.Member.FirstOrDefault(temp => temp.Phone == HttpContext.User.Identity.Name); ManageProfileModel model = new ManageProfileModel(); model.Bio = m.Bio; model.Email = m.Email; model.FullName = m.FullName; model.Image = m.Image; model.Name = m.Name; model.Newsletter = m.Newsletter; model.Phone = m.Phone; return(View(model)); } else { return(RedirectToAction("login")); } }
public IActionResult Manage(ManageProfileModel model) { try { if (model.Image != null) { var imageName = string.Format("{0}.jpg", Guid.NewGuid()); string base64 = model.Image.Split(',')[1]; byte[] bytes = Convert.FromBase64String(base64); using (Image image = Image.FromStream(new MemoryStream(bytes))) { var path = Path.Combine(Directory.GetCurrentDirectory(), @IdeaTree.Utility.ProfileImagePath, imageName); image.Save(path, ImageFormat.Jpeg); model.Image = imageName; } } Member m = _context.Member.FirstOrDefault(temp => temp.Phone == HttpContext.User.Identity.Name); m.Bio = model.Bio; m.Email = model.Email; m.FullName = model.FullName; m.Image = model.Image; m.Newsletter = model.Newsletter; _context.Attach(m).State = EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("Profile", new { name = m.Name })); } catch (Exception ex) { ModelState.AddModelError("Error", "We facing a technical issue, please try after some time."); Utility.ReportException(ex.Message, "Error in Home/Manage."); return(View(model)); } }