public static void RolloverDailyBoosted() { AppIdentityDbContext context; using (context = AppIdentityDbContext.Create()) { IUnitOfWork unitOfWork = new UnitOfWork(context); IObjectiveRepository objectiveRepository = new ObjectiveRepository(unitOfWork); List <BoostedObjective> boostedObjectives = objectiveRepository.GetBoostedObjectives().Where(b => b.IsLive() == false).ToList(); foreach (BoostedObjective objective in boostedObjectives) { objectiveRepository.DeleteBoostedObjective(objective.BoostedObjectiveID); } BoostedObjective newBoostedObjective = new BoostedObjective(); // grab an active objective that has a product associated it (objectives without products are special and shouldn't be boosted via this method) Objective randomObjective = objectiveRepository.GetObjectives().Where(l => l.IsActive && l.Product != null && l.RequiresAdmin == false).OrderBy(x => Guid.NewGuid()).FirstOrDefault(); if (randomObjective == null) { unitOfWork.Save(); return; } SelectBoostAmount(newBoostedObjective); DateTime endDate = GetMidnightEST().AddDays(1); newBoostedObjective.EndDate = endDate; newBoostedObjective.IsDaily = true; randomObjective.AddBoostedObjective(newBoostedObjective); objectiveRepository.UpdateObjective(randomObjective); ISiteRepository siteRepository = new SiteRepository(unitOfWork); String urlAndName = String.Empty; if (randomObjective.Product.IsSteamAppID) { urlAndName = "[url=https://store.steampowered.com/app/" + randomObjective.Product.AppID + "]" + randomObjective.Title + "[/url]"; } else { urlAndName = randomObjective.Title; } SiteNotification notification = new SiteNotification() { Notification = "[boosted][/boosted] Objective [ptext]\"" + randomObjective.ObjectiveName + "\"[/ptext] for " + randomObjective.Title + " is [url=https://theafterparty.azurewebsites.net/objectives/boosted]boosted[/url] by [gtext]" + randomObjective.BoostedObjective.BoostAmount + "x[/gtext] for a boosted award of [gtext]" + randomObjective.FixedReward() + "[/gtext]!", NotificationDate = DateTime.Now }; siteRepository.InsertSiteNotification(notification); unitOfWork.Save(); } }
IEnumerable <string> GetUsersToNotify(SiteNotification notif) { foreach (var user in db.SelectObjectsWhere <User> ("SiteNotifications & {0} = {1}", (int)notif, (int)notif)) { yield return(user.Email); } }
public async Task <ApiResponse> SavePushNotificationSettingsAsync(SiteNotification model) { var _apiRes = new ApiResponse(); var result = await _context.site_notification.FirstOrDefaultAsync(); if (result != null) { result.iphone_key = model.iphone_key; result.android_key = model.android_key; result.send_url = model.send_url; result.is_active = model.is_active; result.updated_by = model.UserId; result.updated_on = DateTime.Now; _context.site_notification.Update(result); _context.SaveChanges(); } else { model.created_by = model.UserId; model.created_on = DateTime.Now; model.updated_by = model.UserId; model.updated_on = DateTime.Now; await _context.site_notification.AddAsync(model); await _context.SaveChangesAsync(); } _apiRes.Message = "Push Notification settings has been saved."; _apiRes.Status = true; return(_apiRes); }
public static void RolloverWeeklyDeals() { AppIdentityDbContext context; using (context = AppIdentityDbContext.Create()) { IUnitOfWork unitOfWork = new UnitOfWork(context); IListingRepository listingRepository = new ListingRepository(unitOfWork); List <DiscountedListing> oldWeeklies = listingRepository.GetDiscountedListings().Where(d => d.IsLive() == false).ToList(); if (oldWeeklies != null && oldWeeklies.Count > 0) { foreach (DiscountedListing oldListing in oldWeeklies) { listingRepository.DeleteDiscountedListing(oldListing.DiscountedListingID); } } Random rand = new Random(); int numDeals = rand.Next(randBase) + randOffset; List <Listing> newDeals = listingRepository.GetListings().Where(l => l.Quantity > 0 && l.ListingPrice > 1).OrderBy(x => Guid.NewGuid()).Take(numDeals).ToList(); if (newDeals == null || newDeals.Count == 0) { unitOfWork.Save(); return; } DateTime dealExpiry = GetMidnightEST().AddDays(7).AddHours(5); foreach (Listing listing in newDeals) { DiscountedListing newDiscountedListing = new DiscountedListing(); SelectDealPercent(newDiscountedListing); newDiscountedListing.WeeklyDeal = true; newDiscountedListing.ItemSaleExpiry = dealExpiry; listing.AddDiscountedListing(newDiscountedListing); listingRepository.UpdateListing(listing); } ISiteRepository siteRepository = new SiteRepository(unitOfWork); SiteNotification notification = new SiteNotification() { Notification = "[weekly][/weekly] There are [gtext]" + numDeals + "[/gtext] new [url=https://theafterparty.azurewebsites.net/store/deals/weekly]deals[/url] available this week!", NotificationDate = DateTime.Now }; siteRepository.InsertSiteNotification(notification); unitOfWork.Save(); } }
public void DeleteSiteNotification(int siteNotificationID) { SiteNotification siteNotification = context.SiteNotifications.Find(siteNotificationID); if (siteNotification != null) { context.SiteNotifications.Remove(siteNotification); } }
public HomeIndexVM() { Sessions = new List <Database.Models.Session>(); // Default the timezone to UTC TimeZoneId = "UTC"; RecentChanges = new List <NewsRecentChanges>(); SiteNotification = new SiteNotification(); DisplayNotification = false; }
public void UpdateSiteNotification(SiteNotification siteNotification) { SiteNotification targetSiteNotification = context.SiteNotifications.Find(siteNotification.SiteNotificationID); if (targetSiteNotification != null) { targetSiteNotification.Notification = siteNotification.Notification; targetSiteNotification.NotificationDate = siteNotification.NotificationDate; } }
public void AddSiteNotification(string notification) { SiteNotification siteNotification = new SiteNotification(); siteNotification.Notification = notification; siteNotification.NotificationDate = DateTime.Now; siteRepository.InsertSiteNotification(siteNotification); unitOfWork.Save(); }
public void RolloverDailyDeal() { DiscountedListing discountedListing = listingRepository.GetDiscountedListings().Where(d => d.DailyDeal).FirstOrDefault(); if (discountedListing != null) { listingRepository.DeleteDiscountedListing(discountedListing.DiscountedListingID); } List <DiscountedListing> expiredListings = listingRepository.GetDiscountedListings().Where(d => d.IsLive() == false).ToList(); if (expiredListings != null) { foreach (DiscountedListing listing in expiredListings) { listingRepository.DeleteDiscountedListing(listing.DiscountedListingID); } } DiscountedListing newDiscountedListing = new DiscountedListing(); Listing randomListing = listingRepository.GetListings().Where(l => l.Quantity > 0).OrderBy(x => Guid.NewGuid()).FirstOrDefault(); if (randomListing == null) { unitOfWork.Save(); return; } SelectDealPercent(newDiscountedListing); DateTime expiry = DateTime.Now.AddDays(1).AddMinutes(-5); newDiscountedListing.DailyDeal = true; newDiscountedListing.ItemSaleExpiry = expiry; randomListing.AddDiscountedListing(newDiscountedListing); listingRepository.UpdateListing(randomListing); SiteNotification notification = new SiteNotification() { Notification = "Today's daily deal is " + randomListing.ListingName + ", now on sale for " + randomListing.SaleOrDefaultPrice() + " points!", NotificationDate = DateTime.Now }; siteRepository.InsertSiteNotification(notification); unitOfWork.Save(); }
public async Task <SiteNotification> CreateSiteNotificationAsync(int siteRegistrationNoteId, int adminId, int assineeId) { var notification = new SiteNotification { SiteRegistrationNoteId = siteRegistrationNoteId, AdminId = adminId, AssigneeId = assineeId, }; _context.SiteNotifications.Add(notification); await _context.SaveChangesAsync(); return(notification); }
public void AddObjective(Objective objective) { objectiveRepository.InsertObjective(objective); unitOfWork.Save(); SiteNotification notification = new SiteNotification(); string game = ""; if (objective.Product != null) { game = " for " + objective.Product.ProductName; } notification.Notification = "\"" + objective.ObjectiveName + "\" objective added" + game + "!"; notification.NotificationDate = DateTime.Now; siteRepository.InsertSiteNotification(notification); }
public async Task <IViewComponentResult> InvokeAsync() { var model = new SiteNotification(); var result = await _service.GetPushNotificationSettingsAsync(); if (result.Data != null) { model.notification_id = result.Data.notification_id; model.iphone_key = result.Data.iphone_key; model.android_key = result.Data.android_key; model.send_url = result.Data.send_url; //model.is_active = result.Data.is_active; //model.is_status = (result.Data.is_active == 1 ? true : false); } return(await Task.FromResult((IViewComponentResult)View("Default", model))); }
public void SetSiteNotification(SiteNotification notif, bool enable) { if ((notif & SiteNotification.SiteAdminNotificationMask) != 0) { CheckIsSiteAdmin(); } if (enable) { User.SiteNotifications |= notif; } else { User.SiteNotifications &= ~notif; } db.UpdateObject(User); }
public async Task <ActionResult> AddObjective(AddEditObjectivesViewModel model) { if (ModelState.IsValid) { if (model.ProductID != 0) { model.Objective.AddProduct(objectiveService.GetProductByID(model.ProductID)); } else if (String.IsNullOrEmpty(model.Objective.Title)) { model.Objective.Title = "Misc."; } SiteNotification notification = new SiteNotification(); objectiveService.AddObjective(model.Objective); notification.Notification = "[new][/new] [ptext]Monukai[/ptext] added an objective, [url=https://theafterparty.azurewebsites.net/objectives/objective/" + model.Objective.ObjectiveID + "][gtext]\"" + model.Objective.ObjectiveName + "\"[/gtext][/url], for the game [ptext]" + model.Objective.Title + "[/ptext]"; notification.NotificationDate = DateTime.UtcNow; siteService.AddSiteNotification(notification); model.LoggedInUser = await objectiveService.GetCurrentUser(); model.FullNavList = CreateObjectivesAdminNavList(); return(View("EditObjective", model)); } else { model.LoggedInUser = await objectiveService.GetCurrentUser(); model.FullNavList = CreateObjectivesAdminNavList(); return(View(model)); } }
private async Task AddNewNotification(SiteModel site) { if (site.ParentId.HasValue) { var notificationParent = this.siteNotiRepo.FindBy(sn => sn.SiteId == site.ParentId); // Insert new notification foreach (var newItem in notificationParent) { SiteNotification newSiteNotification = new SiteNotification { SiteId = site.Id, NotificationId = newItem.NotificationId, InheritedNotification = newItem.InheritedNotification, InheritedReceiver = newItem.InheritedReceiver, DefaultReceiver = newItem.DefaultReceiver, Enabled = newItem.Enabled, }; // Add New await this.siteNotiRepo.AddAsync(newSiteNotification); } } }
public void SendMail(string subject, string body, SiteNotification notif) { BuildService.SendMail (GetUsersToNotify (notif), subject, body); }
public void InsertSiteNotification(SiteNotification siteNotification) { context.SiteNotifications.Add(siteNotification); }
public async Task <ApiResponse> SavePushNotificationSettingsAsync(SiteNotification model) => await _repository.SavePushNotificationSettingsAsync(model);
public void SetSiteNotification(SiteNotification notif, bool enable) { if ((notif & SiteNotification.SiteAdminNotificationMask) != 0) CheckIsSiteAdmin (); if (enable) User.SiteNotifications |= notif; else User.SiteNotifications &= ~notif; db.UpdateObject (User); }
public void EditSiteNotification(SiteNotification siteNotification) { siteRepository.UpdateSiteNotification(siteNotification); unitOfWork.Save(); }
public void AddSiteNotification(SiteNotification siteNotification) { siteRepository.InsertSiteNotification(siteNotification); unitOfWork.Save(); }
public void SendMail(string subject, string body, SiteNotification notif) { BuildService.SendMail(GetUsersToNotify(notif), subject, body); }
public static void RolloverDailyDeal() { AppIdentityDbContext context; using (context = AppIdentityDbContext.Create()) { IUnitOfWork unitOfWork = new UnitOfWork(context); IListingRepository listingRepository = new ListingRepository(unitOfWork); DiscountedListing discountedListing = listingRepository.GetDiscountedListings().Where(d => d.DailyDeal).FirstOrDefault(); if (discountedListing != null) { listingRepository.DeleteDiscountedListing(discountedListing.DiscountedListingID); } List <DiscountedListing> expiredListings = listingRepository.GetDiscountedListings().Where(d => d.IsLive() == false).ToList(); if (expiredListings != null) { foreach (DiscountedListing listing in expiredListings) { listingRepository.DeleteDiscountedListing(listing.DiscountedListingID); } } DiscountedListing newDiscountedListing = new DiscountedListing(); Listing randomListing = listingRepository.GetListings().Where(l => l.Quantity > 0 && l.ListingPrice > 1).OrderBy(x => Guid.NewGuid()).FirstOrDefault(); if (randomListing == null) { unitOfWork.Save(); return; } SelectDealPercent(newDiscountedListing); DateTime expiry = GetMidnightEST().AddDays(1).AddHours(5); newDiscountedListing.DailyDeal = true; newDiscountedListing.ItemSaleExpiry = expiry; randomListing.AddDiscountedListing(newDiscountedListing); listingRepository.UpdateListing(randomListing); ISiteRepository siteRepository = new SiteRepository(unitOfWork); String urlAndName = String.Empty; if (String.IsNullOrWhiteSpace(randomListing.GetQualifiedSteamStorePageURL()) == false) { urlAndName = "[url=" + randomListing.GetQualifiedSteamStorePageURL() + "]" + randomListing.ListingName + "[/url]"; } else { urlAndName = randomListing.ListingName; } SiteNotification notification = new SiteNotification() { Notification = "[daily][/daily] Today's [url=https://theafterparty.azurewebsites.net/store/deals/daily]daily deal[/url] is " + urlAndName + ", now on sale for [gtext]" + randomListing.SaleOrDefaultPrice() + "[/gtext] " + randomListing.GetPluralizedSalePriceUnit() + "!", NotificationDate = DateTime.Now }; siteRepository.InsertSiteNotification(notification); unitOfWork.Save(); } }
IEnumerable<string> GetUsersToNotify(SiteNotification notif) { foreach (var user in db.SelectObjectsWhere<User> ("SiteNotifications & {0} = {1}", (int)notif, (int)notif)) yield return user.Email; }
// --- Listing building logic public List <String> AddSteamProductKeys(Platform platform, string input) { List <Listing> listings = new List <Listing>(); List <String> addedKeys = new List <String>(); input = input.Replace("\r\n", "\r"); input = input.Replace("\n", "\r"); List <String> lines = input.Split(new string[] { "\r" }, StringSplitOptions.RemoveEmptyEntries).ToList(); Regex SubIDPriceKey = new Regex(@"^sub/([0-9]+)\t+([0-9,]+)\t+([0-9]+)\t+([^\t]+)(\t+[^\t]+)?$"); Regex AppIDPriceKey = new Regex(@"^([0-9]+)\t+([0-9]+)(\t+[^\t]+)?$"); //\t+([^\t]+) DateTime dateAdded = DateTime.Now; Match match; bool isGift = false; string key = ""; string gameName = ""; int appId = 0; int price = 0; int subId = 0; List <int> appIds = new List <int>(); foreach (String line in lines) { price = 0; appId = 0; gameName = ""; key = ""; isGift = false; subId = 0; appIds = new List <int>(); if (AppIDPriceKey.Match(line).Success) { match = AppIDPriceKey.Match(line); appId = Int32.Parse(match.Groups[1].ToString()); price = Int32.Parse(match.Groups[2].ToString()); if (String.IsNullOrEmpty(match.Groups[3].Value)) { isGift = true; } else { key = match.Groups[3].Value.Trim(); } } else if (SubIDPriceKey.Match(line).Success) { match = SubIDPriceKey.Match(line); subId = Int32.Parse(match.Groups[1].Value); string[] separator = new string[] { "," }; foreach (string splitId in match.Groups[2].Value.Split(separator, StringSplitOptions.RemoveEmptyEntries)) { appIds.Add(Int32.Parse(splitId)); } if (String.IsNullOrEmpty(match.Groups[5].Value)) { isGift = true; } else { key = match.Groups[5].Value.Trim(); } gameName = match.Groups[4].Value; price = Int32.Parse(match.Groups[3].ToString()); } else { addedKeys.Add("Unable to parse: " + line); continue; } Listing listing = null; if (appId != 0) { listing = listings.Where(x => x.Product.AppID == appId).SingleOrDefault(); if (listing == null) { listing = GetListingByAppIDSteam(appId, platform.PlatformID);//GetListingByAppID(appId, platform.PlatformName); if (listing != null) { listings.Add(listing); } } } else if (subId != 0) { listing = listings.Where(x => x.Product.AppID == subId).SingleOrDefault(); if (listing == null) { listing = GetListingByAppIDSteam(subId, platform.PlatformID);//GetListingByAppID(subId, platform.PlatformName); if (listing != null) { listings.Add(listing); } } } if (listing != null) { listing.ListingPrice = price; listing.AddProductKeyAndUpdateQuantity(new ProductKey(isGift, key)); listing.DateEdited = dateAdded; //listingRepository.UpdateListing(listing); addedKeys.Add(platform.PlatformName + ": " + listing.ListingName + "...+1!"); } else { listing = new Listing(gameName, price, dateAdded); listing.AddPlatform(platform); listing.AddProductKeyAndUpdateQuantity(new ProductKey(isGift, key)); Product product = new Product(appId, gameName); //Add logic to get data from api on product info & product details listing.AddProduct(product); // insert this listing entry for now, as we build the listing with data gathered from Steam's store api // we may need to build more listings recursively, we need this listing to be in the repository so it doesn't get stuck in a loop //AddListing(listing); if (appId != 0) { BuildListingWithAppID(listing, appId); } else if (appIds.Count != 0) { listing.Product.AppID = subId; BuildListingWithPackageID(listing, appIds, gameName); } listings.Add(listing); //UpdateListing(listing); addedKeys.Add(platform.PlatformName + ": " + listing.ListingName + "...created!"); } } foreach (Listing updatedListing in listings) { if (updatedListing.ListingID != 0) { listingRepository.UpdateListing(updatedListing); } else { listingRepository.InsertListing(updatedListing); } } SiteNotification notification = new SiteNotification(); var url = String.Format("https://theafterparty.azurewebsites.net/store/date?month={0}&day={1}&year={2}", DateTime.Today.Month, DateTime.Today.Day, DateTime.Today.Year); notification.Notification = "[new][/new] [url=" + url + "][gtext]" + addedKeys.Count() + "[/gtext][/url] items added to the [url=https://theafterparty.azurewebsites.net/store/newest]Co-op Shop[/url]!"; notification.NotificationDate = DateTime.Now; siteRepository.InsertSiteNotification(notification); unitOfWork.Save(); return(addedKeys); }
public List <String> AddProductKeys(Platform platform, string input) { if (platform.PlatformName.ToLower().CompareTo("steam") == 0) { return(AddSteamProductKeys(platform, input)); } List <String> addedKeys = new List <String>(); input = input.Replace("\r\n", "\r"); List <String> lines = input.Split(new string[] { "\r" }, StringSplitOptions.RemoveEmptyEntries).ToList(); Regex IDPriceKey = new Regex(@"^id/([0-9]+)\t+([0-9]+)\t+([^\t]+)$"); Regex NamePriceKey = new Regex("^([^\t]+)\t+([0-9]+)\t+([^\t]+)$"); Regex NamePrice = new Regex("^([^\t]+)\t+([0-9]+)$"); DateTime dateAdded = DateTime.Now; Match match; bool isGift = false; string key = ""; string gameName = ""; int price = 0; foreach (String line in lines) { price = 0; gameName = ""; key = ""; isGift = false; int p_id = 0; if (IDPriceKey.Match(line).Success) { match = IDPriceKey.Match(line); p_id = Int32.Parse(match.Groups[1].ToString()); price = Int32.Parse(match.Groups[2].ToString()); key = match.Groups[3].ToString(); } else if (NamePriceKey.Match(line).Success) { match = NamePriceKey.Match(line); gameName = match.Groups[1].Value; price = Int32.Parse(match.Groups[2].ToString()); key = match.Groups[3].ToString(); } else if (NamePrice.Match(line).Success) { match = NamePrice.Match(line); gameName = match.Groups[1].Value; price = Int32.Parse(match.Groups[2].ToString()); isGift = true; } Listing listing = null; if (String.IsNullOrEmpty(gameName) == false) { listing = listingRepository.GetListings().Where(l => l.ContainsPlatform(platform) && object.Equals(l.Product.ProductName, gameName)).SingleOrDefault(); } if (listing != null) { listing.ListingPrice = price; listing.AddProductKeyAndUpdateQuantity(new ProductKey(isGift, key)); listing.DateEdited = dateAdded; listingRepository.UpdateListing(listing); addedKeys.Add(platform.PlatformName + ": " + listing.ListingName + "...+1!"); } else { if (p_id != 0) { listing = listingRepository.GetListings().Where(l => l.Platforms.Any(p => p.PlatformID == platform.PlatformID) && l.Product.AppID == p_id && l.Product.IsSteamAppID == true).FirstOrDefault(); } if (listing == null) { Product product = null; if (p_id != 0) { product = listingRepository.GetProducts().FirstOrDefault(p => p.AppID == p_id && p.IsSteamAppID == true); if (product == null) { product = new Product(p_id); bool success = BuildOrUpdateSteamProduct(p_id, product); if (success == false) { product = null; } } } if (product != null) { listing = new Listing(product.ProductName, price, dateAdded); } else { product = new Product(gameName, false); listing = new Listing(gameName, price, dateAdded); } listing.AddPlatform(platform); listing.AddProduct(product); listing.AddProductKeyAndUpdateQuantity(new ProductKey(isGift, key)); listingRepository.InsertListing(listing); addedKeys.Add(platform.PlatformName + ": " + listing.ListingName + "...created!"); } else { listing.ListingPrice = price; listing.AddProductKeyAndUpdateQuantity(new ProductKey(isGift, key)); listing.DateEdited = dateAdded; listingRepository.UpdateListing(listing); addedKeys.Add(platform.PlatformName + ": " + listing.ListingName + "...+1!"); } } unitOfWork.Save(); } SiteNotification notification = new SiteNotification(); var url = String.Format("https://theafterparty.azurewebsites.net/store/date?month={0}&day={1}&year={2}", DateTime.Today.Month, DateTime.Today.Day, DateTime.Today.Year); notification.Notification = "[new][/new] [url=" + url + "][gtext]" + addedKeys.Count() + "[/gtext][/url] items added to the [url=https://theafterparty.azurewebsites.net/store/newest]Co-op Shop[/url]!"; notification.NotificationDate = DateTime.Now; siteRepository.InsertSiteNotification(notification); unitOfWork.Save(); return(addedKeys); }