public UserMainPage() { InitializeComponent(); userMainViewModel = new UserMainViewModel(); userMainViewModel.navigation = Navigation; this.BindingContext = userMainViewModel; }
//Updates user info public bool UpdateUser(string uniqueName, UserMainViewModel userToBeUpdated) { try { var user = _context.Users.First(u => u.UniqueName == uniqueName); if (user != null) { user.Name = userToBeUpdated.Name; user.GivenName = userToBeUpdated.GivenName; user.Surname = userToBeUpdated.Surname; user.JobTitle = userToBeUpdated.JobTitle; user.ManagerUniqueName = userToBeUpdated.ManagerUniqueName; _context.SaveChanges(); return(true); } else { return(false); } } catch (Exception) { throw; } }
public async Task <IActionResult> Account(string id) { var user = await _userManager.FindByIdAsync(id); if (user == null) { return(RedirectToAction("StatusCodePage", "Error", new { code = 404 })); } else if (user != null && ((user.UserName == User.Identity.Name) || User.IsInRole("Administrator"))) { var model = new UserMainViewModel() { UserId = user.Id, }; await CollectUserRakings(user, model); return(View(model)); } else { var properUser = await _userManager.FindByNameAsync(User.Identity.Name); return(RedirectToAction("AccesDenied", "Login", new { returnUrl = "/User/Account/" + properUser.Id })); } }
public UserMainPage() { viewModel = new UserMainViewModel(); BindingContext = viewModel; InitializeComponent(); if (ServiceContext.Instance.CurrentUser != null) { //imageUserPhoto.Source = new UriImageSource //{ // Uri = new Uri(ServiceContext.Instance.CurrentUser.UserHeadImg), // CachingEnabled = true, // CacheValidity = new TimeSpan(5, 0, 0, 0) //}; } }
public ActionResult EditCredentials(int id) { var user = UserManager.FindById(id); var userViewModel = new UserViewModel()//Load User Credentials { UserName = user.UserName, FName = user.FirstName, LName = user.LastName, BirthDate = user.BirthDate, Phonenumber = user.PhoneNumber, }; var allroles = UserRole.Roles; var roles = user.Roles; var userRoleViewModels = new List <UserRoleViewModel>(); foreach (var item in allroles)// Load All Roles { var newViewModel = new UserRoleViewModel { Show = item.Show, RoleId = item.Id, BaseCoding = item.BaseCoding, IsActive = item.IsActive, RoleName = item.Name, UserId = id }; foreach (var role in roles.Where(role => role.RoleId == item.Id)) { //if new Role Exist In userRole table, then apply is checked newViewModel.ApplyPrem = true; newViewModel.UserId = role.UserId; } userRoleViewModels.Add(newViewModel); } var userMainViewModel = new UserMainViewModel() { // user main view model, include two model: one "UserViewModel" and a list of "UserRoleViewModel" UserViewModel = userViewModel, UserRoleViewModel = userRoleViewModels, UserPasswordViewModel = new UserPasswordViewModel { UserId = id } }; return(View(userMainViewModel)); }
public async Task <string> StoreUserInfo(string user, string token) { HttpClient client = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "https://graph.microsoft.com/v1.0/me"); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); HttpResponseMessage responseProfile = await client.SendAsync(request); string result = null; HttpRequestMessage requestManager = new HttpRequestMessage(HttpMethod.Get, "https://graph.microsoft.com/v1.0/me/manager"); requestManager.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); var responseManager = await client.SendAsync(requestManager); Task.WaitAll(); if (responseProfile.IsSuccessStatusCode && responseManager.IsSuccessStatusCode) { var profileSerialized = await responseProfile.Content.ReadAsStringAsync(); var profile = JsonConvert.DeserializeObject <GraphProfileViewModel>(profileSerialized); var managerSerialized = await responseManager.Content.ReadAsStringAsync(); var manager = JsonConvert.DeserializeObject <GraphProfileViewModel>(managerSerialized); var userToBeUpdated = new UserMainViewModel() { Name = profile.displayName, Email = profile.userPrincipalName, GivenName = profile.givenName, Surname = profile.surname, JobTitle = profile.jobTitle, ManagerUniqueName = manager.userPrincipalName }; var userStatus = Util.ConnectToRemoteService(HttpMethod.Put, Util.PermissionsURL + "api/permission/updateuser?=" + user, user, string.Empty, userToBeUpdated).Result; result = profileSerialized; } return(result); }
public UserMainViewModel MainMenuUser(int?id, bool predicate) { if (predicate) { UserMainViewModel model = new UserMainViewModel(); model.Results = Database.Results.GetAll(). Where(x => x.UserInfo.IdUserInfo == FindIdUser(HttpContext.Current.User.Identity.Name) && x.TestPassed == !predicate). ToList(); foreach (Result result in model.Results) { result.Test.Theme = Database.Themes.Get(result.Test.IdTheme.Value); } if (id.HasValue) { model.Test = Database.Results.Get(id.Value).Test; } return(model); } else { UserMainViewModel model = new UserMainViewModel(); model.Results = Database.Results.GetAll(). Where(x => x.UserInfo.IdUserInfo == FindIdUser(HttpContext.Current.User.Identity.Name) && x.TestPassed == true). ToList(); foreach (Result result in model.Results) { result.Test.Theme = Database.Themes.Get(result.Test.IdTheme.Value); } if (id.HasValue) { model.Test = Database.Results.Get(id.Value).Test; } return(model); } }
private async Task CollectUserRakings(UserModel user, UserMainViewModel model) { var cubes = await _cubeCollectionsService.GetAllCubesOfUserAsync(user.Id); var categories = cubes .Select(c => c.Category) .Distinct() .ToList(); foreach (var category in categories) { model.Categoreis.Add(new UserMainViewModel.CategoriesTableItem() { Category = category, Position = await _seriesService.GetUserRankedPositionCategoryAsync(user.Id, category), SolvesAmount = await _seriesService.GetAmountOfSolvesForUserAndCategoryAsync(user.Id, category), }); } foreach (var cube in cubes) { model.Cubes.Add(new UserMainViewModel.CubesTableItem() { Cube = cube, Position = await _seriesService.GetUserRankedPositionCubeAsync(user.Id, cube), SolvesAmount = await _seriesService.GetAmountOfSolvesForUserAndCubeAsync(user.Id, cube), }); } model.Categoreis = model.Categoreis .OrderBy(c => c.Category.Name) .ToList(); model.Cubes = model.Cubes .OrderBy(c => c.Cube.Manufacturer.Name) .ThenBy(c => c.Cube.ModelName) .ThenBy(c => c.Cube.PlasticColor.Name) .ToList(); }
public UserMainView(string listType, tblUser user) { InitializeComponent(); DataContext = new UserMainViewModel(this, listType, user); }
private void OnMainGridDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { m_ViewModel = (UserMainViewModel)this.DataContext; }
public UserMainView(UserMainViewModel viewModel) { InitializeComponent(); this.DataContext = viewModel; }
public UserMain(tblPerson person) { DataContext = new UserMainViewModel(this, person); InitializeComponent(); }
public UserMain(tblUser user) { InitializeComponent(); DataContext = new UserMainViewModel(this, user); }