public Client GetClientById(int clientId) { using (var db = new CellularDbContext()) { return(db.Clients.FirstOrDefault(c => c.Id == clientId)); } }
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); } }
public List <Line> GetLinesOfClient(int clientId) { using (var db = new CellularDbContext()) { return(db.Lines.Where(l => l.ClientId == clientId).ToList()); } }
public void InitDB() { using (var context = new CellularDbContext()) { context.Database.Initialize(true); } }
public Package GetPackageOfLine(string lineNumber) { using (var db = new CellularDbContext()) { return(db.Packages.FirstOrDefault(p => p.LineNumber == lineNumber)); } }
public List <Client> GetAllClients() { using (var db = new CellularDbContext()) { return(db.Clients.ToList()); } }
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); } }
public void DeleteDB() { using (var context = new CellularDbContext()) { context.Database.Delete(); } }
public Employee Login(int Id, string password) { using (var db = new CellularDbContext()) { return(db.Employees.FirstOrDefault(e => e.Id == Id && e.Password == password)); } }
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(); } }
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;
public void AddLine(Line line) { using (var db = new CellularDbContext()) { db.Lines.Add(line); db.SaveChanges(); } }
public void AddClient(Client client) { using (var db = new CellularDbContext()) { db.Clients.Add(client); db.SaveChanges(); } }
public void AddSMS(SMS sms) { using (var context = new CellularDbContext()) { context.SMSes.Add(sms); context.SaveChanges(); } }
public void AddCall(Call call) { using (var context = new CellularDbContext()) { context.Calls.Add(call); context.SaveChanges(); } }
public void AddPackage(Package package) { using (var db = new CellularDbContext()) { db.Packages.Add(package); db.SaveChanges(); } }
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(); } }
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(); } }
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); } }
public string[] NumbersOf(int clientId) { using (var context = new CellularDbContext()) { return(context.Lines .Where(l => l.ClientId == clientId) .Select(l => l.PhoneNumber) .ToArray()); } }
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); } }
/// <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)); } }
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); }
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); }
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); } }
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); } }
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(); } }