public ViewResult Topup(int id)
        {
            var model = new Topup();

            model.Id = id;
            return(View("TopupForm", model));
        }
Example #2
0
        public ActionResult ChargingHist(int customerid)
        {
            int      rc;
            Customer customer = new Customer(customerid);

            Meter[] meters = Meter.GetMeters(new MeterParameters {
                UserId = customer.Id
            }, out rc);
            //  Topup[] topups = null;
            List <Topup> topups = new List <Topup>();

            //int c = 0;
            foreach (Meter meter in meters)
            {
                string  meterid = meter.Meterid;
                Topup[] topup   = Topup.GetTopups(new TopupParameters {
                    MeterId = meterid
                }, out rc);
                foreach (Topup topup1 in topup)
                {
                    topups.Add(topup1);
                }
                //  c++;
            }
            return(Content(JsonConvert.SerializeObject(new { result = "success", data = topups })));
        }
Example #3
0
            public async Task <Command> Handle(Command request, CancellationToken ct)
            {
                App.Log.Debug("Retrieving entities from db");

                var user = await _db.Users.ByIdAsync(request.UserId, ct);

                var provider = await _db.Providers.ByIdOrFailAsync(request.ProviderId, ct);

                App.Log.Debug("Creating and paying a new Topup");

                var topup = new Topup(request, user, provider);

                topup.Pay(_payPau, request.CreditCard);

                App.Log.Debug("Save db and enqueue job");

                await _db.AddSaving(topup);

                _jobs.PerformLater(new TopupComplete {
                    TopupId = topup.Id
                });

                App.Log.Information($"Successful created Topup #{topup.Id}");

                return(request);
            }
        public ActionResult ReturnOTPFromMainPage(string Meterid, int customerid)
        {
            int      rc;
            Customer customer = new Customer(customerid);

            Meter[] meters = Meter.GetMeters(new MeterParameters {
                Meterid = Meterid
            }, out rc);
            //if (meters.Length == 0)
            //{
            //    return Content(JsonConvert.SerializeObject(new { result = "meter-not-valid" }));
            //}

            if (customer.Id == meters[0].UserId)
            {
                SMS sms = new SMS();
                sms.To_number = customer.Telephone;
                sms.Msg       = $"أهلا وسهلا بكك أنت تحاول الان استرجاع الكود الغير مشحون الخاص بك";
                string status = sms.Send();

                if (status == "OK")
                {
                    Topup[] topups = Topup.GetTopups(new TopupParameters {
                        MeterId = Meterid, Status = "0"
                    }, out rc);
                    return(Content(JsonConvert.SerializeObject(new { result = "success", data = topups })));
                }
                else
                {
                    return(Content(JsonConvert.SerializeObject(new { result = "error" })));
                }
            }

            else if (customer.Id != meters[0].UserId)
            {
                Customer customer1 = new Customer(meters[0].UserId.Value);

                SMS sms = new SMS();
                sms.To_number = customer1.Telephone;
                sms.Msg       = $"يحاول {customer.Name} استرجاع الكود الغير مشحون الخاص بك";
                string status = sms.Send();

                if (status == "OK")
                {
                    Topup[] topups = Topup.GetTopups(new TopupParameters {
                        MeterId = Meterid, Status = "0"
                    }, out rc);
                    return(Content(JsonConvert.SerializeObject(new { result = "success", data = topups })));
                }
                else
                {
                    return(Content(JsonConvert.SerializeObject(new { result = "error" })));
                }
            }

            else
            {
                return(Content(JsonConvert.SerializeObject(new { result = "error" })));
            }
        }
        public ActionResult Monthlycharging(DateTime fromdate, DateTime todate)
        {
            int      rc;
            Customer customer = (Session["customer"] as Customer);

            Meter[] meters = Meter.GetMeters(new MeterParameters {
                UserId = customer.Id
            }, out rc);

            if (Session["customer"] != null)
            {
                Topup[] topups = Topup.GetTopups(new TopupParameters {
                    fromdate = fromdate, todate = todate, MeterId = meters[0].Meterid
                }, out rc);

                decimal?amount = 0;
                decimal?count  = 0;
                foreach (Topup topup in topups)
                {
                    amount += topup.Amount;
                    count  += 1;
                }
                ViewBag.amount = amount;
                ViewBag.count  = count;
            }
            return(View());
        }
Example #6
0
        public ActionResult ChargeHist(DateTime fromdate, DateTime todate, int customerid)
        {
            int      rc;
            Customer customer = new Customer(customerid);

            Meter[] meters = Meter.GetMeters(new MeterParameters {
                UserId = customer.Id
            }, out rc);

            List <Topup> topups1 = new List <Topup>();

            foreach (Meter meter in meters)
            {
                Topup[] topups = Topup.GetTopups(new TopupParameters {
                    fromdate = fromdate, todate = todate, MeterId = meter.Meterid
                }, out rc);
                foreach (Topup topup in topups)
                {
                    topups1.Add(topup);
                }
            }

            decimal?amount = 0;
            decimal?count  = 0;

            foreach (Topup topup in topups1)
            {
                amount += topup.Amount;
                count  += 1;
            }
            decimal?result = decimal.Round(amount.Value / count.Value, 2);

            return(Content(JsonConvert.SerializeObject(new { result = "success", data = result })));
        }
Example #7
0
        public override async Task Given()
        {
            // arrange
            _topup   = _.MakeSaving <Topup>(m => m.Status = TopupStatus.Paid);
            _command = _.Make <TopupComplete>(m => m.TopupId = _topup.Id);

            // act
            await _.Send(_command);
        }
 public void Topup(Topup model)
 {
     foreach (var value in _context.Accounts)
     {
         if (value.Id == model.Id)
         {
             value.Balance += model.Balance;
         }
     }
     _context.SaveChanges();
 }
Example #9
0
        public void Topup_complete()
        {
            // arrange
            var topup = new Topup();

            // act
            topup.Complete();

            // assert
            topup.Status.ShouldBe(TopupStatus.Completed);
        }
 public ActionResult TopupForm(Topup model)
 {
     if (ModelState.IsValid)
     {
         _accountRepository.Topup(model);
         TempData["MsgChangeStatus"] = "You are successfully topup account";
         return(RedirectToAction("Index", "Account"));
     }
     else
     {
         return(View("TopupForm", model));
     }
 }
 public ActionResult ChargeMeter(int id)
 {
     if (Session["employee"] == null)
     {
         return(RedirectToAction("index", "Employees"));
     }
     else
     {
         Topup topup = new Topup(id);
         topup.Charged();
         return(RedirectToAction("Charged", "Topups"));
     }
 }
        public ActionResult Search(string MeterId)
        {
            int rc;

            if (MeterId != null)
            {
                Topup[] topups = Topup.GetTopups(new TopupParameters {
                    MeterId = MeterId
                }, out rc);
                ViewBag.topups = topups;
            }
            return(View());
        }
Example #13
0
        public async Task <IActionResult> OnPostAsync()
        {
            return(await Topup.ProcessAsync(ModelState, nameof(Topup),
                                            async() =>
            {
                var incomeType = await _incomeTypeQueries.GetByName(Topup.IncomeType);
                var account = await _accountQueries.GetByName(Topup.AccountName);
                await _accountCommands.Topup(new BusinessLogic.Model.Accounts.TopupAccountModel
                {
                    Correction = Topup.Correcting,
                    AccountId = account.Id,
                    IncomeTypeId = incomeType?.Id,
                    AddIncomeTypeName = incomeType == null ? Topup.IncomeType : null,
                    TopupDate = Topup.TopupDate.ParseDtFromStandardString(),
                    Amount = Topup.Amount.ParseMoneyInvariant()
                });
                return RedirectToPage(Topup.ReturnPage);
            },

                                            async() =>
            {
                IncomeTypes = await _incomeTypeQueries.GetAll();
                Accounts = await _accountQueries.GetAll();
                return Page();
            },

                                            async vrList =>
            {
                if (!Topup.AccountName.IsNullOrEmpty())
                {
                    var account = await _accountQueries.GetByName(Topup.AccountName);
                    if (account == null)
                    {
                        vrList.Add(new ModelValidationResult(nameof(Topup.AccountName), "Нет такого счета"));
                    }
                }

                if (!Topup.IncomeType.IsNullOrEmpty())
                {
                    var incomeType = await _incomeTypeQueries.GetByName(Topup.IncomeType);
                    if (incomeType == null && !Topup.AddNonexistentIncomeType)
                    {
                        vrList.Add(new ModelValidationResult(nameof(Topup.IncomeType), "Нет такой статьи"));
                        SuggestAddIncomeType = true;
                        Topup.AddNonexistentIncomeType = true;
                    }
                }
            }));
        }
        public ActionResult ChargeMeterFromApp(int?OTP, int customerid) //this should reach the website button which charge the meter
        {
            int      rc;
            Customer customer = new Customer(customerid);

            Topup[] topup = Topup.GetTopups(new TopupParameters {
                OTP = OTP
            }, out rc);

            if (topup[0].Status == "0")
            {
                Meter[] meters = Meter.GetMeters(new MeterParameters {
                    Meterid = topup[0].MeterId
                }, out rc);

                if (customer.Id == meters[0].UserId)
                {
                    SMS sms = new SMS();
                    sms.To_number = customer.Telephone;
                    sms.Msg       = $"  أهلا وسهلا بك أنت تحاول الان شحن عدادك باستخدام موقعنا في الشركة ورقم الكود الذي يريد شحنه هو {OTP}";
                    string status = sms.Send();


                    if (status == "OK")
                    {
                        topup[0].Charged();

                        return(Content(JsonConvert.SerializeObject(new { result = "success" })));
                    }
                }

                else if (customer.Id != meters[0].UserId)
                {
                    Customer customer1 = new Customer(meters[0].UserId.Value);
                    SMS      sms       = new SMS();
                    sms.To_number = customer1.Telephone;
                    sms.Msg       = $"يحاول {customer.Name} شحن عدادك باستخدام موقعنا في الشركة ورقم الكود الذي يريد شحنه هو {OTP}";
                    string status = sms.Send();

                    if (status == "OK")
                    {
                        topup[0].Charged();

                        return(Content(JsonConvert.SerializeObject(new { result = "success" })));
                    }
                }
            }
            return(Content(JsonConvert.SerializeObject(new { result = "error" })));
        }
Example #15
0
        public ActionResult Charge_this_otp(int?otp)
        {
            if (Session["employee"] == null)
            {
                return(RedirectToAction("index", "Employees"));
            }
            else
            {
                int     rc;
                Topup[] topups = Topup.GetTopups(new TopupParameters {
                    OTP = otp
                }, out rc);
                topups[0].Charged();


                return(RedirectToAction("ShowOTP", "RequestOTPS", new { success = "charged" }));
            }
        }
Example #16
0
        public void Pay_topup()
        {
            // arrange
            var provider      = _.Make <Provider>(m => m.Amounts = "10,20,30");
            var command       = _.Make <TopupNew.Command>(m => m.Amount = 10);
            var user          = _.Make <User>();
            var paymentResult = _.Make <PayPauResult>();
            var topup         = new Topup(command, user, provider);

            _.Get <IPayPau>().Charge(command.CreditCard, command.Amount).Returns(paymentResult);

            // act
            topup.Pay(_.Get <IPayPau>(), command.CreditCard);

            // assert
            topup.PaymentId.ShouldBe(paymentResult.TransactionId);
            topup.Status.ShouldBe(TopupStatus.Paid);
        }
Example #17
0
        public void Create_new_topup()
        {
            // arrange
            var provider = _.Make <Provider>(m => m.Amounts = "10,20,30");
            var command  = _.Make <TopupNew.Command>(m => m.Amount = 10);
            var user     = _.Make <User>();

            // act
            var topup = new Topup(command, user, provider);

            // assert
            topup.Email.ShouldBe(user.Email);
            topup.Name.ShouldBe(user.Name);

            topup.Provider.ShouldBe(provider);
            topup.Amount.ShouldBe(command.Amount);
            topup.PhoneNumber.ShouldBe(command.PhoneNumber);

            topup.Status.ShouldBe(TopupStatus.Created);
        }
Example #18
0
 public ActionResult RequestOTP(string MeterId, int?Amount, string SerialNUM)
 {
     if (Session["employee"] == null)
     {
         return(RedirectToAction("index", "Employees"));
     }
     else
     {
         int   rc;
         Topup topup = new Topup();
         if (SerialNUM != null)
         {
             CashCard[] cashCard = CashCard.GetCashCards(new CashCardParameters {
                 SerialNumber = SerialNUM
             }, out rc);
             topup = new Topup(MeterId, Amount, cashCard[0].SerialNumber);
         }
         return(View(topup));
     }
 }
Example #19
0
        public ActionResult RequestOTP(Topup topup)
        {
            int?result = 0;

            if (ModelState.IsValid)
            { //checking model state
              //check whether id is already exists in the database or not

                result = topup.SaveData();

                if (result == 2)
                {
                    ModelState.AddModelError("SerialNUM", "this card is not valid ");
                    ViewBag.result = result;
                    return(View(topup));
                }
                else if (result == 4)
                {
                    ModelState.AddModelError("SerialNUM", "this card is not for this meter ");
                    ViewBag.result = result;
                    return(View(topup));
                }
                else if (result == 1)
                {
                    ViewBag.result = result;
                    return(RedirectToAction("ShowOTP", "RequestOTPS", new { otp = topup.OTP }));
                }
                else
                {
                    ModelState.AddModelError("Amount", "there is no suffecient mony in the card");
                    ViewBag.result = result;
                    return(View(topup));
                }
            }

            else
            {
                ViewBag.result = result;
                return(View(topup));
            }
        }
        //[HttpPost]
        //public ActionResult MonthlyCharge(Topup[] topups)
        //{
        //    //int? result = 0;
        //    if (ViewData.ModelState.IsValidField("meter id"))
        //    { //checking model state

        //        //check whether id is already exists in the database or not


        //        if (topups.Length == 0)
        //        {
        //            ModelState.AddModelError("MeterId", "meter not valid");
        //            return View(topups);
        //        }
        //        else {
        //            decimal? amount = 0;
        //            decimal? count = 0;
        //            foreach (Topup topup in topups)
        //            {
        //                amount += topup.Amount;
        //                count += 1;
        //            }
        //            ViewBag.amount = amount;
        //            ViewBag.count = count;
        //            return View(topups);
        //        }
        //    }

        //    else
        //    {
        //        //ModelState.AddModelError("MeterId", "meter must entered");
        //        return View(topups);
        //    }

        //}

        public ActionResult MonthlyCharge(DateTime?fromdate, DateTime?todate, string MeterId)
        {
            if (Session["employee"] == null)
            {
                return(RedirectToAction("index", "Employees"));
            }
            else
            {
                if (ViewData.ModelState.IsValidField("MeterId") == false && fromdate != null && todate != null)
                {
                    ModelState.AddModelError("MeterId", "meter id is required");
                    return(View());
                }
                if (ViewData.ModelState.IsValidField("MeterId") == false && fromdate == null && todate == null)
                {
                    ModelState.AddModelError("MeterId", "meter id is required");
                    int both = 0;
                    ViewBag.both = both;
                    return(View());
                }
                if (ViewData.ModelState.IsValidField("MeterId") == false && fromdate != null && todate == null)
                {
                    ModelState.AddModelError("MeterId", "meter id is required");
                    int to = 0;
                    ViewBag.to = to;
                    return(View());
                }
                if (ViewData.ModelState.IsValidField("MeterId") == false && fromdate == null && todate != null)
                {
                    ModelState.AddModelError("MeterId", "meter id is required");
                    int from = 0;
                    ViewBag.from = from;
                    return(View());
                }
                if (ViewData.ModelState.IsValidField("MeterId") == true && fromdate == null && todate == null)
                {
                    // ModelState.AddModelError("MeterId", "meter id is required");
                    int both = 0;
                    ViewBag.both = both;
                    return(View());
                }
                if (ViewData.ModelState.IsValidField("MeterId") == true && fromdate != null && todate == null)
                {
                    //ModelState.AddModelError("MeterId", "meter id is required");
                    int to = 0;
                    ViewBag.to = to;
                    return(View());
                }
                if (ViewData.ModelState.IsValidField("MeterId") == true && fromdate == null && todate != null)
                {
                    //ModelState.AddModelError("MeterId", "meter id is required");
                    int from = 0;
                    ViewBag.from = from;
                    return(View());
                }
                else if (ViewData.ModelState.IsValidField("MeterId") == true && fromdate != null && todate != null)

                {
                    //check whether id is already exists in the database or not
                    int     rc, count = 0;
                    Meter[] meters = Meter.GetMeters(new MeterParameters {
                    }, out rc);

                    foreach (Meter meter1 in meters)
                    {
                        if (MeterId == meter1.Meterid)
                        {
                            count = 1;
                        }
                    }

                    if (count == 1)
                    {
                        Topup[] topups = Topup.GetMonthlyTopups(new TopupParameters {
                            fromdate = fromdate, todate = todate, MeterId = MeterId
                        }, out rc);

                        decimal?amount = 0;
                        decimal?countt = 0;
                        foreach (Topup topup in topups)
                        {
                            amount += topup.Amount;
                            countt += 1;
                        }
                        ViewBag.amount = amount;
                        ViewBag.count  = countt;
                        return(View());
                    }
                    else
                    {
                        if (MeterId != null)
                        {
                            int valid = 0;
                            ViewBag.valid = valid;
                            return(View());
                        }
                        else
                        {
                            return(View());
                        }
                    }
                }

                else
                {
                    return(View());
                }
            }
        }
        public ActionResult Save(int?id, string meterId, decimal?amount, string SerialNUM)
        {
            int rc;

            Meter[] meter = Meter.GetMeters(new MeterParameters {
                Meterid = meterId
            }, out rc);                                                                        //user of meter
            Customer customer = (Session["customer"] as Customer);

            CashCard [] cashCards = CashCard.GetCashCards(new CashCardParameters {
                SerialNumber = SerialNUM
            }, out rc);
            CashCard cashCard = new CashCard(cashCards[0].Id);

            Customer customer1 = new Customer(meter[0].UserId.Value);

            if (Session["customer"] != null)
            {
                if (customer.Id == meter[0].UserId && customer.CardId == cashCard.Id)//for himself from his card
                {
                    SMS sms = new SMS();
                    sms.To_number = customer.Telephone;
                    sms.Msg       = $"أهلا وسهلا بك أنت تقوم بشحن {amount} الى عدادك الان";
                    string status = sms.Send();
                    sms.SaveData();
                    if (status == "OK")
                    {
                        Topup topup = new Topup(id, meterId, amount, SerialNUM);
                        int   result;
                        result         = topup.SaveData();
                        ViewBag.result = result;
                    }
                    else
                    {
                        return(RedirectToAction("Save", "Tpoups"));
                    }
                }

                else if (customer.Id == meter[0].UserId && customer.CardId != cashCard.Id) //for himself from another card
                {
                    Customer[] customer2 = Customer.GetCustomers(new CustomerParameters {
                        CardId = cashCard.Id
                    }, out rc);
                    SMS sms = new SMS();
                    sms.To_number = customer2[0].Telephone;
                    sms.Msg       = $" يحاول {customer.Name} شحن عداده باستخدام البطاقة الخاصة بك بقيمة {amount}";
                    string status = sms.Send();
                    sms.SaveData();
                    if (status == "OK")
                    {
                        Topup topup = new Topup(id, meterId, amount, SerialNUM);
                        int   result;
                        result         = topup.SaveData();
                        ViewBag.result = result;
                    }
                    else
                    {
                        return(RedirectToAction("Save", "Topups"));
                    }
                }

                else if (customer.Id != meter[0].UserId && customer.CardId == cashCard.Id)//for another from his card
                {
                    SMS sms = new SMS();
                    sms.To_number = customer1.Telephone;
                    sms.Msg       = $"يحاول {customer.Name} شحن عدادك بقيمة {amount}";
                    string status = sms.Send();
                    sms.SaveData();

                    SMS sms1 = new SMS();
                    sms1.To_number = customer.Telephone;
                    sms1.Msg       = $"يحاول {customer1.Name} شحن عداده باستخدام بطاقتك بقيمة {amount}";
                    string status1 = sms1.Send();
                    sms1.SaveData();

                    if (status == "OK" && status1 == "OK")
                    {
                        Topup topup = new Topup(id, meterId, amount, SerialNUM);
                        int   result;
                        result         = topup.SaveData();
                        ViewBag.result = result;
                    }
                    else
                    {
                        return(RedirectToAction("Save", "Topups"));
                    }
                }


                else if (customer.Id != meter[0].UserId && customer.CardId != cashCard.Id && customer1.CardId != cashCard.Id)//for another from another card
                {
                    int        rrc;
                    Customer[] customer2 = Customer.GetCustomers(new CustomerParameters {
                        CardId = cashCard.Id
                    }, out rrc);

                    SMS sms = new SMS();
                    sms.To_number = customer2[0].Telephone;
                    sms.Msg       = $"يحاول {customer1.Name} شحن عداده بقيمة {amount} باستخدام بطاقتك";
                    string status = sms.Send();
                    sms.SaveData();

                    SMS sms1 = new SMS();
                    sms1.To_number = customer1.Telephone;
                    sms1.Msg       = $"يحاول {customer.Name} شحن عدادك بقيمة {amount} باستخدام بطاقة {customer2[0].Name}";
                    string status1 = sms1.Send();
                    sms1.SaveData();
                    if (status == "OK" && status1 == "OK")
                    {
                        Topup topup = new Topup(id, meterId, amount, SerialNUM);
                        int   result;
                        result         = topup.SaveData();
                        ViewBag.result = result;
                    }
                    else
                    {
                        return(RedirectToAction("Save", "Topups"));
                    }
                }
                else if (customer.Id != meter[0].UserId && customer.CardId != cashCard.Id && customer1.CardId == cashCard.Id)//for another from the another card
                {
                    SMS sms = new SMS();
                    sms.To_number = customer1.Telephone;
                    sms.Msg       = $"يحاول {customer.Name} شحن عدادك باستخدام بطاقتك";
                    string status = sms.Send();
                    sms.SaveData();

                    SMS sms1 = new SMS();
                    sms1.To_number = customer.Telephone;
                    sms1.Msg       = $"أهلا وسهلا بك أنت تحاول الان شحن عداد {customer1.Name} باستخدام بطاقته {customer1.CardId}";
                    string status1 = sms1.Send();
                    sms1.SaveData();

                    if (status == "OK" && status1 == "OK")
                    {
                        Topup topup = new Topup(id, meterId, amount, SerialNUM);
                        int   result;
                        result         = topup.SaveData();
                        ViewBag.result = result;
                    }
                    else
                    {
                        return(RedirectToAction("Save", "Topups"));
                    }
                }
                return(View());
            }
            else
            {
                return(RedirectToAction("Save", "Topups"));
            }
        }
        public ActionResult TransferOTP(int?SenderOTP, string MeterId, int Amount, int customerid)
        {
            int      rc;
            Customer customer = new Customer(customerid);

            Topup[] topups = Topup.GetTopups(new TopupParameters {
                OTP = SenderOTP
            }, out rc);                                                                       //get senderotp meterid
            if (topups.Length == 0)
            {
                return(Content(JsonConvert.SerializeObject(new { result = "otp-not-valid" })));
            }

            if (topups.Length != 0 && topups[0].Status == "1")
            {
                return(Content(JsonConvert.SerializeObject(new { result = "otp-charged" })));
            }
            Meter[] meters = Meter.GetMeters(new MeterParameters {
                Meterid = topups[0].MeterId
            }, out rc);                                                                                   //get meterid of otp
            if (meters.Length == 0)
            {
                return(Content(JsonConvert.SerializeObject(new { result = "meter-ofotp-not-valid" })));
            }

            Meter[] meters1 = Meter.GetMeters(new MeterParameters {
                Meterid = MeterId
            }, out rc);                                                                          // get userid will take the amount
            if (meters1.Length == 0)
            {
                return(Content(JsonConvert.SerializeObject(new { result = "meter-response-not-valid" })));
            }

            Customer customer1 = new Customer(meters1[0].UserId.Value);//get customer info


            if (customer.Id == meters[0].UserId)//otp for customer
            {
                SMS sms = new SMS();
                sms.To_number = customer.Telephone;
                sms.Msg       = $"أهلا وسلا بك في تطبيقنا أنت تحاول الان تحويل قيمة {Amount} الى حساب {customer1.Name} ";
                string status = sms.Send();


                SMS sms1 = new SMS();
                sms1.To_number = customer1.Telephone;
                sms1.Msg       = $"يحاول {customer.Name} تحويل قيمة {Amount} الى عدادك";
                string status1 = sms1.Send();

                if (status == "OK" && status1 == "OK")
                {
                    Transfer transfer = new Transfer(null, SenderOTP, MeterId, Amount);

                    Topup[] topupp = new Topup[] { };

                    topupp = transfer.SaveData();
                    if (topupp.Length != 0)
                    {
                        return(Content(JsonConvert.SerializeObject(new { result = "success", data = topupp })));
                    }
                    else
                    {
                        return(Content(JsonConvert.SerializeObject(new { result = "insufficient-amount", data = topups[0].Amount })));
                    }
                }
                else
                {
                    return(Content(JsonConvert.SerializeObject(new { result = "error" })));
                }
            }

            else if (customer.Id != meters[0].UserId)                      //otp not for user
            {
                Customer customer2 = new Customer(meters[0].UserId.Value); //get customer of otp
                SMS      sms       = new SMS();
                sms.To_number = customer2.Telephone;
                sms.Msg       = $"أهلا وسلا بك في تطبيقنا أنت تحاول الان تحويل قيمة {Amount} الي حساب {customer1.Name} ";
                string status = sms.Send();


                SMS sms1 = new SMS();
                sms1.To_number = customer1.Telephone;
                sms1.Msg       = $"يحاول {customer2.Name} تحويل قيمة {Amount} الى عدادك";
                string status1 = sms1.Send();

                if (status == "OK" && status1 == "OK")
                {
                    Transfer transfer = new Transfer(null, SenderOTP, MeterId, Amount);

                    Topup[] topupp = new Topup[] { };

                    topupp = transfer.SaveData();
                    if (topupp.Length != 0)
                    {
                        return(Content(JsonConvert.SerializeObject(new { result = "success", data = topupp })));
                    }
                    else
                    {
                        return(Content(JsonConvert.SerializeObject(new { result = "insufficient-amount", data = topups[0].Amount })));
                    }
                }
                else
                {
                    return(Content(JsonConvert.SerializeObject(new { result = "error" })));
                }
            }
            else
            {
                return(Content(JsonConvert.SerializeObject(new { result = "error" })));
            }
        }
Example #23
0
 public TopupCompletedMail(Topup topup)
 {
     _topup = topup;
 }
        public ActionResult RequestOTP(string MeterId, int?Amount, string SerialNumber, int customerid)
        //this should reach the website button which request OTP

        {
            int      rc;
            Customer customer = new Customer(customerid);

            Meter[] meters = Meter.GetMeters(new MeterParameters {
                Meterid = MeterId
            }, out rc);                                                                         //user of meter
            if (meters.Length == 0)
            {
                return(Content(JsonConvert.SerializeObject(new { result = "invalid-meter" })));
            }

            CashCard[] cashCards = CashCard.GetCashCards(new CashCardParameters {
                SerialNumber = SerialNumber
            }, out rc);                                                                                                  //cash card information
            if (cashCards.Length == 0)
            {
                return(Content(JsonConvert.SerializeObject(new { result = "invalid-cashcard" })));
            }

            Customer customer1 = null;

            if (meters != null)
            {
                customer1 = new Customer(meters[0].UserId.Value); //user id of meter id entered
            }

            if (customer.Id == meters[0].UserId && customer.CardId == cashCards[0].Id)//for himself from his card
            {
                SMS sms = new SMS();
                sms.To_number = customer.Telephone;
                sms.Msg       = $"أهلا وسهلا بك أنت تقوم بشحن {Amount} الى عدادك الان";
                string status = sms.Send();

                if (status == "OK")
                {
                    Topup topup = new Topup(null, MeterId, Amount, cashCards[0].SerialNumber);

                    int result;
                    result = topup.SaveDataForAPP();
                    if (result == 1)
                    {
                        return(Content(JsonConvert.SerializeObject(new { result = "success", data = topup })));
                    }
                    else
                    {
                        return(Content(JsonConvert.SerializeObject(new { result = "insuffecient-balance", data = cashCards[0].Amount })));
                    }
                }
            }

            else if (customer.Id == meters[0].UserId && customer.CardId != cashCards[0].Id) //for himself from another card
            {
                Customer[] customer2 = Customer.GetCustomers(new CustomerParameters {
                    CardId = cashCards[0].Id
                }, out rc);
                SMS sms = new SMS();
                sms.To_number = customer2[0].Telephone;
                sms.Msg       = $" يحاول {customer.Name} شحن عداده باستخدام البطاقة الخاصة بك بقيمة {Amount}";
                string status = sms.Send();

                if (status == "OK")
                {
                    Topup topup = new Topup(null, MeterId, Amount, cashCards[0].SerialNumber);
                    int   result;
                    result = topup.SaveDataForAPP();
                    if (result == 1)
                    {
                        return(Content(JsonConvert.SerializeObject(new { result = "success", data = topup })));
                    }
                    else
                    {
                        return(Content(JsonConvert.SerializeObject(new { result = "insuffecient-balance", data = cashCards[0].Amount })));
                    }
                }
            }

            else if (customer.Id != meters[0].UserId && customer.CardId == cashCards[0].Id)//for another from his card
            {
                SMS sms = new SMS();
                sms.To_number = customer1.Telephone;
                sms.Msg       = $"يحاول {customer.Name} شحن عدادك بقيمة {Amount}";
                string status = sms.Send();


                SMS sms1 = new SMS();
                sms1.To_number = customer.Telephone;
                sms1.Msg       = $"يحاول {customer1.Name} شحن عداده باستخدام بطاقتك بقيمة {Amount}";
                string status1 = sms1.Send();

                if (status == "OK" && status1 == "OK")
                {
                    Topup topup = new Topup(null, MeterId, Amount, cashCards[0].SerialNumber);
                    int   result;
                    result = topup.SaveDataForAPP();
                    if (result == 1)
                    {
                        return(Content(JsonConvert.SerializeObject(new { result = "success", data = topup })));
                    }
                    else
                    {
                        return(Content(JsonConvert.SerializeObject(new { result = "insuffecient-balance", data = cashCards[0].Amount })));
                    }
                }
            }


            else if (customer.Id != meters[0].UserId && customer.CardId != cashCards[0].Id && customer1.CardId != cashCards[0].Id)//for another from another card
            {
                int        rrc;
                Customer[] customer2 = Customer.GetCustomers(new CustomerParameters {
                    CardId = cashCards[0].Id
                }, out rrc);

                SMS sms = new SMS();
                sms.To_number = customer2[0].Telephone;
                sms.Msg       = $"يحاول {customer1.Name} شحن عداده بقيمة {Amount} باستخدام بطاقتك";
                string status = sms.Send();


                SMS sms1 = new SMS();
                sms1.To_number = customer1.Telephone;
                sms1.Msg       = $"يحاول {customer.Name} شحن عدادك بقيمة {Amount} باستخدام بطاقة {customer2[0].Name}";
                string status1 = sms1.Send();

                if (status == "OK" && status1 == "OK")
                {
                    Topup topup = new Topup(null, MeterId, Amount, cashCards[0].SerialNumber);
                    int   result;
                    result = topup.SaveDataForAPP();
                    if (result == 1)
                    {
                        return(Content(JsonConvert.SerializeObject(new { result = "success", data = topup })));
                    }
                    else
                    {
                        return(Content(JsonConvert.SerializeObject(new { result = "insuffecient-balance", data = cashCards[0].Amount })));
                    }
                }
            }
            else if (customer.Id != meters[0].UserId && customer.CardId != cashCards[0].Id && customer1.CardId == cashCards[0].Id)//for another from the another card
            {
                SMS sms = new SMS();
                sms.To_number = customer1.Telephone;
                sms.Msg       = $"يحاول {customer.Name} شحن عدادك باستخدام بطاقتك";
                string status = sms.Send();


                SMS sms1 = new SMS();
                sms1.To_number = customer.Telephone;
                sms1.Msg       = $"أهلا وسهلا بك أنت تحاول الان شحن عداد {customer1.Name} باستخدام بطاقته {customer1.CardId}";
                string status1 = sms1.Send();



                if (status == "OK" && status1 == "OK")
                {
                    Topup topup = new Topup(null, MeterId, Amount, cashCards[0].SerialNumber);
                    int   result;
                    result = topup.SaveDataForAPP();
                    if (result == 1)
                    {
                        return(Content(JsonConvert.SerializeObject(new { result = "success", data = topup })));
                    }
                    else
                    {
                        return(Content(JsonConvert.SerializeObject(new { result = "insuffecient-balance", data = cashCards[0].Amount })));
                    }
                }
            }

            return(Content(JsonConvert.SerializeObject(new { result = "error" })));
        }
        public ActionResult ChargeFromMainPage(int?OTP, string Meterid, int customerid)//chargr from mainpage
        {
            int      rc;
            Customer customer = new Customer(customerid);

            Meter[] meter = Meter.GetMeters(new MeterParameters {
                Meterid = Meterid
            }, out rc);                                                                        //meter information of entered meter
            if (meter.Length == 0)
            {
                return(Content(JsonConvert.SerializeObject(new { result = "invalid-meter" })));
            }

            Topup[] topup = Topup.GetTopups(new TopupParameters {
                OTP = OTP
            }, out rc);                                                                // top up that has this otp
            if (topup.Length == 0)
            {
                return(Content(JsonConvert.SerializeObject(new { result = "invalid-otp" })));
            }


            if (topup[0].Status == "0")
            {
                Meter[] meters = Meter.GetMeters(new MeterParameters {
                    Meterid = topup[0].MeterId
                }, out rc);                                                                                                     //meter information of otp enetered

                if (customer.Id == meters[0].UserId && customer.Id == meter[0].UserId && meter[0].Meterid == meters[0].Meterid) //customer meter as meter of otp as meter id entered
                {
                    SMS sms = new SMS();
                    sms.To_number = customer.Telephone;
                    sms.Msg       = $"  أهلا وسهلا بك أنت تحاول الان شحن عدادك باستخدام موقعنا في الشركة ورقم الكود الذي يريد شحنه هو {OTP}";
                    string status = sms.Send();


                    if (status == "OK")
                    {
                        topup[0].Charged();
                        return(Content(JsonConvert.SerializeObject(new { result = "success", data = topup[0].Amount })));
                    }
                }

                else if (customer.Id != meters[0].UserId && customer.Id == meter[0].UserId && meter[0].Meterid == meters[0].Meterid)//customer id not as  meter id of otp and meter id entered as customer id
                {
                    return(Content(JsonConvert.SerializeObject(new { result = "not-your-meterid" })));
                }
                else if (customer.Id != meters[0].UserId && customer.Id != meter[0].UserId && meter[0].Meterid == meters[0].Meterid)
                //if the customer try to charge to another
                {
                    //if (meters[0].UserId == meter[0].UserId)//if the meter of otp as meter id entered
                    //{
                    Customer customer1 = new Customer(meters[0].UserId.Value);
                    SMS      sms       = new SMS();
                    sms.To_number = customer1.Telephone;
                    sms.Msg       = $"يحاول {customer.Name} شحن عدادك باستخدام موقعنا في الشركة ورقم الكود الذي يريد شحنه هو {OTP}";
                    string status = sms.Send();

                    if (status == "OK")
                    {
                        topup[0].Charged();

                        return(Content(JsonConvert.SerializeObject(new { result = "success" })));
                    }
                }
                else if (meter[0].Meterid != meters[0].Meterid)
                {
                    return(Content(JsonConvert.SerializeObject(new { result = "not-compatible" })));
                }
            }
            return(Content(JsonConvert.SerializeObject(new { result = "otp-with-status-1" })));
        }
Example #26
0
 public TopupFailedMail(Topup topup)
 {
     _topup = topup;
 }
        public ActionResult Save(int?id, int?senderOTP, string meterId, decimal?amount)
        {
            int rc;

            Topup[] topup = Topup.GetTopups(new TopupParameters {
                OTP = senderOTP
            }, out rc);                                                                    //get senderotp meterid
            Meter[] meters = Meter.GetMeters(new MeterParameters {
                Meterid = topup[0].MeterId
            }, out rc);                                            //get meterid customer
            Customer customer = (Session["customer"] as Customer); //check if senderotp customer as session customer

            Meter[] meters1 = Meter.GetMeters(new MeterParameters {
                Meterid = meterId
            }, out rc);                                                 // get userid will take the amount
            Customer customer1 = new Customer(meters1[0].UserId.Value); //get customer info


            if (Session["customer"] != null)
            {
                if (customer.Id == meters[0].UserId)
                {
                    SMS sms = new SMS();
                    sms.To_number = customer.Telephone;
                    sms.Msg       = $"أهلا وسلا بك في تطبيقنا أنت تحاول الان تحويل قيمة {amount} الي حساب {customer1.Name} ";
                    string status = sms.Send();
                    sms.SaveData();

                    SMS sms1 = new SMS();
                    sms.To_number = customer1.Telephone;
                    sms.Msg       = $"يحاول {customer.Name} تحويل قيمة {amount} الى عدادك";
                    string status1 = sms1.Send();
                    sms1.SaveData();

                    if (status == "OK" && status1 == "OK")
                    {
                        Transfer transfer = new Transfer(id, senderOTP, meterId, amount);

                        Topup[] result = null;
                        result = transfer.SaveData();

                        ViewBag.result = result;
                    }
                }

                else if (customer.Id != meters[0].UserId)
                {
                    Customer customer2 = new Customer(meters[0].UserId.Value);
                    SMS      sms       = new SMS();
                    sms.To_number = customer2.Telephone;
                    sms.Msg       = $"أهلا وسلا بك في تطبيقنا أنت تحاول الان تحويل قيمة {amount} الي حساب {customer1.Name} ";
                    string status = sms.Send();
                    sms.SaveData();

                    SMS sms1 = new SMS();
                    sms.To_number = customer1.Telephone;
                    sms.Msg       = $"يحاول {customer2.Name} تحويل قيمة {amount} الى عدادك";
                    string status1 = sms1.Send();
                    sms1.SaveData();

                    if (status == "OK" && status1 == "OK")
                    {
                        Transfer transfer = new Transfer(id, senderOTP, meterId, amount);
                        Topup[]  result   = null;
                        result = transfer.SaveData();

                        ViewBag.result = result;
                    }
                }
                return(View());
            }
            else
            {
                return(RedirectToAction("Save", "Transfer"));
            }
        }
Example #28
0
        public ActionResult Charge(int?otp)
        {
            Customer customer = null;
            int      rc;

            Topup[] topup = Topup.GetTopups(new TopupParameters {
                OTP = otp
            }, out rc);
            if (topup[0].Status == "0")
            {
                if (Session["customer"] != null)
                {
                    Meter[] meters = Meter.GetMeters(new MeterParameters {
                        Meterid = topup[0].MeterId
                    }, out rc);
                    customer = (Session["customer"] as Customer);
                    if (customer.Id == meters[0].UserId)
                    {
                        SMS sms = new SMS();
                        sms.To_number = customer.Telephone;
                        sms.Msg       = $"  أهلا وسهلا بك أنت تحاول الان شحن عدادك باستخدام موقعنا في الشركة ورقم الكود الذي يريد شحنه هو {otp}";
                        string status = sms.Send();
                        sms.SaveData();
                        if (status == "OK")
                        {
                            topup[0].Charged();
                        }
                        else
                        {
                            return(RedirectToAction("index", "ChargeMeter", new { error = 4 }));
                        }
                    }

                    else if (customer.Id != meters[0].UserId)
                    {
                        Customer customer1 = new Customer(meters[0].UserId.Value);
                        SMS      sms       = new SMS();
                        sms.To_number = customer1.Telephone;
                        sms.Msg       = $"يحاول {customer.Name} شحن عدادك باستخدام موقنا في الشركة ورقم الكود الذي يريد شحنه هو {otp}";
                        string status = sms.Send();
                        sms.SaveData();
                        if (status == "OK")
                        {
                            topup[0].Charged();
                        }
                        else
                        {
                            return(RedirectToAction("index", "ChargeMeter", new { error = 4 }));
                        }
                    }
                }
                else if (Session["customer"] == null)
                {
                    return(RedirectToAction("index", "ChargeMeter", new { error = 2 }));
                }
                return(View());
            }
            else
            {
                return(RedirectToAction("index", "ChargeMeter", new { error = 3 }));
            }
        }
Example #29
0
        private async void client_GetInfoFinished(object sender, GetInfoCompletedArgs args)
        {
            switch (args.Canceled)
            {
            case true:
                Tools.Tools.SetProgressIndicator(false);
                break;

            case false:
                if (string.IsNullOrEmpty(args.Json))
                {
                    return;
                }
                if (!string.Equals(args.Json, "[]"))
                {
                    try
                    {
                        Topup = (_page == 1) ? JsonConvert.DeserializeObject <TopUp[]>(args.Json) : Topup.Concat(JsonConvert.DeserializeObject <TopUp[]>(args.Json));
                        await GetTopUps(_date1, _date2, ++_page);
                    }
                    catch (Exception)
                    {
                        Tools.Tools.SetProgressIndicator(false);
                        return;
                    }
                    return;
                }
                break;
            }
            OnGetInfoFinished(args);
        }