public async Task <bool> ConfirmRequest(int id) { //Grabs request by ID var request = GetRequestById(id); //Find the User of the Request var user = _repo.GetUserById(request.UserId); var bar = _barRepo.GetBarById(request.BarId); //Adds claim to make the user a UserAdmin var result = await _userManager.AddClaimAsync(user, new Claim("IsUserAdmin", "true")); //Create a new UserBar with the information from the request. UserBar userBar = new UserBar { Bar = bar, User = user, BarId = bar.Id, UserId = user.Id }; //Add to UserBar database _userBarRepo.Add(userBar); _userBarRepo.SaveChanges(); //Delete the request after we add the new UserBar to the database. DeleteRequest(id); return(result.Succeeded); }
/// <summary> /// Gets the json for a <see cref="UserBar"/>, so it can be loaded with a better deserialiser. /// </summary> /// <param name="userBar">Bar data object from Morphic.Core</param> private string GetUserBarJson(UserBar userBar) { // Serialise the bar data so it can be loaded with a better deserialiser. SystemJson.JsonSerializerOptions serializerOptions = new SystemJson.JsonSerializerOptions(); serializerOptions.Converters.Add(new JsonElementInferredTypeConverter()); serializerOptions.Converters.Add( new SystemJson.Serialization.JsonStringEnumConverter(SystemJson.JsonNamingPolicy.CamelCase)); string barJson = SystemJson.JsonSerializer.Serialize(userBar, serializerOptions); // Dump to a file, for debugging. string barFile = AppPaths.GetConfigFile("last-bar.json5"); File.WriteAllText(barFile, barJson); return(barJson); }
public void Add(string Username, BarDTO b) { var GoogleBarId = b.GoogleBarId; var User = _userBarRepo.GetUserByUsername(Username); var UserId = User.Id; var UserBar = new UserBar { UserId = UserId, BarId = GetBarIdByGoogleBarId(GoogleBarId) }; _userBarRepo.Add(UserBar); _userBarRepo.SaveChanges(); }
public async Task FavoriteBarAsync(int userId, int barId) { var user = await FindUserByIdAsync(userId); var bar = await barService.FindBarByIdAsync(barId); var userBar = new UserBar() { UserId = userId, BarId = barId, User = user, Bar = bar, UserName = user.UserName, BarName = bar.Name }; dbContext.UserBar.Add(userBar); await dbContext.SaveChangesAsync(); }
public void ClaimBusiness(int id) { //Get Application User var user = _userManager.Users.FirstOrDefault(); //Find Bar From ID Passed var bar = _barService.GetActualBarById(id); //Create a new UserBar and Link with User and Bar var userBar = new UserBar { User = user, Bar = bar, UserId = user.Id, BarId = bar.Id }; //Add the UserBar to the database _userBarService.AddClaim(userBar); //Add new claim to user making them a "User Admin" _userManager.AddClaimAsync(user, new Claim("IsUserAdmin", "true")); }
public void AddClaim(UserBar userBar) { _userBarRepo.Add(userBar); _userBarRepo.SaveChanges(); }