Exemplo n.º 1
0
        public IHttpActionResult GetCustomerPhone(int id)
        {
            CustomerPhone customerPhone = db.CustomerPhones.Find(id);

            if (customerPhone == null)
            {
                return(NotFound());
            }

            return(Ok(customerPhone));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 新增客户电话信息
        /// </summary>
        /// <param name="customerphone">实体</param>
        /// <param name="cancellationToken">验证</param>
        /// <returns></returns>
        public async Task <CustomerPhone> CreateAsync(CustomerPhone customerphone, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (customerphone == null)
            {
                throw new ArgumentNullException(nameof(customerphone));
            }
            Context.Add(customerphone);
            await Context.SaveChangesAsync(cancellationToken);

            return(customerphone);
        }
 private void showCustomerEdit()
 {
     CustomerName.Hide();
     customerNameTextBox.Show();
     CustomerEmail.Hide();
     customerEmailTextBox.Show();
     CustomerPhone.Hide();
     customerPhoneTextBox.Show();
     EditCustomerInfoButton.Hide();
     CancelChangeButton.Show();
     checkCustomerDataChanged(globalCustomerId);
 }
Exemplo n.º 4
0
        public IHttpActionResult PostCustomerPhone(CustomerPhone customerPhone)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CustomerPhones.Add(customerPhone);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = customerPhone.phoneId }, customerPhone));
        }
 private void hideCustomerEdit()
 {
     CustomerName.Show();
     customerNameTextBox.Hide();
     CustomerEmail.Show();
     customerEmailTextBox.Hide();
     CustomerPhone.Show();
     customerPhoneTextBox.Hide();
     EditCustomerInfoButton.Show();
     CancelChangeButton.Hide();
     AcceptChangeButton.Hide();
 }
Exemplo n.º 6
0
        public IHttpActionResult DeleteCustomerPhone(int id)
        {
            CustomerPhone customerPhone = db.CustomerPhones.Find(id);

            if (customerPhone == null)
            {
                return(NotFound());
            }

            db.CustomerPhones.Remove(customerPhone);
            db.SaveChanges();

            return(Ok(customerPhone));
        }
Exemplo n.º 7
0
 /// <summary>
 /// 修改客户电话信息
 /// </summary>
 /// <param name="customerphone"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public async Task UpdateAsync(CustomerPhone customerphone, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (customerphone == null)
     {
         throw new ArgumentNullException(nameof(customerphone));
     }
     Context.Attach(customerphone);
     Context.Update(customerphone);
     try
     {
         await Context.SaveChangesAsync(cancellationToken);
     }
     catch (DbUpdateConcurrencyException) { }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Saves the customer phone.
        /// </summary>
        /// <param name="customerPhone">The customer phone.</param>
        /// <returns></returns>
        public bool SaveCustomerPhone(CustomerPhone customerPhone)
        {
            using (var sqlConnection = GetOpenedSqlConnection2()) {
                var cmd = GetInsertCommand(customerPhone, sqlConnection.SqlConnection(), Tables.CustomerPhones);
                if (!cmd.HasValue)
                {
                    return(false);
                }

                using (var sqlCommand = cmd.GetValue()) {
                    return(ExecuteNonQueryAndLog(sqlCommand));
                }
            }
        }
Exemplo n.º 9
0
        public async Task <IActionResult> GetbyIdAsync([FromRoute] int customerNumber, [FromRoute] string id)
        {
            //TODO return not found error
            // var customerItem = await _customerContext.RetailCustomer.SingleOrDefaultAsync(i => i.Id == customerToUpdate.Id);

            // if (customerItem == null)
            // {
            //     return NotFound(new { Message = $"Item with id {customerToUpdate.Id} not found." });
            // }

            CustomerPhone customer = await _customerContext.CustomerPhone.Where(x => x.CustomerNumber == customerNumber && x.Id == id).SingleOrDefaultAsync();

            return(Ok(customer));
        }
Exemplo n.º 10
0
 /// <summary>
 /// Method that convert a CustomerPhoneEntity(Database) into CustomerPhone
 /// </summary>
 /// <param name="cus">CustomerPhoneEntity</param>
 /// <returns>CustomerPhone</returns>
 public CustomerPhone convertToEntity(CustomerPhoneEntity cus)
 {
     try
     {
         CustomerPhone cusPhone = new CustomerPhone();
         cusPhone.Id            = cus.Customer_Id;
         cusPhone.PhoneNumber   = cus.Phone_Number;
         cusPhone.MinuteBalance = cus.Minute_Balance;
         cusPhone.MinutesUsed   = cus.Minutes_Use;
         return(cusPhone);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 11
0
        public async Task <bool> Create(CustomerPhone CustomerPhone)
        {
            CustomerPhoneDAO CustomerPhoneDAO = new CustomerPhoneDAO();

            CustomerPhoneDAO.Id          = CustomerPhone.Id;
            CustomerPhoneDAO.CustomerId  = CustomerPhone.CustomerId;
            CustomerPhoneDAO.Phone       = CustomerPhone.Phone;
            CustomerPhoneDAO.PhoneTypeId = CustomerPhone.PhoneTypeId;
            DataContext.CustomerPhone.Add(CustomerPhoneDAO);
            await DataContext.SaveChangesAsync();

            CustomerPhone.Id = CustomerPhoneDAO.Id;
            await SaveReference(CustomerPhone);

            return(true);
        }
Exemplo n.º 12
0
        public async Task <CustomerPhone> CreateCustomerPhone(Customer customer, Phone phone)
        {
            var customerPhoneToCreate = new CustomerPhone
            {
                Customer = customer,
                Phone    = phone
            };

            customerPhoneToCreate.Created = DateTime.Now;

            await _context.CustomerPhones.AddAsync(customerPhoneToCreate);

            await _context.SaveChangesAsync();

            return(customerPhoneToCreate);
        }
Exemplo n.º 13
0
 private void btnBalance_Click(object sender, EventArgs e)
 {
     try
     {
         var cusp = new CustomerPhone {
             Id = Convert.ToInt32(txtBalId.Text), PhoneNumber = txtBalPnumber.Text
         };
         var json     = SerializationHelpers.SerializeJson(cusp);
         var resp     = ResponseCallService(json, "POST", "GetPhoneBalance");
         var userinfo = SerializationHelpers.DeserializeJson <Response>(resp);
         txtBalResponse.Text = "Balance ID Response: " + userinfo.idResponse + "\n Balance Response: " + userinfo.response + "\n Exception: " + userinfo.exception;
     }
     catch (Exception ex)
     {
         txtBalResponse.Text = "Oops... Something went wrong: \nException: " + ex.Message;
     }
 }
Exemplo n.º 14
0
        private static void UpdatePhone(Customer item, int order, string phone)
        {
            var housingPhone = item.Phones.SingleOrDefault(x => x.Order == order);

            if (housingPhone != null)
            {
                housingPhone.Number = phone;
            }
            else if (!string.IsNullOrEmpty(phone))
            {
                housingPhone = new CustomerPhone()
                {
                    Number = phone, Order = order
                };
                item.Phones.Add(housingPhone);
            }
        }
Exemplo n.º 15
0
        public async Task <bool> Update(CustomerPhone CustomerPhone)
        {
            CustomerPhoneDAO CustomerPhoneDAO = DataContext.CustomerPhone.Where(x => x.Id == CustomerPhone.Id).FirstOrDefault();

            if (CustomerPhoneDAO == null)
            {
                return(false);
            }
            CustomerPhoneDAO.Id          = CustomerPhone.Id;
            CustomerPhoneDAO.CustomerId  = CustomerPhone.CustomerId;
            CustomerPhoneDAO.Phone       = CustomerPhone.Phone;
            CustomerPhoneDAO.PhoneTypeId = CustomerPhone.PhoneTypeId;
            await DataContext.SaveChangesAsync();

            await SaveReference(CustomerPhone);

            return(true);
        }
Exemplo n.º 16
0
        public async Task <bool> ValidateId(CustomerPhone CustomerPhone)
        {
            CustomerPhoneFilter CustomerPhoneFilter = new CustomerPhoneFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = CustomerPhone.Id
                },
                Selects = CustomerPhoneSelect.Id
            };

            int count = await UOW.CustomerPhoneRepository.Count(CustomerPhoneFilter);

            if (count == 0)
            {
                CustomerPhone.AddError(nameof(CustomerPhoneValidator), nameof(CustomerPhone.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
Exemplo n.º 17
0
        public async Task <CustomerPhone> Delete(CustomerPhone CustomerPhone)
        {
            if (!await CustomerPhoneValidator.Delete(CustomerPhone))
            {
                return(CustomerPhone);
            }

            try
            {
                await UOW.CustomerPhoneRepository.Delete(CustomerPhone);

                await Logging.CreateAuditLog(new { }, CustomerPhone, nameof(CustomerPhoneService));

                return(CustomerPhone);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerPhoneService));
            }
            return(null);
        }
Exemplo n.º 18
0
        /// <summary>
        /// update the Customer Balance: CustomerPhone table
        /// </summary>
        /// <param name="cusPhone"></param>
        public void updBalance(CustomerPhone cusPhone)
        {
            try
            {
                var dbCtx = new CallMonitorModelEntities();
                CustomerPhoneEntity cPhone = dbCtx.CUSTOMER_PHONE.Where(c => c.Customer_Id == cusPhone.Id &&
                                                                        c.Phone_Number == cusPhone.PhoneNumber).FirstOrDefault();
                cPhone.Minute_Balance = cusPhone.MinuteBalance;
                cPhone.Minutes_Use    = cusPhone.MinutesUsed;

                using (dbCtx)
                {
                    dbCtx.Entry(cPhone).State = System.Data.EntityState.Modified;
                    dbCtx.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 19
0
        public async Task <CustomerPhone> Update(CustomerPhone CustomerPhone)
        {
            if (!await CustomerPhoneValidator.Update(CustomerPhone))
            {
                return(CustomerPhone);
            }
            try
            {
                var oldData = await UOW.CustomerPhoneRepository.Get(CustomerPhone.Id);

                await UOW.CustomerPhoneRepository.Update(CustomerPhone);

                CustomerPhone = await UOW.CustomerPhoneRepository.Get(CustomerPhone.Id);

                await Logging.CreateAuditLog(CustomerPhone, oldData, nameof(CustomerPhoneService));

                return(CustomerPhone);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerPhoneService));
            }
            return(null);
        }
 /// <summary>
 /// Retrieve the actual customer's balance and insert it into the database if the
 /// customer don't have a balance yet. otherwise the balance it is updated.
 /// </summary>
 /// <param name="valueProm">Balance value</param>
 private void getCustomerBalance(decimal valueProm)
 {
     try
     {
         Price p       = dataAccess.getPrice(Convert.ToInt32(1));
         var   balance = dataAccess.getBalance(cus.Id, cus.PhoneNumber);
         if (balance == null)
         {
             balance = new CustomerPhone {
                 Id = cus.Id, PhoneNumber = cus.PhoneNumber, MinuteBalance = ((recharge.Value + valueProm) / p.Prices), MinutesUsed = 0
             };
             var resBalance = dataAccess.customerPhoneBalance(balance);
         }
         else
         {
             balance.MinuteBalance += ((recharge.Value + valueProm) / p.Prices);
             dataAccess.updBalance(balance);
         }
     }
     catch (Exception ex)
     {
         throw new Exception("getCustomerBalance Error: " + ex.Message);
     }
 }
Exemplo n.º 21
0
 private async Task SaveReference(CustomerPhone CustomerPhone)
 {
 }
Exemplo n.º 22
0
    private static async Task FinishDetails()
    {
        var phone = new SubscriberPhone
        {
            Subscriber = _subscriber,
            Number     = "12345678901"
        };

        var address = new SubscriberAddress
        {
            Subscriber = _subscriber,
            Street     = "10 Hamilton St.",
            Apartment  = "2nd Floor",
            City       = "Staten Island",
            PostalCode = "10304",
            Latitude   = 40.788645,
            Longitude  = -73.9707,
            State      = _context.States.First(s => s.Code == "NY")
        };

        await _context.SubscriberPhones.AddAsync(phone);

        await _context.SubscriberAddresses.AddAsync(address);

        var bphone = new BranchPhone
        {
            Branch = _context.Branches.First(),
            Number = "12345678901"
        };

        var baddress = new BranchAddress
        {
            Branch     = _context.Branches.First(),
            Street     = "10 Hamilton St.",
            Apartment  = "2nd Floor",
            City       = "Staten Island",
            PostalCode = "10304",
            Latitude   = 40.788645,
            Longitude  = -73.9707,
            State      = _context.States.First(s => s.Code == "NY")
        };

        await _context.BranchPhones.AddAsync(bphone);

        await _context.BranchAddresses.AddAsync(baddress);

        var fphone = new FranchisePhone
        {
            Franchise = _context.Franchises.First(),
            Number    = "12345678901"
        };

        var faddress = new FranchiseAddress
        {
            Franchise  = _context.Franchises.First(),
            Street     = "10 Hamilton St.",
            Apartment  = "2nd Floor",
            City       = "Staten Island",
            PostalCode = "10304",
            Latitude   = 40.788645,
            Longitude  = -73.9707,
            State      = _context.States.First(s => s.Code == "NY")
        };

        await _context.FranchisePhones.AddAsync(fphone);

        await _context.FranchiseAddresses.AddAsync(faddress);


        var cphone = new CustomerPhone
        {
            Customer = _context.Customers.First(),
            Number   = "12345678901"
        };

        var caddress = new CustomerAddress
        {
            Customer   = _context.Customers.First(),
            Street     = "10 Hamilton St.",
            Apartment  = "2nd Floor",
            City       = "Staten Island",
            PostalCode = "10304",
            Latitude   = 40.788645,
            Longitude  = -73.9707,
            State      = _context.States.First(s => s.Code == "NY")
        };

        await _context.CustomerPhones.AddAsync(cphone);

        await _context.CustomerAddresses.AddAsync(caddress);

        await _context.SaveChangesAsync();
    }
Exemplo n.º 23
0
        /// <summary>
        /// Execute an incoming Call Request. Calculating:
        /// 1.Call Duration.
        /// 2.Call Cost.
        /// 3.Minutes Used.
        /// 4.Minutes Balance.
        /// </summary>
        /// <param name="data">Stream with Json Data; Object: Call Entity</param>
        /// <returns>Stream with Json Data; Object: Response Entity</returns>
        public Stream startPhoneCall(Stream data)
        {
            try
            {
                decimal callLast = 0;
                call = SerializationHelpers.DeserializeJson <Call>(data);

                cus = dataAccess.getCustomerPerPhone(call.PhoneNumber);

                cusPhone = dataAccess.getBalance(cus.Id, cus.PhoneNumber);
                if (cusPhone != null)
                {
                    if (!transValidations.validateMinLeft(cusPhone.MinuteBalance))
                    {
                        resp.idResponse = 0;
                        resp.response   = "Customer does not have minutes for making this call.";
                        resp.exception  = null;
                        return(SerializationHelpers.GenerateStreamFromString(SerializationHelpers.SerializeJson <Response>(resp)));
                    }
                }
                else
                {
                    resp.idResponse = 0;
                    resp.response   = "Customer does not have minutes for making this call.";
                    resp.exception  = null;
                    return(SerializationHelpers.GenerateStreamFromString(SerializationHelpers.SerializeJson <Response>(resp)));
                }

                Price p = dataAccess.getPrice(Convert.ToInt32(2));

                //Call simulation
                var makecall = new CallSimulatorMock();
                var callreq  = new CallSimulatorRequest {
                    toPhoneNumber = cus.PhoneNumber, fromPhoneNumber = call.DestinationNumber, startCall = DateTime.Now, minutesLet = cusPhone.MinuteBalance
                };
                var callresp = new CallSimulatorResponse();
                callresp = makecall.StartPhoneCall(callreq);

                TimeSpan duCall = BussinessOps.GetDurationCall(callresp);
                if (Convert.ToDecimal(duCall.TotalSeconds) >= (cusPhone.MinuteBalance * 60))
                {
                    callLast = cusPhone.MinuteBalance;
                    cusPhone.MinuteBalance = 0;
                    cusPhone.MinutesUsed   = callLast;
                    dataAccess.updBalance(cusPhone);
                }
                else
                {
                    callLast = Convert.ToDecimal(duCall.TotalSeconds);
                    cusPhone.MinuteBalance -= callLast / 60;
                    cusPhone.MinutesUsed   += callLast / 60;
                    dataAccess.updBalance(cusPhone);
                }

                var callCost = BussinessOps.GetCallCost(p.Prices, callLast);
                var c        = new Call {
                    Id = cus.Id, PhoneNumber = cus.PhoneNumber, DestinationNumber = call.DestinationNumber, InitialDatetime = callresp.startCall, FinalDatetime = callresp.endCall, Duration = callLast, Cost = callCost, State = callresp.answerType
                };
                var res = dataAccess.initPhoneCall(c);

                resp.idResponse = 0;
                resp.response   = "From Phone Number: " + cus.PhoneNumber + " \nTo from Phone Number: " + call.DestinationNumber + " \nStart Call DateTime: " + c.InitialDatetime.ToString() + " \nEndCall DateTime : " + c.FinalDatetime.ToString() +
                                  " \nCall Duration: " + c.Duration.ToString() + "sec. \n Call Cost: " + c.Cost + " \n Call State: " + callresp.answerDesc;
                resp.exception = null;
                return(SerializationHelpers.GenerateStreamFromString(SerializationHelpers.SerializeJson <Response>(resp)));
            }
            catch (Exception ex)
            {
                resp.idResponse = 400;
                resp.response   = "Transaction: PhoneCall; Customer does not Exist.";
                resp.exception  = ex.Message;
                return(SerializationHelpers.GenerateStreamFromString(SerializationHelpers.SerializeJson <Response>(resp)));
            }
        }
Exemplo n.º 24
0
        public async Task <bool> Delete(CustomerPhone CustomerPhone)
        {
            await DataContext.CustomerPhone.Where(x => x.Id == CustomerPhone.Id).DeleteFromQueryAsync();

            return(true);
        }
Exemplo n.º 25
0
        public void TestMethod1()
        {
            var wechatCoreDb = new WechatCoreDbContext(new Microsoft.EntityFrameworkCore.DbContextOptions <WechatCoreDbContext>());
            var memberDb     = new MemberDbContext(new Microsoft.EntityFrameworkCore.DbContextOptions <MemberDbContext>());
            var argsModel    = new BindCustomerPhoneByWxopenPhoneArgsModel()
            {
                EncryptedData = "Bbu3OZPldIdKPezC8druWzqZlIA5lhyDEFPpMR20vieOHUxIO+…xhv+IZaw1krTTqyXvikTO91cKGtfIPOBN0VbxIj2JshpsDQ==", Iv = "EPonbgT9+okCcL025u8boQ=="
            };
            var jwtFlag = "jwt";// User.Identity.Name;

            if (string.IsNullOrEmpty(argsModel.EncryptedData))
            {
                throw new ArgumentNullException("encryptedData");
            }
            var jwt = wechatCoreDb.GetSingleMemberLogin(jwtFlag);

            if (jwt == null)
            {
                throw new Exception("未找到登陆纪录");
            }
            var session_key = jwt.GetloginSettingValue <string>("sessionKey");
            var openId      = jwt.GetloginSettingValue <string>("openId");

            var json = Senparc.Weixin.WxOpen.Helpers.EncryptHelper.DecodeEncryptedData(session_key, argsModel.EncryptedData, argsModel.Iv);
            // _logger.LogInformation(json);

            var args = Newtonsoft.Json.JsonConvert.DeserializeObject <Senparc.Weixin.WxOpen.Entities.DecodedPhoneNumber>(json);

            var customerPhone = wechatCoreDb.Query <CustomerPhone>()
                                .Where(m => !m.IsDel)
                                .Where(m => m.Status == CustomerPhoneStatus.已绑定 && m.OpenId == openId)
                                .FirstOrDefault();

            if (customerPhone == null)
            {
                customerPhone = new CustomerPhone()
                {
                    OpenId = openId,
                    Phone  = args.phoneNumber,
                    Status = CustomerPhoneStatus.已绑定
                };
                wechatCoreDb.Add <CustomerPhone>(customerPhone);
                wechatCoreDb.SaveChanges();
            }

            //var email = $"{customerPhone.Phone}@phone";
            //var member = memberDb.Query<Member>()
            //    .Where(m => !m.IsDel)
            //    .Where(m => m.Email == email)
            //    .FirstOrDefault();

            //if (member == null)
            //{
            //    member = new Member()
            //    {
            //        Email = email,
            //        Password = CommonUtil.CreateNoncestr(8),
            //        Status = MemberStatus.正常,
            //        Truename = customerPhone.Phone,
            //        LastLoginTime = DateTime.Now,
            //        RegTime = DateTime.Now
            //    };

            //    memberDb.AddToMember(member);
            //    memberDb.SaveChanges();
            //}

            //改为使用MemberPhone
            var memberId = memberDb.GetMemberIdByMemberPhone(customerPhone.Phone);

            if (memberId <= 0)//说明没有手机绑定的会员,则新建一个
            {
                var member = new Member()
                {
                    Email         = $"{customerPhone.Phone}@phone",
                    Password      = CommonUtil.CreateNoncestr(8),
                    Status        = MemberStatus.正常,
                    Truename      = customerPhone.Phone,
                    LastLoginTime = DateTime.Now,
                    RegTime       = DateTime.Now
                };
                memberDb.AddToMember(member);
                var memberPhone = new MemberPhone()
                {
                    Member = member,
                    Phone  = customerPhone.Phone,
                    State  = MemberPhoneState.已绑定
                };
                memberDb.Add <MemberPhone>(memberPhone);
                memberDb.SaveChanges();

                memberId = member.Id;
            }

            jwt.MemberId = memberId;
            wechatCoreDb.SaveChanges();
        }
Exemplo n.º 26
0
        public async Task <IActionResult> UpdateAsync([FromRoute] int customerNumber, [FromBody] CustomerPhone phoneToUpdate)
        {
            // var customerItem = await _customerContext.RetailCustomer.SingleOrDefaultAsync(i => i.Id == customerToUpdate.Id);

            //TODO return not found error
            // if (customerItem == null)
            // {
            //     return NotFound(new { Message = $"Item with id {customerToUpdate.Id} not found." });
            // }

            _customerContext.CustomerPhone.Update(phoneToUpdate);

            await _customerContext.SaveChangesAsync();

            return(Ok(phoneToUpdate));
        }
Exemplo n.º 27
0
 // PUT: api/CustomerPhone/5
 public void Put(int id, [FromBody] CustomerPhone oCustomerPhone)
 {
     oBizCustomer.updateCustomerPhone(id, oCustomerPhone);
 }
Exemplo n.º 28
0
 // POST: api/CustomerPhone
 public void Post([FromBody] CustomerPhone oCustomerPhone)
 {
     oBizCustomer.insertCustomerPhone(oCustomerPhone);
 }
Exemplo n.º 29
0
 public void updateCustomerPhone(int intIdCustomer, CustomerPhone oCustomerPhone)
 {
     oDACustomer.updateCustomerPhone(intIdCustomer, oCustomerPhone);
 }
Exemplo n.º 30
0
 public void insertCustomerPhone(CustomerPhone oCustomerPhone)
 {
     oDACustomer.insertCustomerPhone(oCustomerPhone);
 }