示例#1
0
        /// <summary>
        /// get number of calls to center by the client
        /// </summary>
        public int GetCallsToCenter(int clientId)
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var callsToCenter = context.Clients.SingleOrDefault(c => c.ClientID == clientId);
                    if (callsToCenter == null)
                    {
                        return(0);
                    }

                    return(callsToCenter.CallsToCenter);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Get calls to center exception: " + e.Message);
            }
        }
示例#2
0
        /// <summary>
        /// gets number of lines that the client have - by client id
        /// </summary>
        public int GetNumberOfLines(int clientId)
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var linesAmount = context.Lines.Where(l => l.ClientId == clientId);
                    if (linesAmount == null)
                    {
                        return(0);
                    }

                    return(linesAmount.Count());
                }
            }
            catch (Exception e)
            {
                throw new Exception("Get number of lines exception: " + e.Message);
            }
        }
示例#3
0
        /// <summary>
        /// get client to login by id and number
        /// </summary>
        public Client GetClient(int clientId, string contactNumber)
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var clientFromDb = context.Clients.SingleOrDefault(c => (c.IdNumber == clientId && c.ContactNumber == contactNumber));
                    if (clientFromDb == null)
                    {
                        return(null);
                    }

                    return(clientFromDb);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Get client exception: " + e.Message);
            }
        }
示例#4
0
        /// <summary>
        /// Delete client from db by client id
        /// </summary>
        public void DeleteClient(int clientId)
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    //var client = context.Clients.Include(c => c.Lines).Single(c => c.ClientID == clientId);
                    //context.Lines.RemoveRange(client.Lines);
                    var client = context.Clients.Find(clientId);
                    context.Clients.Remove(client);

                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                log.LogWrite("Delete client Dal error: " + e.Message);
                throw new Exception("Delete client exception: " + e.Message);
            }
        }
示例#5
0
        /// <summary>
        /// get line by line id
        /// </summary>
        public Line GetLine(int lineId)
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var line = context.Lines.SingleOrDefault(l => l.LineId == lineId);
                    if (line == null)
                    {
                        throw new Exception("no line found");
                    }

                    return(line);
                }
            }
            catch (Exception e)
            {
                log.LogWrite("Get line Dal error: " + e.Message);
                throw new Exception("Get line exception: " + e.Message);
            }
        }
示例#6
0
        /// <summary>
        /// get package templates from db
        /// </summary>
        public List <TemplatePackage> GetTemplates()
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var templates = context.TemplatePackages.ToList();
                    if (templates == null)
                    {
                        throw new Exception("no templates found");
                    }

                    return(templates);
                }
            }
            catch (Exception e)
            {
                log.LogWrite("Get templates Dal error: " + e.Message);
                throw new Exception("Get templates exception: " + e.Message);
            }
        }
示例#7
0
        /// <summary>
        /// get most called numbers from MostCalled Table in db by package id
        /// </summary>
        public MostCalled GetMostCalledNums(int packageId)
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var numbers = context.MostCalled.SingleOrDefault(m => m.PackageId == packageId);
                    if (numbers == null)
                    {
                        throw new Exception("no numbers found for package " + packageId);
                    }

                    return(numbers);
                }
            }
            catch (Exception e)
            {
                log.LogWrite("Get most called numbers Dal error: " + e.Message);
                throw new Exception("Get most called numbers exception: " + e.Message);
            }
        }
示例#8
0
        /// <summary>
        /// get package from db by line id
        /// </summary>
        public Package GetPackage(int lineId)
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var pacakge = context.Packages.SingleOrDefault(p => p.LineId == lineId);
                    if (pacakge == null)
                    {
                        throw new Exception("no package found");
                    }

                    return(pacakge);
                }
            }
            catch (Exception e)
            {
                log.LogWrite("Get package Dal error: " + e.Message);
                throw new Exception("Get package exception: " + e.Message);
            }
        }
示例#9
0
        /// <summary>
        /// get all lines of client by its id from DB
        /// </summary>
        public List <Line> GetLines(int clientId)
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var lines = context.Lines.Where(l => l.ClientId == clientId).ToList();
                    if (lines == null)
                    {
                        throw new Exception("no lines found");
                    }

                    return(lines);
                }
            }
            catch (Exception e)
            {
                log.LogWrite("Get lines Dal error: " + e.Message);
                throw new Exception("Get lines exception: " + e.Message);
            }
        }
示例#10
0
        /// <summary>
        /// get client types - vip/regulare..
        /// </summary>
        public List <ClientType> GetClientTypes()
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var types = context.ClientTypes.ToList();
                    if (types == null)
                    {
                        throw new Exception("no types found");
                    }

                    return(types);
                }
            }
            catch (Exception e)
            {
                log.LogWrite("Get client types Dal error: " + e.Message);
                throw new Exception("Get client types exception: " + e.Message);
            }
        }
示例#11
0
        /// <summary>
        /// gets all calls from Calls table in db by lineid and month
        /// </summary>
        /// <returns>list of call</returns>
        public IEnumerable <Call> GetCalls(int lineId, int month)
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var calls = context.Calls.Where(c => (c.LineID == lineId && c.Month.Month == month)).ToList();
                    if (calls == null)
                    {
                        throw new HttpResponseException(HttpStatusCode.NotFound);
                    }

                    return(calls);
                }
            }
            catch (Exception e)
            {
                log.LogWrite("Get calls Dal error: " + e.Message);
                throw new Exception("Get calls exception: " + e.Message);
            }
        }
示例#12
0
 /// <summary>
 /// add most called numbers to db - if package not in db throw exception
 /// </summary>
 public MostCalled AddMostCalled(MostCalled mostCalled)
 {
     try
     {
         using (CellularModel context = new CellularModel())
         {
             var packageFromDb = context.Packages.SingleOrDefault(p => p.PackageId == mostCalled.PackageId);
             if (packageFromDb == null)
             {
                 throw new KeyNotFoundException("package not exits, unable to add most called");
             }
             context.MostCalled.Add(mostCalled);
             context.SaveChanges();
             return(mostCalled);
         }
     }
     catch (Exception e)
     {
         log.LogWrite("Add most called Dal error: " + e.Message);
         throw new Exception(e.Message);
     }
 }
示例#13
0
        /// <summary>
        /// gets total price of the receipt for the client for last 3 month
        /// </summary>
        public double GetRecieptsSum(int clientId)
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var payment1 = context.Payments.SingleOrDefault(p => (p.ClientID == clientId && p.Month.Month == DateTime.Now.Month));
                    var payment2 = context.Payments.SingleOrDefault(p => (p.ClientID == clientId && p.Month.Month - 1 == DateTime.Now.Month - 1));
                    var payment3 = context.Payments.SingleOrDefault(p => (p.ClientID == clientId && p.Month.Month - 2 == DateTime.Now.Month - 2));
                    if (payment1 == null && payment2 == null && payment3 == null)
                    {
                        return(0);
                    }

                    return(payment1.TotalPayment + payment2.TotalPayment + payment3.TotalPayment);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Get payment exception: " + e.Message);
            }
        }
示例#14
0
 /// <summary>
 /// adds sms to sms table in db
 /// </summary>
 public SMS AddSms(SMS sms)
 {
     try
     {
         using (CellularModel context = new CellularModel())
         {
             var lineFromDb = context.Lines.SingleOrDefault(l => l.LineId == sms.LineID);
             if (lineFromDb == null)
             {
                 throw new Exception("Line not exits, choose another line id");
             }
             context.SMS.Add(sms);
             context.SaveChanges();
             return(sms);
         }
     }
     catch (Exception e)
     {
         log.LogWrite("Add sms Dal error: " + e.Message);
         throw new Exception(e.Message);
     }
 }
示例#15
0
 /// <summary>
 /// adds payment to db
 /// </summary>
 public Payment AddPayment(Payment payment)
 {
     try
     {
         using (CellularModel context = new CellularModel())
         {
             var clientFromDb = context.Clients.SingleOrDefault(l => l.ClientID == payment.ClientID);
             if (clientFromDb == null)
             {
                 throw new Exception("Client not exits, choose another line id");
             }
             context.Payments.Add(payment);
             context.SaveChanges();
             return(payment);
         }
     }
     catch (Exception e)
     {
         log.LogWrite("Add payment Dal error: " + e.Message);
         throw new Exception(e.Message);
     }
 }
示例#16
0
 /// <summary>
 /// adds call to db
 /// </summary>
 public Call AddCall(Call call)
 {
     try
     {
         using (CellularModel context = new CellularModel())
         {
             var lineFromDb = context.Lines.SingleOrDefault(l => l.LineId == call.LineID);
             if (lineFromDb == null)
             {
                 throw new Exception("Line not exits, choose another line id");
             }
             context.Calls.Add(call);
             context.SaveChanges();
             return(call);
         }
     }
     catch (Exception e)
     {
         log.LogWrite("Add call Dal error: " + e.Message);
         throw new Exception(e.Message);
     }
 }
示例#17
0
        /// <summary>
        /// Update existing line in db by line id
        /// </summary>
        /// <param name="newLine">line with updated fields</param>
        /// <returns></returns>
        public Line UpdateLine(int lineId, eStatus status)
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var lineInDb = context.Lines.SingleOrDefault(l => l.LineId == lineId);
                    if (lineInDb == null)
                    {
                        throw new Exception("Line not found");
                    }
                    lineInDb.Status = status;

                    context.SaveChanges();
                    return(lineInDb);
                }
            }
            catch (Exception e)
            {
                log.LogWrite("Update line error: " + e.Message);
                throw new Exception("Update line exception: " + e.Message);
            }
        }
示例#18
0
 /// <summary>
 /// add client to db - if client idnumber or contact number exists in db dont add client
 /// </summary>
 /// <returns>client to know the agent is added</returns>
 public Client AddClient(Client client)
 {
     try
     {
         using (CellularModel context = new CellularModel())
         {
             var clientIdNum = context.Clients.SingleOrDefault(c => c.IdNumber == client.IdNumber);
             var contactNum  = context.Clients.SingleOrDefault(c => c.ContactNumber == client.ContactNumber);
             if (clientIdNum != null || contactNum != null)
             {
                 throw new Exception("id or contact number exists, change input");
             }
             context.Clients.Add(client);
             context.SaveChanges();
             return(client);
         }
     }
     catch (Exception e)
     {
         log.LogWrite("Add client Dal error: " + e.Message);
         throw new Exception("Add client DAL exception: " + e.Message);
     }
 }
示例#19
0
        /// <summary>
        /// get client type (vip,bussines...) by line id
        /// </summary>
        public ClientType GetClientType(int lineId)
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var clientId     = context.Lines.SingleOrDefault(l => l.LineId == lineId).ClientId;
                    var clientTypeId = context.Clients.SingleOrDefault(c => c.ClientID == clientId).ClientTypeId;
                    var type         = context.ClientTypes.SingleOrDefault(ct => ct.Id == clientTypeId);
                    if (type == null)
                    {
                        throw new HttpResponseException(HttpStatusCode.NotFound);
                    }

                    return(type);
                }
            }
            catch (Exception e)
            {
                log.LogWrite("Get client type Dal error: " + e.Message);
                throw new Exception("Get client type exception: " + e.Message);
            }
        }
示例#20
0
        /// <summary>
        /// get most calling clients to center call
        /// </summary>
        /// <returns></returns>
        public List <Client> GetMostCalling()
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var mostCallingToCenter = context.Clients.OrderBy(c => c.CallsToCenter);
                    if (mostCallingToCenter == null)
                    {
                        return(null);
                    }

                    return(mostCallingToCenter.ToList());
                }
            }
            catch (NullReferenceException e)
            {
                throw new Exception("Get most calling to cetner null");
            }
            catch (Exception e)
            {
                throw new Exception("Get most calling to cetner exception: " + e.Message);
            }
        }
示例#21
0
        /// <summary>
        /// Update existing agent in db by agent id
        /// </summary>
        /// <param name="newAgent">agent with updated password and sales</param>
        /// <returns></returns>
        public ServiceAgent UpdateServiceAgent(ServiceAgent newAgent, int agentId)
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var agentInDb = context.ServiceAgents.SingleOrDefault(a => a.ServiceAgentId == agentId);
                    if (agentInDb == null)
                    {
                        throw new Exception("Agent not found");
                    }
                    agentInDb.Password    = newAgent.Password;
                    agentInDb.SalesAmount = newAgent.SalesAmount;

                    context.SaveChanges();
                    return(newAgent);
                }
            }
            catch (Exception e)
            {
                log.LogWrite("Update Agent Dal error: " + e.Message);
                throw new Exception("Update Agent DAL exception: " + e.Message);
            }
        }
示例#22
0
        public List <ServiceAgent> GetBestSellers()
        {
            try
            {
                using (CellularModel context = new CellularModel())
                {
                    var bestSellers = context.ServiceAgents.OrderByDescending(s => s.SalesAmount);
                    if (bestSellers == null)
                    {
                        return(null);
                    }

                    return(bestSellers.ToList());
                }
            }
            catch (NullReferenceException)
            {
                throw new Exception("Get best sellers null");
            }
            catch (Exception e)
            {
                throw new Exception("Get best sellers exception: " + e.Message);
            }
        }