private void ExcuteGetNewPassword() { SelectedUser.TempPassword = new Random().Next(123456, 134567).ToString(); if (SelectedUser.UserId != 0) { var userName = SelectedUser.UserName; var token = WebSecurity.GeneratePasswordResetToken(userName); WebSecurity.ResetPassword(token, SelectedUser.TempPassword); using (var dbCon = new ServerDbContextFactory().Create()) { var usr = dbCon.Set <UserDTO>().FirstOrDefault(u => u.UserId == SelectedUser.UserId); if (usr != null) { usr.TempPassword = SelectedUser.TempPassword; dbCon.Set <UserDTO>().Add(usr); dbCon.Entry(usr).State = EntityState.Modified; dbCon.SaveChanges(); } } } }
public ServerAgentViewModel() { CleanUp(); var iDbContext = new ServerDbContextFactory().Create(); _unitOfWork = new UnitOfWorkServer(iDbContext); SelectedAgent = new AgentDTO(); Agents = new ObservableCollection <AgentDTO>(); GetLiveAgents(); EditCommandVisibility = false; }
public ServerProductActivationViewModel() { CleanUp(); var iDbContext = new ServerDbContextFactory().Create(); _unitOfWork = new UnitOfWorkServer(iDbContext); SelectedProductActivation = new ProductActivationDTO(); ProductActivations = new ObservableCollection <ProductActivationDTO>(); GetLiveProductActivations(); EditCommandVisibility = false; }
public ServerSettingViewModel() { CleanUp(); var iDbContext = new ServerDbContextFactory().Create(); _unitOfWork = new UnitOfWorkServer(iDbContext); SelectedSetting = new SettingDTO(); Settings = new ObservableCollection <SettingDTO>(); GetLiveSettings(); EditCommandVisibility = false; }
public UserAgencyAgentViewModel() { CleanUp(); var iDbContext = new ServerDbContextFactory().Create(); _unitOfWork = new UnitOfWorkServer(iDbContext); Load(); Messenger.Default.Register <UserDTO>(this, message => { SelectedUser = message; }); }
public ServerUserViewModel() { CleanUp(); var iDbContext = new ServerDbContextFactory().Create(); _unitOfWork = new UnitOfWorkServer(iDbContext); _userService = new UserService(iDbContext); Load(); SelectedUser = new UserDTO(); SelectedRole = new RoleDTO(); SelectedRoleToAdd = new RoleDTO(); Users = new ObservableCollection <UserDTO>(); Roles = new ObservableCollection <RoleDTO>(); SelectedRoles = new ObservableCollection <RoleDTO>(); FilteredRoles = new ObservableCollection <RoleDTO>(); GetLiveRoles(); GetLiveUsers(); EditCommandVisibility = false; NewPasswordExpandibility = false; //#region Web Security //const string serverName = "."; //const string sqlceFileName = "PinnaFaceDbWeb"; //const string sQlServConString = "data source=" + serverName + ";initial catalog=" + sqlceFileName + // ";user id=sa;password=amihan"; //const string connectionStringName = sQlServConString; //const string providerName = "System.Data.SqlClient"; //if (!WebSecurity.Initialized) // WebSecurity.InitializeDatabaseConnection(connectionStringName, providerName, "Users", // "UserId", "UserName", false); //#endregion }
private void ExecuteSaveUserViewCommand() { try { if (Users.Any(u => u.UserName == SelectedUser.UserName && u.UserId != SelectedUser.UserId)) { MessageBox.Show("There exist user with same username, try another username... "); return; } SelectedUser.Roles = new List <UsersInRoles>(); foreach (var role in SelectedRoles) { SelectedUser.Roles.Add(new UsersInRoles { UserId = SelectedUser.UserId, Role = role }); } if (!string.IsNullOrEmpty(SelectedUser.NewPassword)) { SelectedUser.Password = SelectedUser.NewPassword; SelectedUser.ConfirmPassword = SelectedUser.NewPassword; //SelectedUser.TempPassword = SelectedUser.NewPassword; } SelectedUser.DateLastModified = DateTime.Now; var dbContext2 = new ServerDbContextFactory().Create(); if (SelectedUser.UserId == 0) { SelectedUser.DateRecordCreated = DateTime.Now; WebSecurity.CreateUserAndAccount(SelectedUser.UserName, SelectedUser.Password, new { Status = 0, Enabled = true, RowGuid = Guid.NewGuid(), Email = SelectedUser.Email ?? "", CreatedByUserId = 1, DateRecordCreated = DateTime.Now, ModifiedByUserId = 1, DateLastModified = DateTime.Now }, true); SelectedUser.UserId = WebSecurity.GetUserId(SelectedUser.UserName); var membershipDto = dbContext2.Set <MembershipDTO>().ToList() .FirstOrDefault(m => m.UserId == SelectedUser.UserId); if (membershipDto != null) { membershipDto.RowGuid = Guid.NewGuid(); membershipDto.Enabled = true; membershipDto.CreatedByUserId = 1; membershipDto.DateRecordCreated = DateTime.Now; membershipDto.ModifiedByUserId = 1; membershipDto.DateLastModified = DateTime.Now; dbContext2.Set <MembershipDTO>().Add(membershipDto); dbContext2.Entry(membershipDto).State = EntityState.Modified; dbContext2.SaveChanges(); } } try { if (SelectedLocalAgency != null) { SelectedUser.AgencyId = SelectedLocalAgency.Id; } else if (SelectedForeignAgent != null) { SelectedUser.AgentId = SelectedForeignAgent.Id; } var lofRoles = SelectedRoles; // _unitOfWork.UserRepository<RoleDTO>().Query().Get().ToList(); foreach (var role in lofRoles) { dbContext2.Set <UsersInRoles>().Add(new UsersInRoles { RoleId = role.RoleId, UserId = WebSecurity.GetUserId(SelectedUser.UserName) }); } dbContext2.SaveChanges(); } catch (Exception ex) { } _unitOfWork.Commit(); GetLiveUsers(); } catch (Exception e) { MessageBox.Show(e.Message); } }