public void AutoMapper_ConvertFrom_Subscriber_To_NewSubscriber_IsValid() { var mapper = Configuration.CreateMapper(); var guid = Guid.NewGuid(); var sourceObject = new TwitchLib.Client.Models.Subscriber( badges: null, badgeInfo: null, colorHex: null, color: new System.Drawing.Color(), displayName: "testDisplayName", emoteSet: "", id: guid.ToString(), login: "******", systemMessage: "", msgId: "", msgParamCumulativeMonths: "", msgParamStreakMonths: "", msgParamShouldShareStreak: true, systemMessageParsed: "", resubMessage: "", subscriptionPlan: TwitchLib.Client.Enums.SubscriptionPlan.Tier2, subscriptionPlanName: "", roomId: "", userId: "123456", isModerator: true, isTurbo: false, isSubscriber: true, isPartner: false, tmiSentTs: DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(), userType: TwitchLib.Client.Enums.UserType.Staff, rawIrc: "", channel: "testChannel" ); var resultObject = mapper.Map <NewSubscriber>(sourceObject); var expectedObject = new NewSubscriber() { Channel = "testChannel", Months = 0, SubscribedTime = DateTime.UtcNow, SubscriptionPlan = Shared.Database.Models.SubscriptionPlan.Tier2, Id = guid, User = new User { UserId = 123456, UserName = "******", }, UserType = Shared.Database.Models.UserType.Staff, }; resultObject.Should().BeEquivalentTo(expectedObject, options => options .Using <DateTime>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromMilliseconds(100))) .WhenTypeIs <DateTime>() ); }
public ReturnMessage PostNewSubscriber(NewSubscriber newSubscriber) { GameData.Game gameVW; try { //var subscriber = new SubscriberRepository(_context, _NGSubscriptionsEntities); var mobileUser = _ISubscriberRepository.GetUserByPhoneNoWithoutExpDateCheck(newSubscriber.t); //If user subscription is expired if (mobileUser == null) { gameVW = new GameData.Game() { NetworkOperator = newSubscriber.nO, MSISDN = newSubscriber.t, SubDate = DateTime.Now, ExpDate = (newSubscriber.sT == 0) ? DateTime.Today.AddDays(7) : DateTime.Today.AddDays(1), Timestamped = DateTime.Now, Token = Guid.NewGuid().ToString().Substring(0, 7).ToUpper() }; return(new ReturnMessage() { ID = _ISubscriberRepository.PostNewSubscriber(gameVW), Message = $"Subscription Successful. Valid till: {gameVW.ExpDate.Value.ToShortDateString()}", Success = true }); } else { mobileUser.SubDate = DateTime.Now; mobileUser.ExpDate = (newSubscriber.sT == 0) ? (mobileUser.ExpDate < DateTime.Now) ? //if subscription is already expired DateTime.Now.AddDays(7) : // New Expiry Date is 7 days from today mobileUser.ExpDate.Value.AddDays(7) : //else New Expiry Date is 7 days from Old Expiry Date (mobileUser.ExpDate < DateTime.Now) ? //if subscription is already expired DateTime.Now.AddDays(1) : // New Expiry Date is 1 day from today mobileUser.ExpDate.Value.AddDays(1); //else New Expiry Date is 1 day from Old Expiry Date return(new ReturnMessage() { ID = _ISubscriberRepository.PostNewSubscriber(mobileUser), Message = $"Subscription Successful. Valid till: {mobileUser.ExpDate.Value.ToShortDateString()}", Success = true }); } } catch (Exception ex) { return(new ReturnMessage() { Success = false, Message = ex.Message }); } }
public async Task <IActionResult> Create(NewSubscriber nag) { if (ModelState.IsValid) { _db.Add(nag); await _db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(nag)); }
public async Task <IActionResult> Edit(NewSubscriber nec) { if (ModelState.IsValid) { _db.Update(nec); await _db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(nec)); }
private void Test_NewSubscriber(string _testString, string _channel) { try { if (ChatParsing.detectNewSubscriber(_testString, _channel)) { NewSubscriber sub = new NewSubscriber(_testString); if (sub.Channel == _channel && (sub.Name != null && sub.Name.Length > 1)) { Successful = true; } } else { Successful = false; } } catch (Exception ex) { FailedException = ex; } }
void CheckFollowers() { if (cooldown > 0) { --cooldown; return; } cooldown = 5; UserModule usermodule = context.GetModule <UserModule>(); try { foreach (UserInformation follower in GetFollowers()) { usermodule.SetInitialized(TwitchConstants.ServiceKey, follower.Username); if (!string.IsNullOrEmpty(follower.Avatar)) { User user = usermodule.GetUser(TwitchConstants.ServiceKey, follower.Username); if (user.Avatar != follower.Avatar) { usermodule.UpdateUserAvatar(user, follower.Avatar); } } if (usermodule.GetUserStatus(TwitchConstants.ServiceKey, follower.Username) >= UserStatus.Follower) { continue; } if (usermodule.SetUserStatus(TwitchConstants.ServiceKey, follower.Username, UserStatus.Follower)) { NewFollower?.Invoke(follower); } } } catch (WebException e) { Logger.Warning(this, "Unable to get followers", e.Message); return; } catch (Exception e) { Logger.Error(this, "Unable to get followers", e); return; } try { foreach (SubscriberInformation subscriber in GetSubscribers()) { usermodule.SetInitialized(TwitchConstants.ServiceKey, subscriber.Username); if (!string.IsNullOrEmpty(subscriber.Avatar)) { User user = usermodule.GetUser(TwitchConstants.ServiceKey, subscriber.Username); if (user.Avatar != subscriber.Avatar) { usermodule.UpdateUserAvatar(user, subscriber.Avatar); } } if (usermodule.GetUserStatus(TwitchConstants.ServiceKey, subscriber.Username) >= subscriber.Status) { continue; } if (usermodule.SetUserStatus(TwitchConstants.ServiceKey, subscriber.Username, subscriber.Status)) { NewSubscriber?.Invoke(subscriber); } } } catch (WebException e) { Logger.Warning(this, "Unable to get subscribers", e.Message); return; } catch (Exception e) { Logger.Error(this, "Unable to get subscribers", e); return; } context.GetModule <UserModule>().EndInitialization(TwitchConstants.ServiceKey); }
public void AddSubscriber(SubscriberInformation subscriber) { Logger.Info(this, $"New subscriber '{subscriber.Username}' with plan {subscriber.PlanName} on {subscriber.Service}."); NewSubscriber?.Invoke(subscriber); }
public void AutoMapper_ConvertFrom_NewGiftedSubscriptionDto_To_NewSubscriber_IsValid() { var mapper = Configuration.CreateMapper(); var guid = Guid.NewGuid(); var sourceObject = new NewGiftedSubscriptionDto { Channel = "testChannel", GiftedSubscription = new TwitchLib.Client.Models.GiftedSubscription( badges: null, badgeInfo: null, color: "", displayName: "testDisplayName", emotes: "", id: guid.ToString(), login: "******", isModerator: true, msgId: "", msgParamMonths: "10", msgParamRecipientDisplayName: "targetDisplayName", msgParamRecipientId: "111111", msgParamRecipientUserName: "******", msgParamSubPlanName: "Prime", msgMultiMonthDuration: "11", msgParamSubPlan: TwitchLib.Client.Enums.SubscriptionPlan.Prime, roomId: "", isSubscriber: true, systemMsg: "", systemMsgParsed: "", tmiSentTs: DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(), isTurbo: false, userType: TwitchLib.Client.Enums.UserType.Staff, userId: "123456" ) }; var resultObject = mapper.Map <NewSubscriber>(sourceObject); var expectedObject = new NewSubscriber() { Channel = "testChannel", Months = 10, SubscribedTime = DateTime.UtcNow, SubscriptionPlan = Shared.Database.Models.SubscriptionPlan.Prime, Id = guid, User = new User { UserId = 111111, UserName = "******", }, GiftedBy = new User { UserId = 123456, UserName = "******", }, UserType = Shared.Database.Models.UserType.Staff, }; resultObject.Should().BeEquivalentTo(expectedObject, options => options .Using <DateTime>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromMilliseconds(100))) .WhenTypeIs <DateTime>() ); }