Exemple #1
0
        public RequestStatusEnum CreateNewLinePackage(LinePackObject linePackObj)
        {
            //creates a new line,package,package details,and selected numbers
            lock (dbLock)
            {
                using (CnContext context = new CnContext())
                {
                    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);
            }
        }
Exemple #2
0
        public RequestStatusEnum UpdateClientDetails(Client client)
        {
            //updates the details of an exisiting client
            lock (dbLock)
            {
                using (CnContext context = new CnContext())
                {
                    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);
        }
Exemple #3
0
        public RequestStatusEnum UpdateLinePackage(LinePackObject linePackObj)
        {
            //updates the line,package,package details,and selected numbers
            lock (dbLock)
            {
                using (CnContext context = new CnContext())
                {
                    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);
        }
Exemple #4
0
 public RequestStatusEnum SaveException(Error error)
 {
     //saves the exception to the database
     using (CnContext context = new CnContext())
     {
         context.Errors.Add(error);
         context.SaveChanges();
     }
     return(RequestStatusEnum.Success);
 }
Exemple #5
0
 public RequestStatusEnum SaveExceptionsList(List <Error> errors)
 {
     //saves the exceptions to the database
     using (CnContext context = new CnContext())
     {
         foreach (var error in errors)
         {
             context.Errors.Add(error);
         }
         context.SaveChanges();
     }
     return(RequestStatusEnum.Success);
 }
Exemple #6
0
 public RequestStatusEnum AddNewClient(Client client)
 {
     //adds a new Client
     lock (dbLock)
     {
         using (CnContext context = new CnContext())
         {
             context.Clients.Add(client);
             context.SaveChanges();
         }
     }
     Clients.Add(client);
     return(RequestStatusEnum.Success);
 }
Exemple #7
0
 private void UpdateDBPackageDetails(PackageDetails packDet)
 {
     //updates the package details in the database
     lock (dbLock)
     {
         using (CnContext context = new CnContext())
         {
             PackageDetails packDetFromDb = context.PackageDetails.FirstOrDefault(pd => pd.ID == packDet.ID);
             if (packDetFromDb != null)
             {
                 packDetFromDb.UsedMinutes = packDet.UsedMinutes;
                 packDetFromDb.UsedSMS     = packDet.UsedSMS;
             }
             context.SaveChanges();
         }
     }
 }
Exemple #8
0
 public async Task <bool> AddSms(SMS sms)
 {
     lock (dbLock)
     {
         using (CnContext context = new CnContext())
         {
             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 async Task <bool> AddCall(Call call)
        {
            lock (dbLock)
            {
                using (CnContext context = new CnContext())
                {
                    context.Calls.Add(call);
                    Package        package = GetPackageByLineId(call.LineID);
                    PackageDetails packDet = GetPackageDetailsByPackageId(package.ID);
                    packDet.UsedMinutes += call.Duration;
                    UpdateDBPackageDetails(packDet);
                    context.SaveChanges();
                }
            }
            Calls.Add(call);

            return(true);
        }
Exemple #10
0
 public void AddCallsToCenter(string clientId)
 {
     //adds a calls to center to this client
     lock (dbLock)
     {
         Client client = GetClientByID(clientId);
         client.CallsToCenter++;
         using (CnContext context = new CnContext())
         {
             Client dbClient = context.Clients.FirstOrDefault(c => c.ID == clientId);
             if (dbClient != null)
             {
                 dbClient.CallsToCenter++;
             }
             context.SaveChanges();
         }
     }
 }
Exemple #11
0
 public string DeleteClient(string id)
 {
     //moves the client to the un active clients
     lock (dbLock)
     {
         Client client = GetClientByID(id);
         DiactivateClientLinesById(id);
         using (CnContext context = new CnContext())
         {
             UnActiveClient unActive = ConvertClientToUnActive(client);
             context.UnActiveClients.Add(unActive);
             context.Clients.Remove(context.Clients.FirstOrDefault(c => c.ID == id));
             context.SaveChanges();
         }
         Clients.Remove(client);
     }
     return("Client removed succesfully!");
 }
Exemple #12
0
 public RequestStatusEnum UpdateLineStatus(Line line)
 {
     //updates the line's new status
     using (CnContext context = new CnContext())
     {
         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);
         }
     }
 }
Exemple #13
0
 public RequestStatusEnum DeleteLine(string line)
 {
     //deletes the line and all its belongings
     lock (dbLock)
     {
         using (CnContext context = new CnContext())
         {
             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);
     }
 }
Exemple #14
0
 private void DiactivateClientLinesById(string id)
 {
     //deactivates the client lines
     lock (dbLock)
     {
         List <Line> clientLines = GetClientLinesById(id);
         using (CnContext context = new CnContext())
         {
             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();
         }
     }
 }