public RequestStatusEnum CreateNewLinePackage(LinePackObject linePackObj) { //creates a new line,package,package details,and selected numbers lock (dbLock) { using (CnContextMock context = new CnContextMock()) { context.Packages.Add(new Package(linePackObj.Package.PackageName, linePackObj.Package.PackageTotalPrice)); context.SaveChanges(); LoadLinesAndPackges(); int PackageId = Packages.Last().ID; context.SelectedNumbers.Add(new SelectedNumbers(linePackObj.SelectedNumbers.FirstNumber, linePackObj.SelectedNumbers.SecondNumber, linePackObj.SelectedNumbers.ThirdNumber)); context.SaveChanges(); LoadLinesAndPackges(); int selectedNumId = SelectedNumbers.Last().ID; context.PackageDetails.Add(new PackageDetails(PackageId, "Custom Package", linePackObj.PackageDetails.MaxMinutes, 0, linePackObj.PackageDetails.MaxSMS, 0, linePackObj.PackageDetails.FixedSmsPrice, linePackObj.PackageDetails.FixedCallPrice, linePackObj.PackageDetails.DiscountPercentage, selectedNumId, linePackObj.PackageDetails.MostCalledNumber)); context.Lines.Add(new Line(linePackObj.ClientId, linePackObj.LineNumber, LineStatusEnum.Available, PackageId, linePackObj.EmployeeID)); context.SaveChanges(); } LoadCollections(); return(RequestStatusEnum.Success); } }
public RequestStatusEnum UpdateClientDetails(Client client) { //updates the details of an exisiting client lock (dbLock) { using (CnContextMock context = new CnContextMock()) { Client dbClient = context.Clients.FirstOrDefault(c => c.ID == client.ID); dbClient.FirstName = client.FirstName; dbClient.LastName = client.LastName; dbClient.Address = client.Address; dbClient.BirthDate = client.BirthDate; dbClient.ClientType = client.ClientType; dbClient.ContactNumber = client.ContactNumber; context.SaveChanges(); } } Client toUpdate = GetClientByID(client.ID); toUpdate.FirstName = client.FirstName; toUpdate.LastName = client.LastName; toUpdate.Address = client.Address; toUpdate.BirthDate = client.BirthDate; toUpdate.ClientType = client.ClientType; toUpdate.ContactNumber = client.ContactNumber; return(RequestStatusEnum.Success); }
public RequestStatusEnum UpdateLinePackage(LinePackObject linePackObj) { //updates the line,package,package details,and selected numbers lock (dbLock) { using (CnContextMock context = new CnContextMock()) { Package packpageFromDb = context.Packages.FirstOrDefault(p => p.ID == linePackObj.Package.ID); packpageFromDb.PackageTotalPrice = linePackObj.Package.PackageTotalPrice; packpageFromDb.PackageName = linePackObj.Package.PackageName; PackageDetails packdetFromDb = context.PackageDetails.FirstOrDefault(pd => pd.ID == linePackObj.PackageDetails.ID); packdetFromDb.DiscountPercentage = linePackObj.PackageDetails.DiscountPercentage; packdetFromDb.FixedCallPrice = linePackObj.PackageDetails.FixedCallPrice; packdetFromDb.FixedSmsPrice = linePackObj.PackageDetails.FixedSmsPrice; packdetFromDb.MaxMinutes = linePackObj.PackageDetails.MaxMinutes; packdetFromDb.MaxSMS = linePackObj.PackageDetails.MaxSMS; packdetFromDb.MostCalledNumber = linePackObj.PackageDetails.MostCalledNumber; SelectedNumbers selectedNumsFromDb = context.SelectedNumbers.FirstOrDefault(sn => sn.ID == linePackObj.SelectedNumbers.ID); selectedNumsFromDb.FirstNumber = linePackObj.SelectedNumbers.FirstNumber; selectedNumsFromDb.SecondNumber = linePackObj.SelectedNumbers.SecondNumber; selectedNumsFromDb.ThirdNumber = linePackObj.SelectedNumbers.ThirdNumber; context.SaveChanges(); } } LoadCollections(); return(RequestStatusEnum.Success); }
public RequestStatusEnum SaveException(Error error) { //saves the exception to the database using (CnContextMock context = new CnContextMock()) { context.Errors.Add(error); context.SaveChanges(); } return(RequestStatusEnum.Success); }
private void LoadCallsAndSms() { //loads calls,sms and payments lock (dbLock) { using (CnContextMock context = new CnContextMock()) { Calls = context.Calls.ToList(); SMS = context.SMS.ToList(); Payments = context.Payments.ToList(); } } }
private void LoadClients() { //loads clients,users and etc lock (dbLock) { using (CnContextMock context = new CnContextMock()) { Clients = context.Clients.ToList(); Users = context.Users.ToList(); ClientTypes = context.ClientTypes.ToList(); } } }
public RequestStatusEnum SaveExceptionsList(List <Error> errors) { //saves the exceptions to the database using (CnContextMock context = new CnContextMock()) { foreach (var error in errors) { context.Errors.Add(error); } context.SaveChanges(); } return(RequestStatusEnum.Success); }
private void LoadLinesAndPackges() { //loads line,packages and etc lock (dbLock) { using (CnContextMock context = new CnContextMock()) { Lines = context.Lines.ToList(); Packages = context.Packages.ToList(); PackageDetails = context.PackageDetails.ToList(); SelectedNumbers = context.SelectedNumbers.ToList(); } } }
public RequestStatusEnum AddNewClient(Client client) { //adds a new Client lock (dbLock) { using (CnContextMock context = new CnContextMock()) { context.Clients.Add(client); context.SaveChanges(); } } Clients.Add(client); return(RequestStatusEnum.Success); }
private void UpdateDBPackageDetails(PackageDetails packDet) { //updates the package details in the database lock (dbLock) { using (CnContextMock context = new CnContextMock()) { PackageDetails packDetFromDb = context.PackageDetails.FirstOrDefault(pd => pd.ID == packDet.ID); if (packDetFromDb != null) { packDetFromDb.UsedMinutes = packDet.UsedMinutes; packDetFromDb.UsedSMS = packDet.UsedSMS; } context.SaveChanges(); } } }
public async Task <bool> AddSms(SMS sms) { lock (dbLock) { using (CnContextMock context = new CnContextMock()) { context.SMS.Add(sms); Package package = GetPackageByLineId(sms.LineID); PackageDetails packDet = GetPackageDetailsByPackageId(package.ID); packDet.UsedSMS++; UpdateDBPackageDetails(packDet); context.SaveChanges(); } } SMS.Add(sms); return(true); }
public void AddCallsToCenter(string clientId) { //adds a calls to center to this client lock (dbLock) { Client client = GetClientByID(clientId); client.CallsToCenter++; using (CnContextMock context = new CnContextMock()) { Client dbClient = context.Clients.FirstOrDefault(c => c.ID == clientId); if (dbClient != null) { dbClient.CallsToCenter++; } context.SaveChanges(); } } }
public string DeleteClient(string id) { //moves the client to the un active clients lock (dbLock) { Client client = GetClientByID(id); DiactivateClientLinesById(id); using (CnContextMock context = new CnContextMock()) { UnActiveClient unActive = ConvertClientToUnActive(client); context.UnActiveClients.Add(unActive); // context.Clients.Remove(c=) context.SaveChanges(); } Clients.Remove(client); } return("Client removed succesfully!"); }
public RequestStatusEnum UpdateLineStatus(Line line) { //updates the line's new status using (CnContextMock context = new CnContextMock()) { Line lineFromDb = context.Lines.FirstOrDefault(l => l.Number == line.Number); if (lineFromDb != null) { lineFromDb.Status = line.Status; context.SaveChanges(); LoadLinesAndPackges(); return(RequestStatusEnum.Success); } else { return(RequestStatusEnum.Error); } } }
public RequestStatusEnum DeleteLine(string line) { //deletes the line and all its belongings lock (dbLock) { using (CnContextMock context = new CnContextMock()) { Line lineFromDb = context.Lines.FirstOrDefault(l => l.Number == line); Package packageFromDb = context.Packages.FirstOrDefault(p => p.ID == lineFromDb.PackageID); PackageDetails packDetFromDb = context.PackageDetails.FirstOrDefault(pd => pd.PackageID == packageFromDb.ID); SelectedNumbers selectedNumsFromDb = context.SelectedNumbers.FirstOrDefault(sn => sn.ID == packDetFromDb.SelectedNumbersID); context.Lines.Remove(lineFromDb); context.Packages.Remove(packageFromDb); context.PackageDetails.Remove(packDetFromDb); context.SelectedNumbers.Remove(selectedNumsFromDb); context.SaveChanges(); LoadLinesAndPackges(); } return(RequestStatusEnum.Success); } }
private void DiactivateClientLinesById(string id) { //deactivates the client lines lock (dbLock) { List <Line> clientLines = GetClientLinesById(id); using (CnContextMock context = new CnContextMock()) { foreach (var item in clientLines) { Line dbLine = context.Lines.FirstOrDefault(l => l.ClientID == id); if (dbLine != null) { dbLine.Status = LineStatusEnum.Blocked; } item.Status = LineStatusEnum.Blocked; } context.SaveChanges(); } } }