Exemple #1
0
 public Client GetClientById(int clientId)
 {
     using (var db = new CellularDbContext())
     {
         return(db.Clients.FirstOrDefault(c => c.Id == clientId));
     }
 }
Exemple #2
0
        public bool AddActivity(IEnumerable <CallEntity> calls)
        {
            try
            {
                using (var context = new CellularDbContext())
                {
                    context.Calls.AddRange(calls);
                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            { /**/ return(false); }
        }

        public bool AddActivity(IEnumerable <SMSEntity> smss)
        {
            try
            {
                using (var context = new CellularDbContext())
                {
                    context.SMSMessages.AddRange(smss);
                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            { /**/ return(false); }
        }
Exemple #3
0
 public List <Line> GetLinesOfClient(int clientId)
 {
     using (var db = new CellularDbContext())
     {
         return(db.Lines.Where(l => l.ClientId == clientId).ToList());
     }
 }
Exemple #4
0
 public void InitDB()
 {
     using (var context = new CellularDbContext())
     {
         context.Database.Initialize(true);
     }
 }
Exemple #5
0
 public Package GetPackageOfLine(string lineNumber)
 {
     using (var db = new CellularDbContext())
     {
         return(db.Packages.FirstOrDefault(p => p.LineNumber == lineNumber));
     }
 }
Exemple #6
0
 public List <Client> GetAllClients()
 {
     using (var db = new CellularDbContext())
     {
         return(db.Clients.ToList());
     }
 }
Exemple #7
0
        public bool AddActivity(CallEntity call)
        {
            try
            {
                using (var context = new CellularDbContext())
                {
                    context.Calls.Add(call);
                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            { /**/ return(false); }
        }

        public bool AddActivity(SMSEntity sms)
        {
            try
            {
                using (var context = new CellularDbContext())
                {
                    context.SMSMessages.Add(sms);
                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            { /**/ return(false); }
        }
Exemple #8
0
 public void DeleteDB()
 {
     using (var context = new CellularDbContext())
     {
         context.Database.Delete();
     }
 }
Exemple #9
0
 public Employee Login(int Id, string password)
 {
     using (var db = new CellularDbContext())
     {
         return(db.Employees.FirstOrDefault(e => e.Id == Id && e.Password == password));
     }
 }
Exemple #10
0
        public void AddingClientWithEmployyeId()
        {
            using (var context = new CellularDbContext())
            {
                var OdedEmp = new Employee
                {
                    FirstName = "Oded",
                    LastName  = "Bartov",
                    Id        = 8888,
                    Password  = "******",
                    Rank      = EmployeeRank.CustomerRepresentative
                };

                var ilanCli = new Client
                {
                    RegisteredBy      = OdedEmp.Id,
                    Id                = 4646,
                    FirstName         = "Ilan",
                    LastName          = "Rozenfeld",
                    ClientTypeId      = ClientTypeEnum.VIP,
                    Password          = "******",
                    RegisterationDate = DateTime.Now.AddDays(-600)
                };

                context.Employees.Add(OdedEmp);
                context.Clients.Add(ilanCli);

                context.SaveChanges();
            }
        }
Exemple #11
0
 public double GetCallMinuetPrice(ClientTypeEnum clientType)
 {
     if (!prices.ContainsKey((clientType, ServiceType.Call)))
     {
         using (var context = new CellularDbContext())
         {
             var price = context.ClientTypes.Find(clientType).CallMinutesPrice;
             prices[(clientType, ServiceType.Call)] = price;
Exemple #12
0
 public void AddLine(Line line)
 {
     using (var db = new CellularDbContext())
     {
         db.Lines.Add(line);
         db.SaveChanges();
     }
 }
Exemple #13
0
 public void AddClient(Client client)
 {
     using (var db = new CellularDbContext())
     {
         db.Clients.Add(client);
         db.SaveChanges();
     }
 }
Exemple #14
0
 public void AddSMS(SMS sms)
 {
     using (var context = new CellularDbContext())
     {
         context.SMSes.Add(sms);
         context.SaveChanges();
     }
 }
Exemple #15
0
 public void AddCall(Call call)
 {
     using (var context = new CellularDbContext())
     {
         context.Calls.Add(call);
         context.SaveChanges();
     }
 }
Exemple #16
0
 public void AddPackage(Package package)
 {
     using (var db = new CellularDbContext())
     {
         db.Packages.Add(package);
         db.SaveChanges();
     }
 }
Exemple #17
0
 public void DeleteLine(string lineNumber)
 {
     using (var db = new CellularDbContext())
     {
         var lineRemoved = db.Lines.FirstOrDefault(l => l.PhoneNumber == lineNumber);
         db.Lines.Remove(lineRemoved);
         db.SaveChanges();
     }
 }
Exemple #18
0
 public void DeletePackage(int packageId)
 {
     using (var db = new CellularDbContext())
     {
         var packageRemoved = db.Packages.FirstOrDefault(p => p.Id == packageId);
         db.Packages.Remove(packageRemoved);
         db.SaveChanges();
     }
 }
Exemple #19
0
 public Package EditPackage(Package package)
 {
     using (var db = new CellularDbContext())
     {
         var packageEdited = db.Packages.FirstOrDefault(p => p.Id == package.Id);
         db.Entry(packageEdited).CurrentValues.SetValues(package);
         db.SaveChanges();
         return(packageEdited);
     }
 }
Exemple #20
0
 public string[] NumbersOf(int clientId)
 {
     using (var context = new CellularDbContext())
     {
         return(context.Lines
                .Where(l => l.ClientId == clientId)
                .Select(l => l.PhoneNumber)
                .ToArray());
     }
 }
Exemple #21
0
 public bool IsEmployeeExistByUsername(string username)
 {
     try
     {
         using (var context = new CellularDbContext())
         {
             bool contains = context.Employees.Any(e => e.Username == username);
             return(contains);
         }
     }
     catch (Exception) { /*write fatal error to logger*/ return(false); }
 }
Exemple #22
0
 /// <summary>
 /// Formula to calculte the value client.
 /// </summary>
 /// <param name="clientId"></param>
 /// <returns></returns>
 private double CalculateProfitableClient(int clientId)
 {
     using (var db = new CellularDbContext())
     {
         var countofLines        = db.Lines.Count(l => l.ClientId == clientId);
         var countOfCallToCenter = db.Lines.Where(l => l.ClientId == clientId).ToArray()
                                   .Sum(l => db.Calls.
                                        Count(c => c.DestinationNumber == NUMBEROFCENTER &&
                                              c.CallerNumber == l.PhoneNumber));
         return((countofLines * 0.2) + (countOfCallToCenter * -0.1));
     }
 }
Exemple #23
0
 public bool IsCustomerExistByPhoneNumber(string phone)
 {
     try
     {
         using (var context = new CellularDbContext())
         {
             bool contains = context.Customers.Any(e => e.PhoneNumber == phone);
             return(contains);
         }
     }
     catch (Exception) { /*write fatal error to logger*/ return(true); }
 }
        public BillEntity GetBill(int id, int month, int year)
        {
            var bill = new BillEntity();

            using (var db = new CellularDbContext())
            {
                bill = (from b in db.Bills
                        where b.CustomerId == id && b.Month == month && b.Year == year
                        select b).FirstOrDefault();
            }
            return(bill);
        }
Exemple #25
0
        public IEnumerable <CustomerEntity> GetFilteredCustomers(string searchInput)
        {
            var filteredCollection = new List <CustomerEntity>();

            using (var context = new CellularDbContext())
            {
                filteredCollection = (from c in context.Customers
                                      where c.PhoneNumber.Contains(searchInput)
                                      select c).ToList();
            }
            return(filteredCollection);
        }
Exemple #26
0
 public string[] FriendsOf(string lineNumber)
 {
     using (var context = new CellularDbContext())
     {
         var pack = context.Packages.FirstOrDefault(p => p.LineNumber == lineNumber);
         if (pack != null && pack.IncludesFriends)
         {
             return new string[] { pack.Number1, pack.Number2, pack.Number3 }
         }
         ;
         return(null);
     }
 }
Exemple #27
0
 public Client EditClient(Client client)
 {
     using (var db = new CellularDbContext())
     {
         var clientEdited = db.Clients.FirstOrDefault(c => c.Id == client.Id);
         clientEdited.FirstName    = client.FirstName;
         clientEdited.LastName     = client.LastName;
         clientEdited.Password     = client.Password;
         clientEdited.ClientTypeId = client.ClientTypeId;
         db.SaveChanges();
         return(clientEdited);
     }
 }
 public bool AddBill(BillEntity bill)
 {
     try
     {
         using (var db = new CellularDbContext())
         {
             db.Bills.Add(bill);
             db.SaveChanges();
             return(true);
         }
     }
     catch { /* write to log */ return(false); }
 }
 public bool AddBill(IEnumerable <BillEntity> bills)
 {
     try
     {
         using (var db = new CellularDbContext())
         {
             db.Bills.AddRange(bills);
             db.SaveChanges();
             return(true);
         }
     }
     catch { /* write to log */ return(false); }
 }
Exemple #30
0
        public void AddingData()
        {
            using (var context = new CellularDbContext())
            {
                Employee olegEmp = new Employee
                {
                    Id        = 1234,
                    FirstName = "Oleg",
                    LastName  = "Firumianz",
                    Password  = "******",
                    Rank      = EmployeeRank.CustomerRepresentative
                },
                         ItamarEmp = new Employee
                {
                    Id        = 4444,
                    FirstName = "Itamar",
                    LastName  = "Daisy",
                    Password  = "******",
                    Rank      = EmployeeRank.Manager
                };

                Client nirCli = new Client
                {
                    ClientTypeId      = ClientTypeEnum.VIP,
                    Id                = 3133,
                    FirstName         = "Nir",
                    LastName          = "London",
                    Password          = "******",
                    Registrator       = olegEmp,
                    RegisterationDate = DateTime.Now.AddDays(-40)
                },
                       shahafCli = new Client
                {
                    Id                = 1111,
                    Registrator       = ItamarEmp,
                    FirstName         = "Shahaf",
                    LastName          = "Dahan",
                    ClientTypeId      = ClientTypeEnum.Business,
                    Password          = "******",
                    RegisterationDate = DateTime.Now.AddDays(-60)
                };

                Line nirLine1;

                //context.Clients

                context.SaveChanges();
            }
        }