public UtentePresenter(UserProfileView userProfileView, Sessione sessione) { _userProfileView = userProfileView; _userProfileView.Dock = DockStyle.Fill; _sessione = sessione; _sessione.SessionChanged += Sessione_Changed; }
public ActionResult SignUp(UserProfileView USV) { if (ModelState.IsValid) { UserManager UM = new UserManager(); if (!UM.IsLoginNameExist(USV.LoginName)) { UM.AddUserAccount(USV); FormsAuthentication.SetAuthCookie(USV.FirstName, false); return(RedirectToAction("Welcome", "Home")); } else { ModelState.AddModelError("", "Login Name already taken."); } } return(View()); }
public ActionResult UpdateUserData(int userID, string loginName, string password, string firstName, string lastName, string gender, int roleID = 0) { UserProfileView UPV = new UserProfileView(); UPV.SYSUserID = userID; UPV.LoginName = loginName; UPV.Password = password; UPV.FirstName = firstName; UPV.LastName = lastName; UPV.Gender = gender; if (roleID > 0) { UPV.LOOKUPRoleID = roleID; } UserManager UM = new UserManager(); UM.UpdateUserAccount(UPV); return(Json(new { success = true })); }
public IActionResult ProfileUpdate([FromBody] UserProfileView model) { if (!ModelState.IsValid) { return(BadRequest("Bad Model")); } string userName; try { userName = User.Claims.FirstOrDefault(x => x.Type == "name").Value; } catch (Exception) { return(BadRequest("Потрібно спочатку залогінитися!")); } if (string.IsNullOrEmpty(userName)) { return(BadRequest("Потрібно спочатку залогінитися!")); } var query = _context.Users.Include(x => x.UserProfile).AsQueryable(); var user = query.FirstOrDefault(c => c.UserName == userName); if (user == null) { return(BadRequest("Поганий запит!")); } user.UserProfile.Name = model.Name; user.UserProfile.Surname = model.Surname; user.UserProfile.DateOfBirth = model.DateOfBirth; user.UserProfile.Phone = model.Phone; user.PhoneNumber = model.Phone; user.UserName = model.Email; user.Email = model.Email; _context.SaveChanges(); var result = new UserProfileView(user); return(Ok(result)); }
public IActionResult Index() { UserProfileView userProfile = new UserProfileView(); LoginInfo info = HttpContext.Session.GetObject <LoginInfo>("Info"); if (info == null) { return(Redirect("/")); } switch (info.position) { case "kh": { userProfile = _ctx.Customer.Where(p => p.CustomerId == info.UserID).Select(p => new UserProfileView { UserID = p.CustomerId, FirstName = p.FirstName, LastName = p.LastName, Address = p.Address, Phone = p.Phone, Email = p.Email }).SingleOrDefault(); userProfile.orders = list; break; } case "nv": { userProfile = _ctx.Employee.Where(p => p.EmployeeId == info.UserID).Select(p => new UserProfileView { UserID = p.EmployeeId, FirstName = p.FirstName, LastName = p.LastName, Address = p.Address, Phone = p.Phone, Email = p.Email }).SingleOrDefault(); userProfile.orders = list; break; } } return(View(userProfile)); }
public List <UserProfileView> GetAllUserProfiles() { List <UserProfileView> profiles = new List <UserProfileView>(); using (DB_A11531_francistestEntities db = new DB_A11531_francistestEntities()) { UserProfileView UPV; var users = db.SYSUsers.ToList(); foreach (SYSUser u in db.SYSUsers) { UPV = new UserProfileView(); UPV.SYSUserID = u.SYSUserID; UPV.LoginName = u.LoginName; UPV.Password = u.PasswordEncryptedText; var SUP = db.SYSUserProfiles.Find(u.SYSUserID); if (SUP != null) { UPV.FirstName = SUP.FirstName; UPV.LastName = SUP.LastName; UPV.Gender = SUP.Gender; UPV.DateOfBirth = SUP.DateOfBirth; UPV.BronzeBalance = SUP.BronzeBalance; UPV.SilverBalance = SUP.SilverBalance; UPV.GoldBalance = SUP.GoldBalance; } var SUR = db.SYSUserRoles.Where(o => o.SYSUserID.Equals(u.SYSUserID)); if (SUR.Any()) { var userRole = SUR.FirstOrDefault(); UPV.LOOKUPRoleID = userRole.LOOKUPRoleID; UPV.RoleName = userRole.LOOKUPRole.RoleName; UPV.IsRoleActive = userRole.IsActive; } profiles.Add(UPV); } } return(profiles); }
private UserProfileView GetViewProfile(int id) { user user = UserContext.GetUser(id); if (user == null) { return(null); } UserProfileView model = new UserProfileView(); model.Id = user.user_id; model.avatarURL = user.avatarURL; model.dateOfBirdth = string.Empty; model.username = user.username; model.address = user.address; model.fullName = user.firstName + " " + user.middleName + " " + user.lastName; return(model); }
public List <UserProfileView> GetAllUserProfiles() { List <UserProfileView> profiles = new List <UserProfileView>(); using (BonesAndFlowersDBEntities db = new BonesAndFlowersDBEntities()) { UserProfileView UPV; var users = db.SYSUsers.ToList(); foreach (SYSUser u in db.SYSUsers) { UPV = new UserProfileView { SYSUserID = u.SYSUserID, UserName = u.UserName, Password = u.PasswordEncryptedText }; //if (db.SYSUserProfiles != null) var SUP = db.SYSUserProfiles.Find(u.SYSUserID); if (SUP != null) { UPV.Race = SUP.Race; UPV.Class = SUP.Class; UPV.Country = SUP.Country; UPV.Gender = SUP.Gender; } var SUR = db.SYSUserRoles.Where(o => o.SYSUserID.Equals(u.SYSUserID)); if (SUR.Any()) { var userRole = SUR.FirstOrDefault(); UPV.LOOKUPRoleID = userRole.LOOKUPRoleID; UPV.RoleName = userRole.LOOKUPRole.RoleName; UPV.IsRoleActive = userRole.IsActive; } profiles.Add(UPV); } } return(profiles); }
public UserProfileView GetUserProfile(int userID) { UserProfileView UPV = new UserProfileView(); using (DemoDBEntities db = new DemoDBEntities()) { var user = db.SYSUsers.Find(userID); if (user != null) { UPV.SYSUserID = user.SYSUserID; UPV.LoginName = user.LoginName; UPV.Password = user.PasswordEncryptedText; var SUP = db.SYSUserProfiles.Find(userID); if (SUP != null) { UPV.FirstName = SUP.FirstName; UPV.LastName = SUP.LastName; UPV.Gender = SUP.Gender; } var SUR = db.SYSUserRoles.Find(userID); if (SUR != null) { UPV.LOOKUPRoleID = SUR.LOOKUPRoleID; UPV.RoleName = SUR.LOOKUPRole.RoleName; UPV.IsRoleActive = SUR.IsActive; } } } return(UPV); }
public void fillGridfromSession() { DataTable UserProfilesTable = new DataTable(); if (Session["UserProfilesNameTable"] != "" && Session["UserProfilesNameTable"] != null) { UserProfilesTable = (DataTable)Session["UserProfilesNameTable"]; } try { UserProfileView.DataSource = UserProfilesTable; UserProfileView.DataBind(); } catch (Exception ex) { Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Exception - " + ex); throw ex; } }
public ActionResult UpdateUserData(int userID, string loginName, string password, string firstName, string lastName, string gender, DateTime?dateOfBirth, int?bbal, int?sbal, int?gbal, int roleID = 0) { UserProfileView UPV = new UserProfileView(); UPV.SYSUserID = userID; UPV.LoginName = loginName; UPV.Password = password; UPV.FirstName = firstName; UPV.LastName = lastName; UPV.Gender = gender; if (dateOfBirth != null) { UPV.DateOfBirth = dateOfBirth; } if (bbal == null) { bbal = 0; } if (sbal == null) { sbal = 0; } if (gbal == null) { gbal = 0; } UPV.BronzeBalance = bbal; UPV.SilverBalance = sbal; UPV.GoldBalance = gbal; if (roleID > 0) { UPV.LOOKUPRoleID = roleID; } UserManager UM = new UserManager(); UM.UpdateUserAccount(UPV); return(Json(new { success = true })); }
public List <UserProfileView> GetAllUserProfiles() { List <UserProfileView> profiles = new List <UserProfileView>(); using (SchedulerEntities db = new SchedulerEntities()) { UserProfileView UPV; var users = db.SYSUsers.ToList(); foreach (SYSUser u in db.SYSUsers) { UPV = new UserProfileView(); UPV.SYSUserID = u.SYSUserID; UPV.LoginName = u.LoginName; UPV.Password = u.PasswordEncryptedText; var SUP = db.SYSUserProfiles.Find(u.SYSUserID); if (SUP != null) { UPV.FirstName = SUP.FirstName; UPV.LastName = SUP.LastName; UPV.Gender = SUP.Gender; UPV.UserTypeID = SUP.UserTypeID == null ? 0 : (int)SUP.UserTypeID; } var SUR = db.SYSUserRoles.Where(o => o.SYSUserID.Equals(u.SYSUserID)); if (SUR.Any()) { var userRole = SUR.FirstOrDefault(); UPV.LOOKUPRoleID = userRole.LOOKUPRoleID; UPV.RoleName = userRole.LOOKUPRole.RoleName; UPV.IsRoleActive = userRole.IsActive; } profiles.Add(UPV); } } return(profiles); }
public UserProfileView GetUserProfile(int userID) { UserProfileView UPV = new UserProfileView(); using (praEntities db = new praEntities()) { var user = db.SYSUsers.Find(userID); if (user != null) { UPV.SYSUserID = user.SYSUserID; UPV.LoginName = user.LoginName; UPV.Password = user.PasswordEncryptedText; var SUP = db.SYSUserProfiles.Find(userID); if (SUP != null) { UPV.FirstName = SUP.FirstName; UPV.LastName = SUP.LastName; UPV.Gender = SUP.Gender; UPV.Activity = SUP.Aktivnost; UPV.Dateofbirth = (DateTime)SUP.DatumRodenja; UPV.Visina = (int)SUP.Visina; UPV.Tezina = (int)SUP.Tezina; UPV.Diabetes = SUP.Tip; UPV.Email = SUP.Email; } var SUR = db.SYSUserRoles.Find(userID); if (SUR != null) { UPV.LOOKUPRoleID = SUR.LOOKUPRoleID; UPV.RoleName = SUR.LOOKUPRole.RoleName; UPV.IsRoleActive = SUR.IsActive; } } } return(UPV); }
public ActionResult UpdateUserData(int userId, string loginName, string password, string firstName, string lastName, string gender, int roleId = 0) { var upv = new UserProfileView { SYSUserID = userId, LoginName = loginName, Password = password, FirstName = firstName, LastName = lastName, Gender = gender }; if (roleId > 0) { upv.LOOKUPRoleID = roleId; } var um = new UserManager(); um.UpdateUserAccount(upv); return(Json(new { success = true })); }
//[AuthorizeRoles("Admin")] public ActionResult UpdateUserData(int userID, string emailid, string password, string firstName, string lastName, string gender, int roleID = 0) { UserProfileView UPV = new UserProfileView(); UPV.UserId = userID; UPV.EmailAddress = emailid; UPV.FirstName = firstName; UPV.LastName = lastName; if (roleID > 0) { UPV.UserLookupRoleId = roleID; } UserManager UM = new UserManager(); UM.UpdateUserAccount(UPV); return(Json(new { success = true })); }
public List <UserProfileView> GetAllUserProfiles() { List <UserProfileView> profiles = new List <UserProfileView>(); using (PetrissEntities db = new PetrissEntities()) { UserProfileView UPV; var users = db.Users.ToList(); foreach (User u in db.Users) { UPV = new UserProfileView(); UPV.UserId = u.UserId; UPV.EmailAddress = u.EmailId; var _userprofile = db.UsersProfiles.Find(u.UserId); if (_userprofile != null) { UPV.FirstName = _userprofile.FirstName; UPV.LastName = _userprofile.LastName; UPV.PhoneNumber = _userprofile.PhoneNumber; } var SUR = db.UsersRoles.Where(o => o.UserId.Equals(u.UserId)); if (SUR.Any()) { var userRole = SUR.FirstOrDefault(); UPV.UserLookupRoleId = userRole.UserLookupRoleId; UPV.RoleName = userRole.UserLookupRole.RoleName; UPV.IsRoleActive = userRole.IsActive; } profiles.Add(UPV); } } return(profiles); }
public async Task UpdateUserPhotoTest() { // Set up initial stuff SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); PostUserResponse postUserResponse = await TestUtilities.DoLogin(client, "ü", "§", "╚"); string auth = AuthHelper.CreateSocialPlusAuth(postUserResponse.SessionToken); // Call Put User string photoURL = "myPics.org//Selfie.jpg"; PutUserPhotoRequest putUserPhotoRequest = new PutUserPhotoRequest(photoURL); await client.Users.PutUserPhotoAsync(putUserPhotoRequest, auth); // Call Get User UserProfileView getUserProfile = await client.Users.GetUserAsync(postUserResponse.UserHandle, auth); // Clean up first before verifying await client.Users.DeleteUserAsync(auth); // Verify changes ... also verify rest to make sure nothing else wiped out Assert.AreEqual("╚", getUserProfile.Bio); Assert.AreEqual("ü", getUserProfile.FirstName); Assert.AreEqual("§", getUserProfile.LastName); Assert.AreEqual(FollowerStatus.None, getUserProfile.FollowerStatus); Assert.AreEqual(FollowingStatus.None, getUserProfile.FollowingStatus); Assert.AreEqual(photoURL, getUserProfile.PhotoHandle); if (getUserProfile.PhotoUrl.Contains("images/" + photoURL) == false) { Assert.Fail("'images'" + photoURL + " should be contained in this: " + getUserProfile.PhotoUrl); } Assert.AreEqual(ProfileStatus.Active, getUserProfile.ProfileStatus); Assert.AreEqual(0, getUserProfile.TotalFollowers); Assert.AreEqual(0, getUserProfile.TotalFollowing); Assert.AreEqual(0, getUserProfile.TotalTopics); Assert.AreEqual(postUserResponse.UserHandle, getUserProfile.UserHandle); Assert.AreEqual(Visibility.Public, getUserProfile.Visibility); }
public List <UserProfileView> GetAllUserProfiles() { List <UserProfileView> profiles = new List <UserProfileView>(); using (DemoDBContext db = new DemoDBContext()) { UserProfileView UPV; var users = db.Sysuser.ToList(); foreach (Sysuser u in db.Sysuser) { UPV = new UserProfileView(); UPV.SYSUserID = u.SysuserId; UPV.LoginName = u.LoginName; UPV.Password = u.PasswordEncryptedText; var SUP = db.SysuserProfile.Find(u.SysuserId); if (SUP != null) { UPV.FirstName = SUP.FirstName; UPV.LastName = SUP.LastName; UPV.Gender = SUP.Gender; } var SUR = db.SysuserRole.Where(o => o.SysuserId.Equals(u.SysuserId)); if (SUR.Any()) { var userRole = SUR.FirstOrDefault(); UPV.LOOKUPRoleID = userRole.LookuproleId; UPV.RoleName = userRole.Lookuprole.RoleName; UPV.IsRoleActive = userRole.IsActive; } profiles.Add(UPV); } } return(profiles); }
public ActionResult UpdateUserData(int userID, string userName, string password, string userRace, string userClass, string userCountry, string userGender, int roleID = 0) { UserProfileView UPV = new UserProfileView(); UPV.SYSUserID = userID; UPV.UserName = userName; UPV.Password = password; UPV.Race = userRace; UPV.Class = userClass; UPV.Country = userCountry; UPV.Gender = userGender; if (roleID > 0) { UPV.LOOKUPRoleID = roleID; } UserManager UM = new UserManager(); UM.UpdateUserAccount(UPV); return(Json(new { success = true })); }
public UserProfileView getUserProfileByUsername(string Username) { var actual = _db.SingleOrDefault <PureUser>("where UserName=@0", Username); var userrRole = _db.SingleOrDefault <PureRole>("where RoleId=@0", actual.Roleid); UserProfileView userView = new UserProfileView() { FirstName = actual.Firstname, MiddleName = actual.Middlename, LastName = actual.Lastname, UserName = actual.Username, UserEmail = actual.Useremail, UserPWD = actual.Userpwd, RoleId = actual.Roleid, PhoneNos = actual.Phonenos, UserImg = actual.Userimg, RoleName = userrRole.Rolename, UserStatus = actual.Userstatus, CreatedBy = actual.Createdby, CreatedOn = actual.Createdon }; return(userView); }
public List <UserProfileView> GetAllUserProfiles() { List <UserProfileView> profiles = new List <UserProfileView>(); using (DemoDBEntities db = new DemoDBEntities()) { var users = db.SYSUsers.ToList(); foreach (var u in db.SYSUsers) { var upv = new UserProfileView { SYSUserID = u.SYSUserID, LoginName = u.LoginName, Password = u.PasswordEncryptedText }; var sup = db.SYSUserProfiles.Find(u.SYSUserID); if (sup != null) { upv.FirstName = sup.FirstName; upv.LastName = sup.LastName; upv.Gender = sup.Gender; } var sur = db.SYSUserRoles.Where(o => o.SYSUserID.Equals(u.SYSUserID)); if (sur.Any()) { var userRole = sur.FirstOrDefault(); upv.LOOKUPRoleID = userRole.LOOKUPRoleID; upv.RoleName = userRole.LOOKUPRole.RoleName; upv.IsRoleActive = userRole.IsActive; } profiles.Add(upv); } } return(profiles); }
public List <UserProfileView> GetAllUserProfiles() { List <UserProfileView> profiles = new List <UserProfileView>(); using (CMSProjectEntities db = new CMSProjectEntities()) { UserProfileView UPV; var users = db.Users.ToList(); foreach (User u in db.Users) { UPV = new UserProfileView(); UPV.UserID = u.UserID; UPV.Username = u.Username; UPV.Password = u.Password; var UP = db.UserProfiles.Where(o => o.UserID.Equals(UPV.UserID)).FirstOrDefault(); UPV.UserProfileID = UP.UserProfileID; UPV.FirstName = UP.FirstName; UPV.LastName = UP.LastName; UPV.Gender = UP.Gender; UPV.BirthDate = Convert.ToDateTime(UP.BirthDate).ToString("yyyy-MM-dd"); UPV.Mobile = UP.Mobile; UPV.Email = UP.Email; UPV.RoleID = UP.RoleID; var uRole = db.UserRoles.Where(o => o.RoleID.Equals(UPV.RoleID)).FirstOrDefault(); UPV.RoleName = uRole.RoleName; if (UPV.RoleName == "Employee") { profiles.Add(UPV); } } } return(profiles); }
public UserProfileView GetUserProfile(int userID) { UserProfileView UPV = new UserProfileView(); using (DB_A11531_francistestEntities db = new DB_A11531_francistestEntities()) { var user = db.SYSUsers.Find(userID); if (user != null) { UPV.SYSUserID = user.SYSUserID; UPV.LoginName = user.LoginName; UPV.Password = user.PasswordEncryptedText; var SUP = db.SYSUserProfiles.Find(userID); if (SUP != null) { UPV.FirstName = SUP.FirstName; UPV.LastName = SUP.LastName; UPV.Gender = SUP.Gender; UPV.DateOfBirth = SUP.DateOfBirth; UPV.BronzeBalance = SUP.BronzeBalance; UPV.SilverBalance = SUP.SilverBalance; UPV.GoldBalance = SUP.GoldBalance; } var SUR = db.SYSUserRoles.Find(userID); if (SUR != null) { UPV.LOOKUPRoleID = SUR.LOOKUPRoleID; UPV.RoleName = SUR.LOOKUPRole.RoleName; UPV.IsRoleActive = SUR.IsActive; } } } return(UPV); }
public ActionResult MyProfile() { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Authorization")); } int current_user_id = UserContext.GetUserId(User.Identity.Name); if (current_user_id == -1) { return(RedirectToAction("Login", "Authorization")); } UserProfileView model = GetViewProfile(current_user_id); if (model == null) { return(RedirectToAction("Index", "Home")); } ViewBag.Profile = CONST.PROFILE.MY_PROFILE; return(View(model)); }
public ActionResult ViewProfile() { //Show view profile if (UserHelpers.GetCurrentUser(Session) == null) { return(RedirectToAction("Index", "Home")); } // userId = UserHelpers.GetCurrentUser(Session).Id.ToString(); User user = UserContext.GetUser(UserHelpers.GetCurrentUser(Session).Id); if (user == null) { return(RedirectToAction("Index", "Home")); } UserProfileView model = new UserProfileView(); model.Id = user.Id; model.avatarURL = user.avatarURL; model.dateOfBirdth = string.Empty; model.username = user.username; model.address = user.address; model.fullName = user.firstName + " " + user.middleName + " " + user.lastName; return(View(model)); }
public List <UserProfileView> GetUserByName(string name) { List <UserProfileView> profiles = new List <UserProfileView>(); List <SYSUserProfile> users = new List <SYSUserProfile>(); using (mydbEntities db = new mydbEntities()) { var u1 = db.SYSUserProfiles.Where(o => o.FirstName.Contains(name)); if (u1.Any()) { users = u1.ToList(); foreach (SYSUserProfile p in users) { UserProfileView UPV = new UserProfileView(); UPV.FirstName = p.FirstName; UPV.LastName = p.LastName; profiles.Add(UPV); } } return(profiles); } }
public void UpdateUserAccount(UserProfileView user) { using (DemoDBEntities db = new DemoDBEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { SYSUser SU = db.SYSUsers.Find(user.SYSUserID); SU.LoginName = user.LoginName; SU.PasswordEncryptedText = user.Password; SU.RowCreatedSYSUserID = user.SYSUserID; SU.RowModifiedSYSUserID = user.SYSUserID; SU.RowCreatedDateTime = DateTime.Now; SU.RowMOdifiedDateTime = DateTime.Now; db.SaveChanges(); var userProfile = db.SYSUserProfiles.Where(o => o.SYSUserID == user.SYSUserID); if (userProfile.Any()) { SYSUserProfile SUP = userProfile.FirstOrDefault(); SUP.SYSUserID = SU.SYSUserID; SUP.FirstName = user.FirstName; SUP.LastName = user.LastName; SUP.Gender = user.Gender; SUP.RowCreatedSYSUserID = user.SYSUserID; SUP.RowModifiedSYSUserID = user.SYSUserID; SUP.RowCreatedDateTime = DateTime.Now; SUP.RowModifiedDateTime = DateTime.Now; db.SaveChanges(); } if (user.LOOKUPRoleID > 0) { var userRole = db.SYSUserRoles.Where(o => o.SYSUserID == user.SYSUserID); SYSUserRole SUR = null; if (userRole.Any()) { SUR = userRole.FirstOrDefault(); SUR.LOOKUPRoleID = user.LOOKUPRoleID; SUR.SYSUserID = user.SYSUserID; SUR.IsActive = true; SUR.RowCreatedSYSUserID = user.SYSUserID; SUR.RowModifiedSYSUserID = user.SYSUserID; SUR.RowCreatedDateTime = DateTime.Now; SUR.RowModifiedDateTime = DateTime.Now; } else { SUR = new SYSUserRole(); SUR.LOOKUPRoleID = user.LOOKUPRoleID; SUR.SYSUserID = user.SYSUserID; SUR.IsActive = true; SUR.RowCreatedSYSUserID = user.SYSUserID; SUR.RowModifiedSYSUserID = user.SYSUserID; SUR.RowCreatedDateTime = DateTime.Now; SUR.RowModifiedDateTime = DateTime.Now; db.SYSUserRoles.Add(SUR); } db.SaveChanges(); } dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); } } } }
//This method takes a UserProfileView object as the parameter. //This parameter is coming from a stringly-typed View. //It first issies a query to the database using the LINQ syntax //to get the specific user data by passing the SYSUserID //It then updates the SYSUser object with the corresponding data from the UserProfileView object. public void UpdateUserAccount(UserProfileView user) { using (DemoDBEntities db = new DemoDBEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { SYSUser SU = db.SYSUsers.Find(user.SYSUserID); SU.LoginName = user.LoginName; SU.PasswordEncryptedText = user.Password; SU.RowCreatedSYSUserID = user.SYSUserID; SU.RowModifiedSYSUserID = user.SYSUserID; SU.RowCreatedDateTime = DateTime.Now; SU.RowModifiedDateTime = DateTime.Now; db.SaveChanges(); //This query gets the associated SYSUserProfiles data and then updates the corresponding //values. After that, it then looks for the associated LOOKUPRoleID for a certain user. //If the user does not have role assigned to it, then it adds a //new record to the database, otherwise just update the table. var userProfile = db.SYSUserProfiles.Where(o => o.SYSUserID == user.SYSUserID); if (userProfile.Any()) { SYSUserProfile SUP = userProfile.FirstOrDefault(); SUP.SYSUserID = SU.SYSUserID; SUP.FirstName = user.FirstName; SUP.LastName = user.LastName; SUP.Gender = user.Gender; SUP.RowCreatedSYSUserID = user.SYSUserID; SUP.RowModifiedSYSUserID = user.SYSUserID; SUP.RowCreatedDateTime = DateTime.Now; SUP.RowModifiedDateTime = DateTime.Now; db.SaveChanges(); } if (user.LOOKUPRoleID > 0) { var userRole = db.SYSUserRoles.Where(o => o.SYSUserID == user.SYSUserID); SYSUserRole SUR = null; if (userRole.Any()) { SUR = userRole.FirstOrDefault(); SUR.LOOKUPRoleID = user.LOOKUPRoleID; SUR.SYSUserID = user.SYSUserID; SUR.IsActive = true; SUR.RowCreatedSYSUserID = user.SYSUserID; SUR.RowModifiedSYSUserID = user.SYSUserID; SUR.RowCreatedDateTime = DateTime.Now; SUR.RowModifiedDateTime = DateTime.Now; } else { SUR = new SYSUserRole(); SUR.LOOKUPRoleID = user.LOOKUPRoleID; SUR.SYSUserID = user.SYSUserID; SUR.IsActive = true; SUR.RowCreatedSYSUserID = user.SYSUserID; SUR.RowModifiedSYSUserID = user.SYSUserID; SUR.RowCreatedDateTime = DateTime.Now; SUR.RowModifiedDateTime = DateTime.Now; db.SYSUserRoles.Add(SUR); } db.SaveChanges(); } //We used a simple transaction within this method. //This is because the tables SYSUser, SYSUserProfile and SYSUserRole have //dependencies to each other, and we need to make sure that we only //commit changes to the database if the operation for each table //is successful. //The Database.BeginTransaction() is only available in EF 6 onwards dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); } } } }
/// <summary> /// Author : Girish Sonawane /// Created Date : 24-June-2019 /// Description : To UpdateUserProfile /// </summary> /// <returns></returns> public bool UpdateUserProfile(UserProfileView userProfileView) { return(_userRepository.UpdateUserProfile(userProfileView)); }
public ActionResult EditProfile() { string loginName = User.Identity.Name; UserManager UM = new UserManager(); UserProfileView UPV = UM.GetUserProfile(UM.GetUserID(loginName)); return(View(UPV)); }
public IActionResult UpdateInfo(UserProfileView profile, string NameImage) { //Lấy session để biết người này là employee hay customer var cus = HttpContext.Session.GetObject <Customer>("Customer"); var emp = HttpContext.Session.GetObject <Employee>("Employee"); if (cus != null) { if (!string.IsNullOrEmpty(NameImage)) { MoveImage(NameImage);//Move Image and delete OldImage } var customer = _ctx.Customer.SingleOrDefault(p => p.CustomerId == cus.CustomerId); customer.FirstName = profile.FirstName; customer.LastName = profile.LastName; customer.Address = profile.Address; customer.Email = profile.Email; customer.Sex = profile.Sex; customer.PhoneNumber = profile.Phone; customer.PhoneNumberConfirmed = profile.PhoneNumberConfirmed; if (!string.IsNullOrEmpty(NameImage)) { customer.Image = NameImage; } //Update SQL _ctx.Customer.Update(customer); _ctx.SaveChanges(); var claims = new List <Claim> { new Claim(ClaimTypes.Name, customer.FirstName + " " + customer.LastName), new Claim(ClaimTypes.Role, "Customer") }; ClaimsIdentity claimsIdentity = new ClaimsIdentity(claims, "Customer"); ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(claimsIdentity); HttpContext.SignInAsync("Customer", claimsPrincipal); //Update Session HttpContext.Session.SetObject <Customer>("Customer", customer); } else { if (!string.IsNullOrEmpty(NameImage)) { MoveImage(NameImage);//Move Image and delete OldImage } var employee = _ctx.Employee.SingleOrDefault(p => p.EmployeeId == emp.EmployeeId); employee.FirstName = profile.FirstName; employee.LastName = profile.LastName; employee.Address = profile.Address; employee.IdentityCardNumber = profile.IdentityCardNumber; employee.BirthDate = profile.BirthDate; employee.Email = profile.Email; employee.Sex = profile.Sex; employee.Phone = profile.Phone; if (!string.IsNullOrEmpty(NameImage)) { employee.Image = NameImage; } //Update SQL _ctx.Employee.Update(employee); _ctx.SaveChanges(); //Update Session HttpContext.Session.SetObject <Employee>("Employee", employee); // var claims = new List <Claim> { new Claim(ClaimTypes.Name, employee.FirstName + " " + employee.LastName), new Claim(ClaimTypes.Role, employee.Role.ToString()) }; ClaimsIdentity claimsIdentity = new ClaimsIdentity(claims, "Admin"); ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(claimsIdentity); HttpContext.SignInAsync("Admin", claimsPrincipal); } return(this.Ok()); }
private void CreateProfilePage() { Guid parentPageID = new Guid(SampleConstants.InternalResourcesGroupPageId); var hasCreatedPage = SampleUtilities.CreateLocalizedPage(new Guid(SampleConstants.ProfilePageId), "Profile", parentPageID, false, false, "en"); if (hasCreatedPage) { SampleUtilities.SetTemplateToLocalizedPage(new Guid(SampleConstants.ProfilePageId), new Guid(SampleConstants.EducationTemplateId), "en"); ContentBlockBase pageTitle = new ContentBlockBase(); pageTitle.Html = "<h1>Your Profile</h1>"; SampleUtilities.AddControlToLocalizedPage(new Guid(SampleConstants.ProfilePageId), pageTitle, "content", "Content block", "en"); UserProfileView profile = new UserProfileView(); SampleUtilities.AddControlToLocalizedPage(new Guid(SampleConstants.ProfilePageId), profile, "content", "Profile", "en"); } hasCreatedPage = SampleUtilities.CreateLocalizedPage(new Guid(SampleConstants.ProfilePageId), "Profil", parentPageID, false, false, "de"); if (hasCreatedPage) { SampleUtilities.SetTemplateToLocalizedPage(new Guid(SampleConstants.ProfilePageId), new Guid(SampleConstants.EducationTemplateId), "de"); ContentBlockBase pageTitle = new ContentBlockBase(); pageTitle.Html = "<h1>Ihr Profil</h1>"; SampleUtilities.AddControlToLocalizedPage(new Guid(SampleConstants.ProfilePageId), pageTitle, "content", "Content block", "de"); UserProfileView profile = new UserProfileView(); SampleUtilities.AddControlToLocalizedPage(new Guid(SampleConstants.ProfilePageId), profile, "content", "Profil", "de"); } }