public IActionResult Edit(int id) { var platform = _platformManager.GetPlatform(id); var platformViewModel = new PlatformViewModel() { PlatformId = platform.PlatformId, Name = platform.Name, Tenant = platform.Tenant, Description = platform.Description, LogoUrl = platform.Logo.Url, SocialBarColor = platform.ColorScheme.SocialBarColor, NavbarColor = platform.ColorScheme.NavBarColor, BannerColor = platform.ColorScheme.BannerColor, ButtonColor = platform.ColorScheme.ButtonColor, ButtonTextColor = platform.ColorScheme.ButtonTextColor, TextColor = platform.ColorScheme.TextColor, BodyColor = platform.ColorScheme.BodyColor }; return(View(platformViewModel)); }
public async Task <IActionResult> Edit(int id, [FromForm] PlatformViewModel platformViewModel, [FromServices] UserManager <User> userManager) { if (ModelState.IsValid) { var platform = _platformManager.GetPlatform(id); platform.Name = platformViewModel.Name; platform.Tenant = platformViewModel.Tenant; platform.Description = platformViewModel.Description; platform.ColorScheme.SocialBarColor = platformViewModel.SocialBarColor; platform.ColorScheme.BannerColor = platformViewModel.BannerColor; platform.ColorScheme.ButtonColor = platformViewModel.ButtonColor; platform.ColorScheme.ButtonTextColor = platformViewModel.ButtonTextColor; platform.ColorScheme.TextColor = platformViewModel.TextColor; platform.ColorScheme.BodyColor = platformViewModel.BodyColor; if (platformViewModel.LogoChanged) { var fileName = Util.Util.GenerateDataStoreObjectName(platformViewModel.Name); var imageObj = new Media() { Name = fileName, Url = await _fileUploader.UploadFile(fileName, "platform-logos", platformViewModel.Logo), }; platform.Logo = imageObj; } if (platformViewModel.BannerChanged) { var fileName = Util.Util.GenerateDataStoreObjectName(platformViewModel.Name); var imageObj = new Media() { Name = fileName, Url = await _fileUploader.UploadFile(fileName, "platform-banners", platformViewModel.Banner), }; platform.Banner = imageObj; } List <User> admins = userManager.GetUsersForClaimAsync(new Claim(platform.Tenant, "Admin")).Result.ToList(); foreach (User admin in admins) { await userManager.ReplaceClaimAsync(admin, new Claim(platform.Tenant, "Admin"), new Claim(platform.Tenant, "User")); } List <User> admins2 = userManager.GetUsersForClaimAsync(new Claim(platform.Tenant, "Admin")).Result.ToList(); if (platformViewModel.Admins != null) { foreach (string AdminUserName in platformViewModel.Admins) { User newAdmin = userManager.FindByNameAsync(AdminUserName).Result; //Kijken of user al bestaat op het platform var claimsForSubdomain = userManager.GetClaimsAsync(newAdmin).Result.FirstOrDefault(c => c.Type == platform.Tenant); //Subdomain is het subdomain waarop je zit if (claimsForSubdomain == null) { //User heeft nog geen claim op dit platform => claim toewijzen dus! EN DIRECT ADMIN TOEWIJZEN await userManager.AddClaimAsync(newAdmin, new Claim(platform.Tenant, "Admin")); } else { //User heeft al een claim op dit platform -> Claim verwijderen is Admin Vervangen door User /*await userManager.ReplaceClaimAsync(newAdmin, new Claim(claimsForSubdomain.Type, claimsForSubdomain.Value), * new Claim(claimsForSubdomain.Type, "User"));*/ //User heeft al een claim op dit platform en wordt nu admin -> Claim verwijderen is User Vervangen door Admin await userManager.ReplaceClaimAsync(newAdmin, new Claim(claimsForSubdomain.Type, claimsForSubdomain.Value), new Claim(claimsForSubdomain.Type, "Admin")); } } } _platformManager.UpdatePlatform(platform); _unitOfWorkManager.Save(); return(Ok()); } return(StatusCode(400)); }
public async Task <PlatformData> AddPlatformData(string userId, string platformId, int numberOfGigs, DateTimeOffset?periodStart, DateTimeOffset?periodEnd, IList <RatingDataFetchResult> ratings, RatingDataFetchResult averageRating, IList <ReviewDataFetchResult> reviews, IList <AchievementFetchResult> achievements, string rawData, IAsyncDocumentSession session, CancellationToken cancellationToken = default) { var platform = await _platformManager.GetPlatform(platformId, session, cancellationToken); var platformData = await GetPlatformData(userId, platformId, session, cancellationToken); if (platformData == null) { platformData = new PlatformData(platform.Id, userId); await session.StoreAsync(platformData, cancellationToken); } var rawPlatformData = new RawData(rawData); platformData.AddRawDataToDataLog(rawPlatformData); platformData.LastUpdated = DateTimeOffset.UtcNow; platformData.NumberOfGigs = numberOfGigs; platformData.PeriodStart = periodStart; platformData.PeriodEnd = periodEnd; if (averageRating != null) { platformData.AverageRating = new Rating(averageRating.Identifier, averageRating.Value, platform.RatingInfo.MinRating, platform.RatingInfo.MaxRating, platform.RatingInfo.SuccessLimit); } else { platformData.AverageRating = null; } var transformedRatings = ratings.Select(r => new KeyValuePair <Guid, Rating>(r.Identifier, new Rating(r.Identifier, r.Value, platform.RatingInfo.MinRating, platform.RatingInfo.MaxRating, platform.RatingInfo.SuccessLimit))); var transformedReviews = reviews.Select(r => { var rating = transformedRatings.SingleOrDefault(kvp => kvp.Key == r.RatingIdentifier).Value; return(new ReviewData(r.ReviewIdentifier, r.ReviewText, r.ReviewHeading, r.ReviewerName, r.ReviewerAvatarUri, r.ReviewDate, rating?.Identifier)); }); platformData.Reviews = transformedReviews; platformData.Ratings = transformedRatings.Select(kvp => kvp.Value); var transformedAchievements = achievements.Select(a => { AchievementScore score = null; if (a.Score != null) { score = new AchievementScore(a.Score.Value, a.Score.Label); } return(new Achievement(a.AchievementId, a.Name, a.AchievementPlatformType, a.AchievementType, a.Description, a.ImageUri, score)); }); platformData.Achievements = transformedAchievements; return(platformData); }
public async Task <IActionResult> PromptCallback([FromQuery(Name = "prompt_id")] Guid promptId, [FromQuery(Name = "accept")] bool accept, CancellationToken cancellationToken) { using var session = _documentStore.OpenAsyncSession(); var prompt = await _emailValidatorManager.CompleteEmailValidation(promptId, accept, session, cancellationToken); var user = await session.LoadAsync <User>(prompt.UserId, cancellationToken); var platformConnectionInfos = new Dictionary <string, (PlatformConnection PlatformConnection, PlatformIntegrationType PlatformIntegrationType)>(); if (prompt.Result.HasValue) { var userEmail = user.UserEmails.Single(ue => ue.Email == prompt.EmailAddress); userEmail.SetEmailState(prompt.Result.Value ? UserEmailState.Verified : UserEmailState.Unverified); if (userEmail.UserEmailState == UserEmailState.Verified) { var appIds = prompt.PlatformIdToAppId.Values.SelectMany(v => v).Distinct(); var apps = await session.LoadAsync <App>(appIds, cancellationToken); foreach (var platformId in prompt.PlatformIdToAppId.Keys) { Core.Entities.Platform platform; if (platformId != "None") { platform = await _platformManager.GetPlatform(platformId, session, cancellationToken); } else { continue; } var appIdsToNotify = new List <string>(); foreach (var appId in prompt.PlatformIdToAppId[platformId]) { var app = apps[appId]; var(_, platformConnection, _) = await _platformConnectionManager.ConnectUserToEmailPlatform(platform.ExternalId, user, app, prompt.EmailAddress, _emailVerificationConfiguration.AcceptUrl, _emailVerificationConfiguration.DeclineUrl, prompt.PlatformDataClaim, session, true, cancellationToken); if (!platformConnectionInfos.ContainsKey(platformId)) { platformConnectionInfos.Add(platformId, (platformConnection, platform.IntegrationType)); } if (appIdsToNotify.All(aid => aid != appId)) { appIdsToNotify.Add(appId); } } if (appIdsToNotify.Any()) { await _appNotificationManager.NotifyPlatformConnectionDataUpdate(user.Id, appIdsToNotify, platform.Id, session, cancellationToken); } } } } await session.SaveChangesAsync(cancellationToken); foreach (var platformId in platformConnectionInfos.Keys) { var info = platformConnectionInfos[platformId]; if (info.PlatformConnection == null) { continue; } await _platformManager.TriggerDataFetch(user.Id, info.PlatformConnection, info.PlatformIntegrationType, _bus); } await session.SaveChangesAsync(cancellationToken); return(Ok()); }