Пример #1
0
        public bool SavePhoneList(PhoneList phoneList)
        {
            bool result      = true;
            int  phoneListId = 0;

            try
            {
                if (_loanEntities.PhoneList.Select(o => o.phone == phoneList.phone).Count() == 0)
                {
                    _loanEntities.PhoneList.Add(phoneList);
                    _loanEntities.SaveChanges();
                    phoneListId = phoneList.id;

                    if (phoneList.billData != null)
                    {
                        foreach (BillData billData in phoneList.billData)
                        {
                            billData.phoneListId = phoneListId;
                            _loanEntities.BillData.Add(billData);
                        }
                    }

                    if (phoneList.flowBill != null)
                    {
                        foreach (FlowBill flowBill in phoneList.flowBill)
                        {
                            flowBill.phoneListId = phoneListId;
                            _loanEntities.FlowBill.Add(flowBill);
                        }
                    }

                    if (phoneList.flowDetail != null)
                    {
                        foreach (FlowDetail flowDetail in phoneList.flowDetail)
                        {
                            flowDetail.phoneListId = phoneListId;
                            _loanEntities.FlowDetail.Add(flowDetail);
                        }
                    }

                    if (phoneList.messageData != null)
                    {
                        foreach (MessageData messageData in phoneList.messageData)
                        {
                            messageData.phoneListId = phoneListId;
                            _loanEntities.MessageData.Add(messageData);
                        }
                    }

                    if (phoneList.telData != null)
                    {
                        foreach (TelData telData in phoneList.telData)
                        {
                            telData.phoneListId = phoneListId;
                            _loanEntities.TelData.Add(telData);
                        }
                    }
                    _loanEntities.SaveChanges();
                }
            }
            catch (Exception e)
            {
                if (phoneListId != 0)
                {
                    _loanEntities.PhoneList.Remove(phoneList);
                }
            }
            return(result);
        }
Пример #2
0
        // Create PIN
        public async Task <bool> createPin(int id, string phone)
        {
            string _phone = "";
            bool   re     = false;

            if (id != 0)
            {
                var account = await db.tblAccounts.FirstOrDefaultAsync(a => a.acct_Deleted == null && a.acct_AccountID == id);

                if (account == null)
                {
                    throw new HttpException((int)HttpStatusCode.NotFound, "NotFound");
                }

                if (account.acct_PhoneNumber != phone)
                {
                    throw new HttpException(_ErrorCode, ConstantHelper.INVALID_PHONE);
                }
                _phone = account.acct_PhoneNumber;
            }
            else
            {
                tblAccount eAcc = db.tblAccounts.FirstOrDefault(x => x.acct_PhoneNumber.Trim() == phone.Trim());
                if (eAcc != null)
                {
                    throw new HttpException(_ErrorCode, ConstantHelper.PHONE_EXIST);
                }
                _phone = phone;
            }

            var loan = db.tblLoanRequests.FirstOrDefault(x => x.loan_AccountID == id &&
                                                         x.loan_Status.ToLower() != "rejected" && x.loan_Status.ToLower() != "approve" && x.loan_Balance > 0);

            if (loan != null)
            {
                throw new HttpException(_ErrorCode, ConstantHelper.ALREADY_REQUEST_LOAN);
            }


            var dt   = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            var ePin = db.tblPins.Where(x => x.pins_Deleted == null &&
                                        (id != 0 ? x.pins_AccountID == id : x.pins_Phone == phone) &&
                                        x.pins_Date >= dt
                                        ).OrderByDescending(o => o.pins_Date).Take(2);

            if (ePin != null)
            {
                DateTime dt1 = DateTime.Now;
                DateTime dt2 = DateTime.Now;
                int      i   = 0;
                foreach (var _pin in ePin)
                {
                    if (i == 0)
                    {
                        dt1 = _pin.pins_Date.Value;
                        var tt = DateTime.Now.Subtract(dt1).Minutes + (DateTime.Now.Subtract(dt1).Hours * 60);
                        if (tt > 30)
                        {
                            break;
                        }
                    }
                    if (i == 1)
                    {
                        dt2 = _pin.pins_Date.Value;
                    }
                    i++;
                }
                if (i > 1)
                {
                    var a = dt1.Subtract(dt2).Minutes;
                    var b = dt1.Subtract(dt1).Hours;
                    if (dt1.Subtract(dt2).Minutes + (dt1.Subtract(dt2).Hours * 60) < 30)
                    {
                        throw new HttpException(_ErrorCode, ConstantHelper.PENDING_SMS);
                        //var response = new HttpResponseMessage(HttpStatusCode.BadRequest);
                        //response.Content = new StringContent(ConstantHelper.PENDING_SMS);");
                    }
                }
            }
            tblPin pin = new tblPin();

            pin.pins_Date = DateTime.Now;
            if (id != 0)
            {
                pin.pins_AccountID = id;
            }
            else
            {
                pin.pins_Phone = phone;
            }
            pin.pins_Name = GeneratePIN();
            db.tblPins.Add(pin);
            db.SaveChanges();

            //
            if (!string.IsNullOrEmpty(_phone))
            {
                using (HttpClient client = new HttpClient())
                {
                    var res = await client.GetAsync("http://api.mekongsms.com/api/sendsms.aspx?username=xware@mekongnet&pass=ea6fac133e078db85a25de53ad18a0e3&sender=MarielBank&smstext=" +
                                                    "Dear valued customer,\nHere is your pin : " + pin.pins_Name +
                                                    "&isflash=0&gsm=" + _phone +
                                                    "\n\nMarielBank");

                    var status = await res.Content.ReadAsStringAsync();

                    if (status.Length > 0)
                    {
                        if (status.Substring(0, 1) == "0")
                        {
                            return(true);
                        }
                    }
                };
            }
            re = false;
            return(re);
        }