Ejemplo n.º 1
0
        /// <summary>
        /// insert the customer into the database company
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <returns>int</returns>
        public int subscribeCustomer(Customer customer)
        {
            int res = 0;

            try
            {
                using (var dbCtx = new CallMonitorModelEntities())
                {
                    dbCtx.CUSTOMER.Add(new CustomerEntity
                    {
                        Id           = customer.Id,
                        Id_Type      = customer.Id_Type,
                        First_Name   = customer.FirstName,
                        Second_Name  = customer.SecondName,
                        Last_Name    = customer.LastName,
                        Phone_Number = customer.PhoneNumber
                    }
                                       );
                    res = dbCtx.SaveChanges();
                }
                return(res);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// insert the initial customer's balance
        /// </summary>
        /// <param name="cusPhone"></param>
        /// <returns>int</returns>
        public int customerPhoneBalance(CustomerPhone cusPhone)
        {
            int res = 0;

            try
            {
                using (var dbCtx = new CallMonitorModelEntities())
                {
                    dbCtx.CUSTOMER_PHONE.Add(new CustomerPhoneEntity
                    {
                        Customer_Id    = cusPhone.Id,
                        Phone_Number   = cusPhone.PhoneNumber,
                        Phone_state    = cusPhone.PhoneState,
                        Minute_Balance = cusPhone.MinuteBalance,
                        Minutes_Use    = cusPhone.MinutesUsed
                    });
                    res = dbCtx.SaveChanges();
                }
                return(res);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// start the phone call made by the customer
 /// </summary>
 /// <param name="call"></param>
 /// <returns>int</returns>
 public int initPhoneCall(Call call)
 {
     try
     {
         int res = 0;
         using (var dbCtx = new CallMonitorModelEntities())
         {
             dbCtx.CALL.Add(new CallEntity
             {
                 Customer_id        = call.Id,
                 Phone_Number       = call.PhoneNumber,
                 Destination_Number = call.DestinationNumber,
                 Initial_DateTime   = call.InitialDatetime,
                 Final_DateTime     = call.FinalDatetime,
                 Call_Duration      = call.Duration,
                 Call_Cost          = call.Cost,
                 Call_State         = call.State
             });
             res = dbCtx.SaveChanges();
         }
         res = getLastCall(call).CallId;
         return(res);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// insert a recharge request from the customer into the database
        /// </summary>
        /// <param name="charge"></param>
        /// <returns>int</returns>
        public int phoneRecharge(Recharge charge)
        {
            int res = 0;

            try
            {
                //var dbCtx = new CallMonitorModelEntities();
                //RechargeEntity reCharge = new RechargeEntity();
                //reCharge = dbCtx.RECHARGE.Where(c => c.Customer_Id == charge.Id && c.Phone_Number == charge.PhoneNumber).FirstOrDefault();
                //if (reCharge != null)
                //{
                //    reCharge.Customer_Id = charge.Id;
                //    reCharge.Phone_Number = charge.PhoneNumber;
                //    reCharge.Recharge_value = charge.Value;
                //    reCharge.Recharge_Date = charge.Date;
                //    reCharge.Recharge_State = charge.State;
                //}
                //else
                //{
                //    dbCtx.RECHARGE.Add(new RechargeEntity{ Customer_Id = charge.Id, Phone_Number = charge.PhoneNumber, Recharge_value = charge.Value, Recharge_Date = charge.Date, Recharge_State = charge.State });
                //}

                //return dbCtx.SaveChanges();
                using (var dbCtx = new CallMonitorModelEntities())
                {
                    dbCtx.RECHARGE.Add(new RechargeEntity
                    {
                        Customer_Id    = charge.Id,
                        Phone_Number   = charge.PhoneNumber,
                        Recharge_value = charge.Value,
                        Recharge_Date  = charge.Date,
                        Recharge_State = charge.State
                    });
                    res = dbCtx.SaveChanges();
                }
                return(res);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 5
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;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// insert an awarded bonus to a customer
        /// </summary>
        /// <param name="cusBonus"></param>
        /// <returns></returns>
        public int customerBonus(CustomerBonus cusBonus)
        {
            int res = 0;

            try
            {
                using (var dbCtx = new CallMonitorModelEntities())
                {
                    dbCtx.CUSTOMER_BONUS.Add(new CustomerBonusEntity
                    {
                        Customer_Id    = cusBonus.Id,
                        Phone_Number   = cusBonus.PhoneNumber,
                        Promotion_Id   = cusBonus.PromotionId,
                        Activation_day = cusBonus.ActivationDay
                    });
                    res = dbCtx.SaveChanges();
                }
                return(res);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }