Esempio n. 1
0
        public void CreateInvalidRegistration()
        {
            MessengerUtil messengerUtil = new MessengerUtil();
            Registration registration = new Registration();

            messengerUtil.Register(registration);
        }
Esempio n. 2
0
        public void CreateValidRegistration()
        {
            MessengerUtil messengerUtil = new MessengerUtil();
            Registration registration = new Registration();
            registration.UserId = 1;
            registration.URI = "FAKE URI";

            messengerUtil.Register(registration);
        }
Esempio n. 3
0
        private void AgeAccounts(User user, CapitalContext context)
        {
            try
            {
                IEnumerable<Account> accounts = context.Accounts.Where(x => x.UserId == user.UserId).Include(x => x.Frequency).AsEnumerable();

                foreach (Account acc in accounts)
                {
                    int? count = context.Statements.Where(x => x.Account.AccountId == acc.AccountId).Count();

                    if (count == 0)
                    {
                        Statement statement = new Statement();
                        statement.AccountId = acc.AccountId;
                        statement.Balance = acc.DefaultPayment;
                        statement.IsPaid = false;
                        statement.CreationDate = DateTime.Now;
                        statement.PaidAmount = 0;
                        statement.PaidDate = null;

                        // int freqDays = context.Frequency.Where(x => x.FrequencyId == context.Accounts.Where(y => y.AccountId == acc.AccountId).FirstOrDefault().FrequencyId).FirstOrDefault().Days;
                        statement.DueDate = acc.StartDate;
                        context.Statements.Add(statement);
                    }
                    else
                    {
                        int id = context.Statements.Where(x => x.Account.UserId == user.UserId).Max(x => x.StatementId);

                        Statement latestStatement = context.Statements.Where(x => x.StatementId == id).FirstOrDefault();

                        TimeSpan difference = DateTime.Now - (DateTime)latestStatement.DueDate;

                        // Make sure the existing unPaid statement doesn't fall within the 7 day period

                        //if (difference.Days >= (acc.Frequency.Days - 7) && difference.Days > 7)
                        if (latestStatement.IsPaid)
                        {
                            // Get Average of previous payments
                            decimal sumPayments = (decimal)context.Statements.Where(x => x.AccountId == acc.AccountId && x.IsPaid == true).AsEnumerable().Sum(x => x.PaidAmount);
                            int totalPayments = (int)context.Statements.Where(x => x.AccountId == acc.AccountId && x.IsPaid == true).Count();


                            Statement statement = new Statement();
                            statement.AccountId = acc.AccountId;
                            //statement.Balance = acc.Payment;
                            if (totalPayments != 0)
                                statement.Balance = (double)Math.Round(sumPayments / totalPayments, 2);
                            else
                                statement.Balance = latestStatement.Balance;
                            statement.IsPaid = false;
                            statement.CreationDate = DateTime.Now;
                            statement.PaidAmount = 0;
                            statement.PaidDate = null;

                            Frequency freq = context.Accounts.Where(x => x.AccountId == acc.AccountId).FirstOrDefault().Frequency;

                            int freqDays = context.Accounts.Where(x => x.AccountId == acc.AccountId).FirstOrDefault().Frequency.Days;
                            statement.DueDate = DateTime.Now.AddDays(freqDays);
                            context.Statements.Add(statement);

                            MessengerUtil messenger = new MessengerUtil();
                            messenger.SendToast(user, string.Format("New {0} Statement!", statement.Account.AccountName), "");
                        }
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                LogError(user, ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
                throw new Exception("Error Aging Account", ex);
            }
        }
Esempio n. 4
0
 public void SendToast(User user, string title, string subTitle)
 {
     try
     {
         MessengerUtil messenger = new MessengerUtil();
         messenger.SendToast(user, title, subTitle);
     }
     catch (ModelException ex)
     {
         CapitalError error = new CapitalError(ex);
         throw new FaultException<CapitalError>(error, error.Message);
     }
     catch (Exception)
     {
         return;
     }
 }
Esempio n. 5
0
 public void SendEmail(string fromUser, string subject, string message)
 {
     try
     {
         MessengerUtil messenger = new MessengerUtil();
         messenger.SendEmail(fromUser, subject, message);
     }
     catch (ModelException ex)
     {
         CapitalError error = new CapitalError(ex);
         throw new FaultException<CapitalError>(error, error.Message);
     }
     catch (Exception)
     {
         return;
     }
 }
Esempio n. 6
0
 public void SendTile(string name)
 {
     try
     {
         MessengerUtil messenger = new MessengerUtil();
         messenger.SendTile(name);
     }
     catch (ModelException ex)
     {
         CapitalError error = new CapitalError(ex);
         throw new FaultException<CapitalError>(error, error.Message);
     }
     catch (Exception)
     {
         return;
     }
 }
Esempio n. 7
0
 public void Register(Registration registration)
 {
     try
     {
         MessengerUtil messenger = new MessengerUtil();
         messenger.Register(registration);
     }
     catch (ModelException ex)
     {
         CapitalError error = new CapitalError(ex);
         throw new FaultException<CapitalError>(error, error.Message);
     }
     catch (Exception)
     {
         return;
     }
 }