Example #1
0
        public async Task <CustomerTypeDto> UpdateCustomerType(int id, CustomerTypeDto customerTypeDto)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (id != customerTypeDto.CustomerTypeId)
                    {
                        return(null);
                    }
                    else
                    {
                        CustomerType ct = db.CustomerTypes.FirstOrDefault(c => c.CustomerTypeId == id);
                        if (ct == null)
                        {
                            return(null);
                        }
                        else
                        {
                            ct = customerTypeDto.ToModel();
                            db.Entry(ct).State = System.Data.Entity.EntityState.Modified;
                            await db.SaveChangesAsync();

                            return(ct.ToDto());
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Example #2
0
        public async Task <CustomerTypeDto> CreateCustomerType(CustomerTypeDto customerTypeDto)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (customerTypeDto == null)
                    {
                        return(null);
                    }
                    else
                    {
                        db.CustomerTypes.Add(customerTypeDto.ToModel());
                        await db.SaveChangesAsync();

                        return(customerTypeDto);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
        public double GetCallsPrice(CustomerDto customer, CustomerTypeDto customerTypeDto)
        {
            double         callPrice = customerTypeDto.MinutePrice;
            List <CallDto> callDto   = _crmProvider.GetCallsForCustomer(customer.CustomerId).Where(c => c.callSendDate.Month == DateTime.Now.Month).ToList();

            if (callDto != null)
            {
                return(callDto.Count * callPrice);
            }
            return(0);
        }
        public double GetSmsPrice(CustomerDto customer, CustomerTypeDto customerTypeDto)
        {
            double        smsPrice = customerTypeDto.SMSPrice;
            List <SMSDto> smsDto   = _crmProvider.GetSmsesForCustomer(customer.CustomerId).Where(s => s.SmsSendTime.Month == DateTime.Now.Month).ToList();

            if (smsDto != null)
            {
                return(smsDto.Count * smsPrice);
            }
            return(0);
        }
Example #5
0
 public bool Delete(CustomerTypeDto dto)
 {
     try
     {
         var retVal = this.dal.Delete(dto.Id);
         return(retVal);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #6
0
 public static CustomerType ToModel(this CustomerTypeDto customerTypeDto)
 {
     if (customerTypeDto == null)
     {
         return(null);
     }
     return(new CustomerType
     {
         CustomerTypeId = customerTypeDto.CustomerTypeId,
         TypeName = customerTypeDto.TypeName,
         MinutePrice = customerTypeDto.MinutePrice,
         SMSPrice = customerTypeDto.SMSPrice,
         Customers = customerTypeDto.Customers.Select(customer => customer.ToModel()).ToList()
     });
 }
Example #7
0
        public static CustomerTypeDto ToDto(this CustomerType e)
        {
            if (e == null)
            {
                return(null);
            }

            var res = new CustomerTypeDto();

            res.Id          = e.Id;
            res.Description = e.Description;
            res.Name        = e.Name;
            res.CostAmount  = e.CostAmount;
            res.Duration    = e.Duration;
            return(res);
        }
Example #8
0
        public List <CustomerTypeDto> GetAllCustomerType()
        {
            List <CustomerTypeDto> customerTypeDtos = new List <CustomerTypeDto>();

            List <CustomerType> customerTypes = this.customerTypeRepository.GetAll().ToList();

            foreach (CustomerType ct in customerTypes)
            {
                CustomerTypeDto dto = new CustomerTypeDto();
                dto.Id      = ct.TypeId.ToString();
                dto.Name    = ct.Name;
                dto.Message = "";
                customerTypeDtos.Add(dto);
            }

            return(customerTypeDtos);
        }
        public IEnumerable <string> MostValuableClients()
        {
            Dictionary <CustomerDto, double> dictionary = new Dictionary <CustomerDto, double>();

            foreach (var item in _customerProvider.GetAllCustomers().Result)
            {
                CustomerTypeDto customerTypeDto = _customerProvider.GetCustomer(item.CustomerId).Result.CustomerType;
                double          value           = GetCallsPrice(item, customerTypeDto) + GetPackageIncludesPrice(item) + GetPackagePrice(item) + GetSmsPrice(item, customerTypeDto);
                dictionary.Add(item, value);
            }
            var sortedDictionary = from v in dictionary
                                   orderby v.Value descending
                                   select v;
            List <string> list = new List <string>();

            foreach (var item in sortedDictionary)
            {
                list.Add($"{item.Key.FirstName} {item.Key.LastName} has a value of {item.Value}");
            }
            return(list.Take(3));
        }
Example #10
0
        public CustomerTypeDto Save(CustomerTypeDto dto)
        {
            try
            {
                var retVal = this.dal.GetByName(dto.Name).ToBasic <DataAccess.Models.CustomerType, CustomerTypeDto>();

                if (retVal != null)
                {
                    retVal = this.dal.Save(retVal.Id, retVal.Name).ToBasic <DataAccess.Models.CustomerType, CustomerTypeDto>();
                }
                else
                {
                    retVal = this.dal.Create(dto.Name).ToBasic <DataAccess.Models.CustomerType, CustomerTypeDto>();
                }

                return(retVal);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #11
0
        public CustomerTypeDto Create(string name)
        {
            try
            {
                CustomerTypeDto retVal = null;
                var             actual = this.dal.GetByName(name).ToBasic <DataAccess.Models.CustomerType, CustomerTypeDto>();

                if (actual == null)
                {
                    retVal = this.dal.Create(name).ToBasic <DataAccess.Models.CustomerType, CustomerTypeDto>();
                }
                else
                {
                    retVal = this.dal.Save(actual.Id, name).ToBasic <DataAccess.Models.CustomerType, CustomerTypeDto>();
                }

                return(retVal);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #12
0
 public bool DeleteCustomerType(CustomerTypeDto dto)
 {
     return(new CustomerTypeLogic().Delete(dto));
 }
Example #13
0
 public CustomerTypeDto SaveCustomerType(CustomerTypeDto dto)
 {
     return(new CustomerTypeLogic().Save(dto));
 }