private static ApplicationWithAttributes MakeApp() { AppCall call = new AppCall(ASMRestSettingsInstance.Instance); call.SkipHtmlEncoding = true; ApplicationWithAttributes app = call.Get(79); return(app); }
public bool CheckMessageCounts(string AppToken) { if (AppToken != PrivateValues.AppToken) { throw new Exception("Unauthorized"); } AppCall AppCall = new AppCall(); AppCall.AppCallTypeId = 3; AppCall.Date = DateTime.Now; try { //get each active user foreach (var User in db.Users.Where(x => x.IsActive)) { //if account type 1 and over 30 messages if (User.AccountTypeId == 1 && CheckMonthTotal(User.Id) > 30) { User.CanEditMessages = false; } //if account type 2 and over 500 messages else if (User.AccountTypeId == 2 && CheckMonthTotal(User.Id) > 500) { User.CanEditMessages = false; } //if account type 3 and over 1000 messages else if (User.AccountTypeId == 3 && CheckMonthTotal(User.Id) > 1000) { User.CanEditMessages = false; } else { User.CanEditMessages = true; } } AppCall.Status = "Success"; db.AppCalls.Add(AppCall); db.SaveChanges(); return(true); } catch (Exception ex) { AppCall.Status = ex.Message; db.AppCalls.Add(AppCall); db.SaveChanges(); throw Utility.ThrowException(ex); } }
public void GetApp() { InitSettings(); AppCall call = new AppCall(ASMRestSettingsInstance.Instance); ApplicationWithAttributes app = call.Get(79); Assert.IsNotNull(app); Assert.AreEqual("Altoro Mutual", Utils.HtmlDecode(app.name)); Assert.AreEqual("Yes", app.GetAttrVal("Web Based")); }
void Init() { if (ASMRestSettingsInstance.Instance.IssueAttributeMap.Count == 0) { IssueAttributeDefinitionListCall defsCall = new IssueAttributeDefinitionListCall(ASMRestSettingsInstance.Instance); var defs = defsCall.Get(); foreach (IssueAttributeDefinitionEx def in defs.attributeDefColl) { ASMRestSettingsInstance.Instance.IssueAttributeMap.Add(def.id.ToString(), def.name); } } AppCall appCall = new AppCall(ASMRestSettingsInstance.Instance); var app = appCall.Get(ATTACKS_APP_ID); IssueListCall issuesCall = new IssueListCall(app, ASMRestSettingsInstance.Instance); issuesCall.SkipHtmlEncoding = true; issuesCall.IssueAttributesMap = ASMRestSettingsInstance.Instance.IssueAttributeMap; _issues = issuesCall.Fetch("+issuetype"); }
public bool CheckPayments(string AppToken) { if (AppToken != PrivateValues.AppToken) { throw new Exception("Unauthorized"); } AppCall AppCall = new AppCall(); AppCall.AppCallTypeId = 4; AppCall.Date = DateTime.Now; try { var AccountPayments = db.AccountPayments.Where(x => x.ExpirationDate < DateTime.Today).ToList(); //get all active accounts foreach (var AccountPayment in AccountPayments) { //if payment id bad, then suspend account if (false) { var CurrentUser = db.Users.SingleOrDefault(x => x.Id == AccountPayment.UserId); foreach (var ChoreList in CurrentUser.ChoreLists.Where(x => x.StatusId == 1)) { ChoreList.StatusId = 2; } } } db.SaveChanges(); //get all active users without free accounts var Users = db.Users.Where(x => x.IsActive && x.AccountTypeId != 1); foreach (var User in Users) { //each user without active payment will have all chorelists suspended if (AccountPayments.Count(x => x.UserId == User.Id) == 0) { //set each chorelist to suspended foreach (var ChoreList in User.ChoreLists.Where(x => x.StatusId == 1)) { ChoreList.StatusId = 2; } } } AppCall.Status = "Success"; db.AppCalls.Add(AppCall); db.SaveChanges(); return(true); } catch (Exception ex) { AppCall.Status = ex.Message; db.AppCalls.Add(AppCall); db.SaveChanges(); throw Utility.ThrowException(ex); } }
public bool SendEmails(string AppToken) { AppCall AppCall = new AppCall(); AppCall.AppCallTypeId = 2; AppCall.Date = DateTime.Now; try { if (AppToken != PrivateValues.AppToken) { throw new Exception("Unauthorized"); } //combine in database each Message with chore user and chore information var MessageQuery = (from Message in db.Messages join Chore in db.Chores on Message.ChoreId equals Chore.Id join ChoreUser in db.ChoreUsers on Message.ChoreUserId equals ChoreUser.Id where Message.DateScheduled < DateTime.Now && !Message.IsComplete select new _Message { Id = Message.Id, ChoreUserId = Message.ChoreUserId, ChoreId = Message.ChoreId, Phone = Message.Phone, Email = Message.Email, ChoreListId = Chore.ChoreListId, ChoreName = Chore.Name, ChoreDescription = Chore.Description, FirstName = ChoreUser.FirstName, LastName = ChoreUser.LastName }).ToList(); //for each message that needs to be sent. foreach (var Message in MessageQuery) { //get message row from entity var messagedb = db.Messages.SingleOrDefault(x => x.Id == Message.Id); try { //if User is currently verified if (messagedb.ChoreUser.IsVerified) { messagedb.IsVerified = true; //send message messagedb.Sid = TwilioRepository.SendMessage(Message); messagedb.DateSent = DateTime.Now; messagedb.IsComplete = true; } else { //if user is not verified, set message as complete messagedb.IsComplete = true; } db.SaveChanges(); } catch (Exception ex) { //save error log if needed messagedb.ErrorLog = ex.Message + " " + ex.StackTrace; db.SaveChanges(); } } AppCall.Status = "Success"; db.AppCalls.Add(AppCall); return(true); } catch (Exception ex) { AppCall.Status = ex.Message; db.AppCalls.Add(AppCall); db.SaveChanges(); throw Utility.ThrowException(ex); } }
//Decide next 24 hours which messages should be sent public bool SetSchedule() { AppCall AppCall = new AppCall(); AppCall.AppCallTypeId = 1; AppCall.Date = DateTime.Now; string ErrorHelper = string.Empty; try { //get active rotations with chore lists of active status var RotationsStatic = (from Rotation in db.RotationIntervals join ChoreList in db.ChoreLists on Rotation.ChoreListId equals ChoreList.Id where ChoreList.StatusId == 1 && Rotation.IsActive && Rotation.StartDate < DateTime.Today select Rotation ).ToList(); //get all active rotations foreach (var Rotation in RotationsStatic) { try { //# days since Start int DaysElapsed = (DateTime.Today - Rotation.StartDate).Days; //if day if (Rotation.IntervalTypeId == 1) { //check if current day needs alarm if ((DaysElapsed % Rotation.IntervalNumber) == 0) { //Set new Chore Rotation RotateChorelist(Rotation); } } //if business day if (Rotation.IntervalTypeId == 2) { //initialize business days elapsed int BusinessDaysElapsed = 0; //calculate business days elapsed for (DateTime DateIterator = Rotation.StartDate; DateIterator < DateTime.Today; DateIterator.AddDays(1)) { //if current day is not saturday and not sunday, iterate i if (DateIterator.DayOfWeek != DayOfWeek.Saturday && DateIterator.DayOfWeek != DayOfWeek.Sunday) { BusinessDaysElapsed++; } } //check if current day needs alarm and isn't business day if (BusinessDaysElapsed % Rotation.IntervalNumber == 0 && DateTime.Today.DayOfWeek != DayOfWeek.Saturday && DateTime.Today.DayOfWeek != DayOfWeek.Sunday) { //Set new Chore Rotation RotateChorelist(Rotation); } } //if month if (Rotation.IntervalTypeId == 3) { //check if current day is same day of month as start date if (DateTime.Today.Day == Rotation.StartDate.Day) { //Set new Chore Rotation RotateChorelist(Rotation); } } } catch (Exception ex) { //append Error helper message ErrorHelper += ex.Message + " " + ex.StackTrace; } } //email admin if error if (!string.IsNullOrEmpty(ErrorHelper)) { EmailAdmin(ErrorHelper); AppCall.Status = ErrorHelper; } else { AppCall.Status = "Success"; } db.AppCalls.Add(AppCall); db.SaveChanges(); return(true); } catch (Exception ex) { AppCall.Status = ex.Message; db.AppCalls.Add(AppCall); db.SaveChanges(); throw Utility.ThrowException(ex); } }