public static string GetUserNameById(string Id) { DatabaseControler dc = new DatabaseControler(); ApplicationUser user = dc.GetUserById(Id); return(user.FirstName + " " + user.LastName); }
public bool IsAdministrator() { bool retval = false; var userId = User.Identity.GetUserId(); DatabaseControler dc = new DatabaseControler(); var user = dc.GetUserById(userId); if (dc.GetUserRoles(user).Contains("ADMINISTRATOR")) { retval = true; } return retval; }
public static bool IsAdministrator(string Id) { bool retval = false; DatabaseControler dc = new DatabaseControler(); ApplicationUser user = dc.GetUserById(Id); if (dc.GetUserRoles(user).Contains("ADMINISTRATOR")) { retval = true; } return(retval); }
public ActionResult Save(DriverViewModels model) { if (!ModelState.IsValid) { return(View("DriverForm", model)); } else if (!IsAdministrator()) { RedirectToAction("Index", "Home"); } DatabaseControler dc = new DatabaseControler(); IdentityResult result = IdentityResult.Success; ApplicationUser user = new ApplicationUser(); ApplicationUserManager userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); if (string.IsNullOrEmpty(model.Id)) { user = new ApplicationUser { UserName = model.Email, Email = model.Email }; result = userManager.Create(user, model.Password); if (result.Succeeded) { user.City = model.City; user.FirstName = model.FirstName; user.FlatNumber = model.FlatNumber; user.HouseNumber = model.HouseNumber; user.LastName = model.LastName; user.Street = model.Street; user.ZipCode = model.ZipCode; user.CreateTime = DateTime.Now; user.ModyfiTime = DateTime.Now; user.EmailConfirmed = true; user.PhoneNumberConfirmed = true; user.PhoneNumber = "+48" + model.Number; user.TwoFactorEnabled = true; var currentUser = userManager.FindByName(user.UserName); var role = userManager.AddToRole(currentUser.Id, "Kierowca".ToUpper()); } AddErrors(result); } else { user = dc.GetUserById(model.Id); user.City = model.City; user.FirstName = model.FirstName; user.FlatNumber = model.FlatNumber; user.HouseNumber = model.HouseNumber; user.LastName = model.LastName; user.Street = model.Street; user.ZipCode = model.ZipCode; user.CreateTime = DateTime.Now; user.ModyfiTime = DateTime.Now; user.Email = model.Email; user.ModyfiTime = DateTime.Now; user.PhoneNumber = model.Number; } if (result.Succeeded) { dc.UpdateUserData(user, User.Identity.GetUserId()); } return(RedirectToAction("Index", "Drivers")); }