Пример #1
0
 public static TransfertP2p AcceptTransfertA2A(TransfertP2p tA2A, KoloAndroidEntities db, out string error)
 {
     error = "";
     if (TransfertVerification(tA2A))
     {
         if (tA2A.TransfertStatusCode != KoloConstants.Operation.Status.RECEIVE_PENDING.ToString())
         {
             TransfertP2p tmp = db.TransfertP2p.FirstOrDefault(t => t.IdTransfertP2p == tA2A.IdTransfertP2p);
             if (tA2A.Secret == tmp.Secret)
             {
                 if (tA2A.NeedsConfirmation)
                 {
                     return(AskConfirmationOfTransfertA2A(tA2A, db, out error));
                 }
                 if (!tA2A.NeedsConfirmation)
                 {
                     return(ConfirmTransfertA2A(tA2A, db, out error));
                 }
             }
             return(new TransfertP2p()
             {
                 IdTransfertP2p = -30, TransfertStatusCode = "Code Secret Erroné Veuillez Ressaisir le demander a l'expediteur "
             });
         }
         return(new TransfertP2p()
         {
             IdTransfertP2p = -20, TransfertStatusCode = "Le statut du transfert est inadequat pour une reception : " + tA2A.TransfertStatusCode
         });
     }
     return(new TransfertP2p()
     {
         IdTransfertP2p = -10, TransfertStatusCode = "Parametres du transfert sont non conformes"
     });
 }
Пример #2
0
        public static List <ExternalAccountHistory> GetExternalAccountsHistoriesGlobal(int idCustomer, out string error)
        {
            error = "";
            List <ExternalAccountHistory> externalAccountHistories = new List <ExternalAccountHistory>();
            KoloAndroidEntities           context = new KoloAndroidEntities();

            try
            {
                List <ExternalAccount> externalAccounts = GetExternalAccounts(idCustomer, out error);
                if (externalAccounts != null)
                {
                    foreach (ExternalAccount externalAccount in externalAccounts)
                    {
                        externalAccountHistories.AddRange(context.ExternalAccountHistories.Where(e => e.IdExternalAccount == externalAccount.IdExternalAccount).ToList());
                    }
                    context.SaveChanges();
                    context.Dispose();
                    return(externalAccountHistories);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                error = ExceptionHelper.GetExceptionMessage(ex);
            }
            return(null);
        }
Пример #3
0
        public static bool DoTopUp(TopUpDetails topUpDetails, out string error)
        {
            error = "";
            TopUp topUp = topUpDetails.GeneraTopUp();

            ExRMoneySvc.ExRMoneySoapClient exMoneyClient = new ExRMoneySvc.ExRMoneySoapClient();
            if (!CustomerHistoryHelper.CheckCustomerBalance(topUp.IdCustomer, Int32.Parse(topUp.Amount)))
            {
                error = "INSUFFISANT BANLANCE";
                return(false);
            }
            var result = exMoneyClient.SendAirTime(topUpDetails.SelectedPartner, topUpDetails.Amount, topUpDetails.Number);

            error = result.Error;
            if (result.Succes)
            {
                KoloAndroidEntities Context = new KoloAndroidEntities();
                Tuple <List <KoloNotification>, List <CustomerBalanceHistory> > tuple = OperationHelper.MakeOperation <TopUp>(topUp, Context, out error);
                Context.KoloNotifications.AddRange(tuple.Item1);
                Context.CustomerBalanceHistories.AddRange(tuple.Item2);
                Context.TopUps.Add(topUp);
                topUp.OpDate = DateTime.Now;
                try
                {
                    Context.SaveChanges();
                }
                catch (Exception ex)
                {
                    error = ExceptionHelper.GetExceptionMessage(ex);
                }
                Context.Dispose();
            }
            return(result.Succes);
        }
Пример #4
0
        private static List <string> GenerateNotificationsMessages <T>(T t, KoloAndroidEntities db)
        {
            List <string>     messages = new List <string>();
            RefOperationStatu statu    = null;

            if (t.GetType() == typeof(TransfertP2p))
            {
                var tmp = t as TransfertP2p;

                tmp.Sender   = db.Customers.Include("Person").FirstOrDefault(c => c.IdCustomer == tmp.IdSendingCustomer);
                tmp.Receiver = db.Customers.Include("Person").FirstOrDefault(c => c.IdCustomer == tmp.IdReceiverCustomer);
                statu        = db.RefOperationStatus.FirstOrDefault(s => s.OperationStatusCode == tmp.TransfertStatusCode);
                string senderMessage = "" + tmp.Sender.Person.Firstname + " " + tmp.Sender.Person.Lastname
                                       + "-»"
                                       + tmp.Receiver.Person.Firstname + " " + tmp.Receiver.Person.Lastname
                                       + " " + tmp.Amount + ".Ref " + tmp.Reference;
                string receiverMessage = " " + tmp.Receiver.Person.Firstname + " " + tmp.Receiver.Person.Lastname
                                         + "-»"
                                         + tmp.Sender.Person.Firstname + " " + tmp.Sender.Person.Lastname
                                         + " " + tmp.Amount + ".Ref " + tmp.Reference;
                if (statu.OperationStatusCode == KoloConstants.Operation.Status.COMPLETED.ToString())
                {
                    senderMessage   += " Balance:" + (tmp.Sender.Balance - tmp.Amount);
                    receiverMessage += " Balance:" + (tmp.Receiver.Balance + tmp.Amount);
                }
                if (statu.OperationStatusCode == KoloConstants.Operation.Status.RECEIVE_PENDING.ToString())
                {
                    senderMessage   += ".Wait Rcv Accept";
                    receiverMessage += ".Wait Your Accept";
                }
                if (statu.OperationStatusCode == KoloConstants.Operation.Status.CONFIRM_PENDING.ToString())
                {
                    senderMessage   += ".Wait Your Confirm";
                    receiverMessage += ".Wait Snd Confir";
                }
                messages.Add(senderMessage);
                messages.Add(receiverMessage);
            }
            if (t.GetType() == typeof(EneoBillPayment))
            {
                var tmp = t as EneoBillPayment;
                tmp.Customer = db.Customers.Include("Person").FirstOrDefault(c => c.IdCustomer == tmp.IdCustomer);
                string message = "Dear " + tmp.Customer.Person.Firstname + " " + tmp.Customer.Person.Lastname
                                 + " you paid ENEO bill " + tmp.BillNumber + " Reference " + tmp.Reference
                                 + " amount " + tmp.BillAmount;
                messages.Add(message);
            }
            if (t.GetType() == typeof(TopUp))
            {
                var tmp = t as TopUp;
                tmp.Customer        = db.Customers.Include("Person").FirstOrDefault(c => c.IdCustomer == tmp.IdCustomer);
                tmp.Customer.Person = db.People.FirstOrDefault(p => p.IdCustomer == tmp.IdCustomer);
                string message = "Dear " + tmp.Customer.Person.Firstname + " " + tmp.Customer.Person.Lastname
                                 + " you done TopUp for " + tmp.PhoneNumber + " amount " + tmp.Amount;
                messages.Add(message);
            }
            return(messages);
        }
Пример #5
0
        public static Customer DoRegistrationConfirmation(Registration registration, KoloAndroidEntities db, out string error)
        {
            var confirmationTime = DateTime.Now;

            error = "";
            var reg = db.Registrations.FirstOrDefault(r => r.IdRegistration == registration.IdRegistration);

            if (reg != null)
            {
                if (reg.RegistrationTokenExpiryDate.HasValue)
                {
                    if (reg.RegistrationToken.Equals(registration.RegistrationToken))
                    {
                        if (reg.RegistrationTokenExpiryDate.Value >= confirmationTime)
                        {
                            reg.RegistrationStatusCode  = "COMPLETED";
                            reg.RegistrationConfirmDate = DateTime.Now;
                            Customer customer = db.Customers.Include("Person").FirstOrDefault(c => c.IdRegistration == reg.IdRegistration);
                            if (customer == null)
                            {
                                customer = RegistrationHelper.CreateCustomer(reg);
                                customer.Registration = reg;
                                db.Customers.Add(customer);
                            }
                            try
                            {
                                db.SaveChanges();
                            }
                            catch (DbEntityValidationException e)
                            {
                                error  = ExceptionHelper.GetExceptionMessage(e);
                                error += string.Empty;
                            }
                            return(customer);
                        }
                        return(new Customer()
                        {
                            IdCustomer = -40
                        });
                    }
                    return(new Customer()
                    {
                        IdCustomer = -30
                    });
                }
                return(new Customer()
                {
                    IdCustomer = -20
                });
            }
            return(new Customer()
            {
                IdCustomer = -10
            });
        }
Пример #6
0
        public static bool DeleteLoginAttempt(int id, KoloAndroidEntities db)
        {
            var loginAttempt = db.LoginAttempts.FirstOrDefault(l => l.IdCustomer == id);

            if (loginAttempt == null)
            {
                return(false);
            }
            db.LoginAttempts.Remove(loginAttempt);
            db.SaveChanges();
            return(true);
        }
Пример #7
0
        public static int DoLogin(ref LoginAttempt loginAttempt, KoloAndroidEntities db, out string error)
        {
            error = "";
            var refResult = new RefResult()
            {
                ResultCode = "FAIL"
            };
            var loginTime  = DateTime.Now;
            var idCustomer = loginAttempt.IdCustomer;
            var customer   = db.Customers
                             .Include("MobileDevices").Include("Person").Include("Registration")
                             .FirstOrDefault(c => c.IdCustomer == idCustomer);

            if (customer != null)
            {
                var customerLogin = db.CustomerLogins.FirstOrDefault(c => c.IdCustomer == customer.IdCustomer);
                loginAttempt.LoginTime = loginTime;
                if (customerLogin != null)
                {
                    var mobile = db.MobileDevices.FirstOrDefault(md => md.IdMobileDevice == customer.IdCustomer);
                    if (MobileDeviceHelper.SameMobileIds(mobile, loginAttempt) == true)
                    {
                        if (PasswordHasher.VerifyPassword(loginAttempt, customerLogin))
                        {
                            loginAttempt.ResultCode = "SUCCESS";
                            loginAttempt.IdCustomer = customer.IdCustomer;
                            db.LoginAttempts.Add(loginAttempt);
                            try
                            {
                                db.SaveChanges();
                                refResult.ResultCode = "SUCCESS";
                                return(loginAttempt.IdLoginAttempt);
                            }
                            catch (Exception ex)
                            {
                                error = ExceptionHelper.GetExceptionMessage(ex);
                            }
                        }
                    }
                }
            }
            using (KoloAndroidEntities dbFail = new KoloAndroidEntities())
            {
                LoginAttempt la = new LoginAttempt()
                {
                    ResultCode = "FAIL",
                };
                dbFail.LoginAttempts.Add(la);
                dbFail.SaveChanges();
            }
            return(loginAttempt.IdLoginAttempt);
        }
Пример #8
0
 private static TransfertP2p GetTransfertP2p(TransfertP2p t, KoloAndroidEntities db)
 {
     return(db.TransfertP2p.FirstOrDefault(e => e.IdReceiverCustomer == t.IdReceiverCustomer &&
                                           e.IdSendingCustomer == t.IdSendingCustomer &&
                                           e.IdTransfertP2p == t.IdTransfertP2p &&
                                           e.IdTransfertScheduled == t.IdTransfertScheduled &&
                                           e.NeedsConfirmation == t.NeedsConfirmation &&
                                           e.Reference == t.Reference &&
                                           e.Secret == t.Secret &&
                                           e.Transfert2Cash == t.Transfert2Cash &&
                                           e.TransfertDate == t.TransfertDate &&
                                           e.TransfertStatusCode == t.TransfertStatusCode));
 }
Пример #9
0
        public static bool CheckCustomerBalance(int id, int amount)
        {
            var context = new KoloAndroidEntities();

            try
            {
                Customer c = context.Customers.FirstOrDefault(custm => custm.IdCustomer == id);
                return((c.Balance - amount) > 0);;
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #10
0
        public static List <ExternalAccount> GetExternalAccounts(int idCustomer, out string error)
        {
            error = "";
            var context = new KoloAndroidEntities();
            List <ExternalAccount> externalAccounts = new List <ExternalAccount>();

            try
            {
                externalAccounts = context.ExternalAccounts.Where(e => e.IdCustomer == idCustomer).ToList();
            }
            catch (Exception ex)
            {
                error = ExceptionHelper.GetExceptionMessage(ex);
            }
            return(externalAccounts);
        }
Пример #11
0
        public static ExternalAccount AddExternalAccount(ref ExternalAccount externalAccount, out string error)
        {
            error = "";
            KoloAndroidEntities context = new KoloAndroidEntities();

            try
            {
                context.ExternalAccounts.Add(externalAccount);
                context.SaveChanges();
                context.Dispose();
                return(externalAccount);
            }
            catch (Exception ex)
            {
                error = ExceptionHelper.GetExceptionMessage(ex);
            }
            return(null);
        }
Пример #12
0
        public static bool RemoveExternalAccount(ExternalAccount externalAccount, out string error)
        {
            error = "";
            KoloAndroidEntities context = new KoloAndroidEntities();

            try
            {
                var tmp = context.ExternalAccounts.Remove(externalAccount);
                context.SaveChanges();
                context.Dispose();
                return(true);
            }
            catch (Exception ex)
            {
                error = ExceptionHelper.GetExceptionMessage(ex);
            }
            return(false);
        }
Пример #13
0
        public static List <ExternalAccountHistory> GetExternalAccountsHistoriesSpecific(ExternalAccount externalAccount, out string error)
        {
            error = "";
            KoloAndroidEntities context = new KoloAndroidEntities();

            try
            {
                List <ExternalAccountHistory> externalAccountHistories = new List <ExternalAccountHistory>();
                externalAccountHistories = context.ExternalAccountHistories.Where(e => e.IdExternalAccount == externalAccount.IdExternalAccount).ToList();
                context.SaveChanges();
                context.Dispose();
                return(externalAccountHistories);
            }
            catch (Exception ex)
            {
                error = ExceptionHelper.GetExceptionMessage(ex);
            }
            return(null);
        }
Пример #14
0
        public static ExternalAccount UpdateExternalAccount(ExternalAccount externalAccount, out string error)
        {
            error = "";
            KoloAndroidEntities context = new KoloAndroidEntities();

            try
            {
                ExternalAccount tmp = context.ExternalAccounts.FirstOrDefault(e => e.IdExternalAccount == externalAccount.IdExternalAccount);
                tmp = externalAccount;
                context.SaveChanges();
                context.Dispose();
                return(tmp);
            }
            catch (Exception ex)
            {
                error = ExceptionHelper.GetExceptionMessage(ex);
            }
            return(null);
        }
Пример #15
0
 public static TransfertP2p ConfirmTransfertA2A(TransfertP2p tA2A, KoloAndroidEntities db, out string error)
 {
     error = "";
     if (TransfertVerification(tA2A))
     {
         if (tA2A.TransfertStatusCode != KoloConstants.Operation.Status.CONFIRM_PENDING.ToString())
         {
             try
             {
                 TransfertP2p t = db.TransfertP2p.FirstOrDefault(tP2P => tP2P.IdTransfertP2p == tA2A.IdTransfertP2p);
                 t.TransfertStatusCode = tA2A.TransfertStatusCode;
                 t.Sender              = db.Customers.FirstOrDefault(c => c.IdCustomer == t.IdSendingCustomer);
                 t.Receiver            = db.Customers.FirstOrDefault(c => c.IdCustomer == t.IdSendingCustomer);
                 t.TransfertStatusCode = KoloConstants.Operation.Status.COMPLETED.ToString();
                 Tuple <List <KoloNotification>, List <CustomerBalanceHistory> > tuple = OperationHelper.MakeOperation <TransfertP2p>(t, db, out error);
                 db.KoloNotifications.AddRange(tuple.Item1);
                 db.CustomerBalanceHistories.AddRange(tuple.Item2);
                 db.SaveChanges();
                 return(t);
             }
             catch (Exception ex)
             {
                 error = ExceptionHelper.GetExceptionMessage(ex);
             }
             return(new TransfertP2p()
             {
                 IdTransfertP2p = -30, TransfertStatusCode = error
             });
         }
         return(new TransfertP2p()
         {
             IdTransfertP2p = -20, TransfertStatusCode = "Le statut du transfert est inadequat pour une reception : " + tA2A.TransfertStatusCode
         });
     }
     return(new TransfertP2p()
     {
         IdTransfertP2p = -10, TransfertStatusCode = "Parametres du transfert sont non conformes"
     });
 }
Пример #16
0
 public static TransfertP2p AskConfirmationOfTransfertA2A(TransfertP2p tA2A, KoloAndroidEntities db, out string error)
 {
     error = "";
     try
     {
         TransfertP2p t = db.TransfertP2p.FirstOrDefault(tP2P => tP2P.IdTransfertP2p == tA2A.IdTransfertP2p);
         t.TransfertStatusCode = tA2A.TransfertStatusCode;
         Tuple <List <KoloNotification>, List <CustomerBalanceHistory> > tuple = OperationHelper.MakeOperation <TransfertP2p>(t, db, out error);
         db.KoloNotifications.AddRange(tuple.Item1);
         db.CustomerBalanceHistories.AddRange(tuple.Item2);
         db.SaveChanges();
         return(t);
     }
     catch (Exception ex)
     {
         error = ExceptionHelper.GetExceptionMessage(ex);
     }
     return(new TransfertP2p()
     {
         IdTransfertP2p = -30, TransfertStatusCode = error
     });
 }
Пример #17
0
        public static Registration DoRegistration(Registration registration, KoloAndroidEntities db, out string error)
        {
            error = "";
            try
            {
                if (!RegistrationHelper.RegistrationExists(registration.PhoneNumber, db))
                {
                    registration.RegistrationStatusCode = "NEEDCONFIRM";
                    registration.RegistrationDate       = DateTime.Now;

                    var token = RegistrationHelper.RandomString(4);
                    registration.RegistrationToken           = token.Substring(0, Math.Min(ExpirationDelay, token.Length));
                    registration.RegistrationTokenExpiryDate = DateTime.Now.AddMinutes(10);

                    db.Registrations.Add(registration);
                    db.SaveChanges();
                    return(registration);
                }
                else
                {
                    var oldRegistration = RegistrationHelper.GetRegistration(registration.PhoneNumber, db);
                    oldRegistration.RegistrationStatusCode = "NEEDCONFIRM";
                    db.SaveChanges();
                    return(oldRegistration);
                    //return new Registration() { IdRegistration = -10, RegistrationStatusCode = "Account arlready exists" };
                }
            }
            catch (Exception e)
            {
                error = ExceptionHelper.GetExceptionMessage(e);
            }
            var reg = new Registration()
            {
                IdRegistration = -100, RegistrationStatusCode = error
            };

            return(reg);
        }
Пример #18
0
 public void Refresh(KoloAndroidEntities db, out string error)
 {
     this.CurrencyList            = db.Currencies.AsNoTracking().ToList();
     this.RefAddressTypes         = db.RefAddressTypes.AsNoTracking().ToList();
     this.RefBillStatus           = db.RefBillStatus.AsNoTracking().ToList();
     this.RefBillTypes            = db.RefBillTypes.AsNoTracking().ToList();
     this.RefCustomerTypes        = db.RefCustomerTypes.AsNoTracking().ToList();
     this.RefExternalAccountTypes = db.RefExternalAccountTypes.AsNoTracking().ToList();
     this.RefGenders                 = db.RefGenders.AsNoTracking().ToList();
     this.RefGroupTypes              = db.RefGroupTypes.AsNoTracking().ToList();
     this.RefIndustryCategorys       = db.RefIndustryCategories.AsNoTracking().ToList();
     this.RefLoginStatus             = db.RefLoginStatus.AsNoTracking().ToList();
     this.RefMaritalStatus           = db.RefMaritalStatus.AsNoTracking().ToList();
     this.RefOperationStatus         = db.RefOperationStatus.AsNoTracking().ToList();
     this.RefOperationTypes          = db.RefOperationTypes.AsNoTracking().ToList();
     this.RefPartnerTypes            = db.RefPartnerTypes.AsNoTracking().ToList();
     this.RefPersonRelationshipTypes = db.RefPersonRelationshipTypes.AsNoTracking().ToList();
     this.RefProvisionStatus         = db.RefProvisionStatus.AsNoTracking().ToList();
     this.RefRegistrationStatus      = db.RefRegistrationStatus.AsNoTracking().ToList();
     this.RefResults                 = db.RefResults.AsNoTracking().ToList();
     this.RefTransfertStatus         = db.RefTransfertStatus.AsNoTracking().ToList();
     error = "";
 }
Пример #19
0
 public static TransfertP2p SendTransfertA2A(TransfertP2p tA2A, KoloAndroidEntities db, out string error)
 {
     error = "";
     if (TransfertVerification(tA2A))
     {
         try
         {
             tA2A.TransfertDate       = DateTime.Now;
             tA2A.TransfertStatusCode = KoloConstants.Operation.Status.RECEIVE_PENDING.ToString();
             tA2A.Reference           = OfficeHelper.GenerateUniqueId();
             Tuple <List <KoloNotification>, List <CustomerBalanceHistory> > tuple = OperationHelper.MakeOperation <TransfertP2p>(tA2A, db, out error);
             db.KoloNotifications.AddRange(tuple.Item1);
             db.CustomerBalanceHistories.AddRange(tuple.Item2);
             db.TransfertP2p.Add(tA2A);
             db.SaveChanges();
             return(tA2A);
         }
         catch (Exception e)
         {
             error = ExceptionHelper.GetExceptionMessage(e);
         }
     }
     return(null);
 }
Пример #20
0
 public static KoloWin.CustomerService.Model.KoloMadDetails DoSendMad(ref KoloWin.CustomerService.Model.KoloMadDetails koloMadDetails, out string error)
 {
     error = "";
     try
     {
         var Context = new KoloAndroidEntities();
         ExWebSvc4Mad.KoloMadDetails wsKoloMadDetails = new ExWebSvc4Mad.ExWebSvcSoapClient().SendKoloMad(koloMadDetails.WsKoloMadDetails());
         if (wsKoloMadDetails != null)
         {
             Model.KoloMadDetails.KoloMadDetailsFromWs(ref koloMadDetails, wsKoloMadDetails);
             TransferGravity transfertGravity = koloMadDetails.GenerateTransferGravity();
             Tuple <List <KoloNotification>, List <CustomerBalanceHistory> > tuple = OperationHelper.MakeOperation <TransferGravity>(transfertGravity, Context, out error);
             Context.KoloNotifications.AddRange(tuple.Item1);
             Context.CustomerBalanceHistories.AddRange(tuple.Item2);
             Context.TransferGravities.Add(transfertGravity);
             Context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         error = ExceptionHelper.GetExceptionMessage(ex);
     }
     return(koloMadDetails);
 }
Пример #21
0
        public static Tuple <List <KoloNotification>, List <CustomerBalanceHistory> > MakeOperation <T>(T t, KoloAndroidEntities db, out string error)
        {
            error = "";
            List <CustomerBalanceHistory> customerBalanceHistories = new List <CustomerBalanceHistory>();
            List <KoloNotification>       koloNotifications        = new List <KoloNotification>();

            if (t.GetType() == typeof(TransfertP2p))
            {
                var tmp = t as TransfertP2p;
                tmp.Sender = db.Customers.Include("Person").FirstOrDefault(c => c.IdCustomer == tmp.IdSendingCustomer);
                if (!CheckCustomerBalance(tmp.Sender, tmp.Amount))
                {
                    KoloNotification n = KoloNotifiactionHelper.UnsuffisantBalanceNotification(tmp.Sender, KoloConstants.Operation.Category.SENDA2A);
                    koloNotifications.Add(n);
                }
                else
                {
                    if (tmp.TransfertStatusCode == KoloConstants.Operation.Status.COMPLETED.ToString())
                    {
                        customerBalanceHistories = CustomerHistoryHelper.GenerateCustomerHistories <TransfertP2p>(tmp, db, out error);
                    }
                    koloNotifications = KoloNotifiactionHelper.GenerateNotification <TransfertP2p>(tmp, KoloConstants.Operation.Category.SENDA2A, db, out error);
                }
            }
            else if (t.GetType() == typeof(EneoBillPayment))
            {
                var tmp = t as EneoBillPayment;
                tmp.Customer = db.Customers.Include("Person").FirstOrDefault(c => c.IdCustomer == tmp.IdCustomer);
                if (!CheckCustomerBalance(tmp.Customer, tmp.BillAmount))
                {
                    KoloNotification n = KoloNotifiactionHelper.UnsuffisantBalanceNotification(tmp.Customer, KoloConstants.Operation.Category.PAYENEOBILL);
                    koloNotifications.Add(n);
                }
                else
                {
                    customerBalanceHistories = CustomerHistoryHelper.GenerateCustomerHistories <EneoBillPayment>(tmp, db, out error);
                    koloNotifications        = KoloNotifiactionHelper.GenerateNotification <EneoBillPayment>(tmp, KoloConstants.Operation.Category.SENDMAD, db, out error);
                }
            }
            else if (t.GetType() == typeof(TopUp))
            {
                var tmp = t as TopUp;
                tmp.Customer = db.Customers.Include("Person").FirstOrDefault(c => c.IdCustomer == tmp.IdCustomer);

                if (!CheckCustomerBalance(tmp.Customer, Int32.Parse(tmp.Amount)))
                {
                    switch (tmp.OperatorCode)
                    {
                    case nameof(KoloConstants.Operation.Category.ORANGE):
                        KoloNotification n = KoloNotifiactionHelper.UnsuffisantBalanceNotification(tmp.Customer, KoloConstants.Operation.Category.ORANGE);
                        koloNotifications.Add(n);
                        break;

                    case nameof(KoloConstants.Operation.Category.MTN):
                        n = KoloNotifiactionHelper.UnsuffisantBalanceNotification(tmp.Customer, KoloConstants.Operation.Category.MTN);
                        koloNotifications.Add(n);
                        break;

                    case nameof(KoloConstants.Operation.Category.NEXTTEL):
                        n = KoloNotifiactionHelper.UnsuffisantBalanceNotification(tmp.Customer, KoloConstants.Operation.Category.NEXTTEL);
                        koloNotifications.Add(n);
                        break;

                    case nameof(KoloConstants.Operation.Category.YOOMEE):
                        n = KoloNotifiactionHelper.UnsuffisantBalanceNotification(tmp.Customer, KoloConstants.Operation.Category.YOOMEE);
                        koloNotifications.Add(n);
                        break;

                    case nameof(KoloConstants.Operation.Category.CAMTEL):
                        n = KoloNotifiactionHelper.UnsuffisantBalanceNotification(tmp.Customer, KoloConstants.Operation.Category.CAMTEL);
                        koloNotifications.Add(n);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    customerBalanceHistories = CustomerHistoryHelper.GenerateCustomerHistories <TopUp>(tmp, db, out error);
                    switch (tmp.OperatorCode)
                    {
                    case nameof(KoloConstants.Operation.Category.ORANGE):
                        koloNotifications = KoloNotifiactionHelper.GenerateNotification <TopUp>(tmp, KoloConstants.Operation.Category.ORANGE, db, out error);
                        break;

                    case nameof(KoloConstants.Operation.Category.MTN):
                        koloNotifications = KoloNotifiactionHelper.GenerateNotification <TopUp>(tmp, KoloConstants.Operation.Category.MTN, db, out error);
                        break;

                    case nameof(KoloConstants.Operation.Category.NEXTTEL):
                        koloNotifications = KoloNotifiactionHelper.GenerateNotification <TopUp>(tmp, KoloConstants.Operation.Category.NEXTTEL, db, out error);
                        break;

                    case nameof(KoloConstants.Operation.Category.YOOMEE):
                        koloNotifications = KoloNotifiactionHelper.GenerateNotification <TopUp>(tmp, KoloConstants.Operation.Category.YOOMEE, db, out error);
                        break;

                    case nameof(KoloConstants.Operation.Category.CAMTEL):
                        koloNotifications = KoloNotifiactionHelper.GenerateNotification <TopUp>(tmp, KoloConstants.Operation.Category.CAMTEL, db, out error);
                        break;

                    default:
                        break;
                    }
                }
            }
            else if (t.GetType() == typeof(TransferGravity))
            {
                var tmp = t as TransferGravity;
                tmp.Customer = db.Customers.Include("Person").FirstOrDefault(c => c.IdCustomer == tmp.KoloSenderId);
                if (!CheckCustomerBalance(tmp.Customer, tmp.Amount))
                {
                    KoloNotification n = KoloNotifiactionHelper.UnsuffisantBalanceNotification(tmp.Customer, KoloConstants.Operation.Category.SENDMAD);
                    koloNotifications.Add(n);
                }
                else
                {
                    customerBalanceHistories = CustomerHistoryHelper.GenerateCustomerHistories <TransferGravity>(tmp, db, out error);
                    koloNotifications        = KoloNotifiactionHelper.GenerateNotification <TransferGravity>(tmp, KoloConstants.Operation.Category.SENDMAD, db, out error);
                }
            }

            var tuple = new Tuple <List <KoloNotification>, List <CustomerBalanceHistory> >(koloNotifications, customerBalanceHistories);

            return(tuple);
        }
Пример #22
0
 public static Registration GetRegistration(string telephone, KoloAndroidEntities db)
 {
     return(db.Registrations.FirstOrDefault(r => r.PhoneNumber == telephone));
 }
Пример #23
0
 public static bool RegistrationExists(int id, KoloAndroidEntities db)
 {
     return(db.Registrations.Any(e => e.IdRegistration == id));
 }
Пример #24
0
 private static bool TransfertP2pExists(int idSender, int idReceiver, int amount, KoloAndroidEntities db)
 {
     return(db.TransfertP2p.Count(e => e.IdSendingCustomer == idSender && e.IdReceiverCustomer == idReceiver && e.Amount == amount) > 0);
 }
Пример #25
0
 public static bool RegistrationExists(string telephone, KoloAndroidEntities db)
 {
     return(db.Registrations.Any(r => r.PhoneNumber == telephone));
 }
Пример #26
0
        private static List <KoloNotification> FillNotifications <T>(T t, ref List <KoloNotification> ns, KoloAndroidEntities db)
        {
            List <string> titles     = GenerateNotificationsTitles(t);
            List <string> messages   = GenerateNotificationsMessages(t, db);
            List <string> categories = GenerateNotificationsCategories(t);

            foreach (KoloNotification notification in ns)
            {
                notification.Title        = titles[ns.IndexOf(notification)];
                notification.Message      = messages[ns.IndexOf(notification)];
                notification.Category     = categories[ns.IndexOf(notification)];
                notification.CreationDate = DateTime.Now;
                notification.Readed       = false;
                notification.ExpiryDate   = DateTime.Now.AddDays(3);
            }
            return(ns);
        }
Пример #27
0
 public static bool CustomerLoginExists(int id, KoloAndroidEntities db)
 {
     return(db.CustomerLogins.Count(e => e.IdCustomer == id) > 0);
 }
Пример #28
0
 public static bool LoginAttemptExists(int id, KoloAndroidEntities db)
 {
     return(db.LoginAttempts.Count(e => e.IdLoginAttempt == id) > 0);
 }
Пример #29
0
        public static List <KoloNotification> GenerateNotification <T>(T t, KoloConstants.Operation.Category category, KoloAndroidEntities db, out string error)
        {
            error = "";
            List <KoloNotification> notifications = new List <KoloNotification>();

            if (t.GetType() == typeof(TransfertP2p))
            {
                var tmp = t as TransfertP2p;
                KoloNotification senderNotification   = new KoloNotification();
                KoloNotification recieverNotification = new KoloNotification();

                senderNotification.IdCustomer   = tmp.IdSendingCustomer;
                recieverNotification.IdCustomer = (int)tmp.IdReceiverCustomer;

                notifications.Add(senderNotification);
                notifications.Add(recieverNotification);

                FillNotifications(tmp, ref notifications, db);
            }
            else if (t.GetType() == typeof(EneoBillPayment))
            {
                var tmp = t as EneoBillPayment;
                KoloNotification notification = new KoloNotification();

                notification.IdCustomer = tmp.IdCustomer;

                notifications.Add(notification);

                FillNotifications(tmp, ref notifications, db);
            }
            else if (t.GetType() == typeof(TopUp))
            {
                var tmp = t as TopUp;
                KoloNotification notification = new KoloNotification();

                notification.IdCustomer = tmp.IdCustomer;

                notifications.Add(notification);

                FillNotifications(tmp, ref notifications, db);
            }
            return(notifications);
        }
Пример #30
0
        public static List <CustomerBalanceHistory> GenerateCustomerHistories <T>(T t, KoloAndroidEntities db, out string error)
        {
            List <CustomerBalanceHistory> customerBalanceHistories = new List <CustomerBalanceHistory>();

            error = "";
            if (t.GetType() == typeof(TransfertP2p))
            {
                var temp = t as TransfertP2p;

                if (temp.Sender == null)
                {
                    temp.Sender = db.Customers.FirstOrDefault(c => c.IdCustomer == temp.IdSendingCustomer);
                }
                if (temp.Receiver == null)
                {
                    temp.Receiver = db.Customers.FirstOrDefault(c => c.IdCustomer == temp.IdReceiverCustomer);
                }
                CustomerBalanceHistory senderBalanceHistory   = CreateCustomerHistory(temp.Sender, KoloConstants.Operation.Category.SENDA2A, KoloConstants.Operation.BalanceUpdateDirection.REMOVE, temp.Amount, out error);
                CustomerBalanceHistory recieverBalanceHistory = CreateCustomerHistory(temp.Sender, KoloConstants.Operation.Category.RECVA2A, KoloConstants.Operation.BalanceUpdateDirection.ADD, temp.Amount, out error);
                customerBalanceHistories.Add(recieverBalanceHistory);
                customerBalanceHistories.Add(senderBalanceHistory);
            }
            else if (t.GetType() == typeof(EneoBillPayment))
            {
                var temp = t as EneoBillPayment;
                if (temp.Customer == null)
                {
                    temp.Customer = db.Customers.FirstOrDefault(c => c.IdCustomer == temp.IdCustomer);
                }

                CustomerBalanceHistory eneoBalanceHistory = CreateCustomerHistory(temp.Customer, KoloConstants.Operation.Category.PAYENEOBILL, KoloConstants.Operation.BalanceUpdateDirection.REMOVE, temp.BillAmount, out error);
                customerBalanceHistories.Add(eneoBalanceHistory);
            }
            else if (t.GetType() == typeof(TopUp))
            {
                var temp = t as TopUp;
                if (temp.Customer == null)
                {
                    temp.Customer = db.Customers.FirstOrDefault(c => c.IdCustomer == temp.IdCustomer);
                }

                CustomerBalanceHistory topUpBalanceHistory = CreateCustomerHistory(temp.Customer, KoloConstants.Operation.Category.ORANGE, KoloConstants.Operation.BalanceUpdateDirection.REMOVE, Int32.Parse(temp.Amount), out error);
                customerBalanceHistories.Add(topUpBalanceHistory);
            }
            else if (t.GetType() == typeof(TransferGravity))
            {
                var temp = t as TransferGravity;
                if (temp.Customer == null)
                {
                    temp.Customer = db.Customers.FirstOrDefault(c => c.IdCustomer == temp.KoloSenderId);
                }

                CustomerBalanceHistory madBalanceHistory = CreateCustomerHistory(temp.Customer, KoloConstants.Operation.Category.SENDMAD, KoloConstants.Operation.BalanceUpdateDirection.REMOVE, temp.Amount, out error);
                customerBalanceHistories.Add(madBalanceHistory);
            }


            return(customerBalanceHistories);
        }