コード例 #1
0
 public Line DeleteLine(Line line)
 {
     using (PhoneCompanyContext context = new PhoneCompanyContext())
     {
         return(context.Lines.Remove(line));
     }
 }
コード例 #2
0
 public Package GetPackage(string name)
 {
     using (PhoneCompanyContext context = new PhoneCompanyContext())
     {
         return(context.Packages.FirstOrDefault(p => p.Name == name));
     }
 }
コード例 #3
0
 public Package GetPackage(int id)
 {
     using (PhoneCompanyContext context = new PhoneCompanyContext())
     {
         return(context.Packages.FirstOrDefault(p => p.Id == id));
     }
 }
コード例 #4
0
 public Client DeleteClient(Client client)
 {
     using (PhoneCompanyContext context = new PhoneCompanyContext())
     {
         return(context.Clients.Remove(client));
     }
 }
コード例 #5
0
 public ClientType GetClientType(Client client)
 {
     using (PhoneCompanyContext context = new PhoneCompanyContext())
     {
         return(context.ClientTypes.FirstOrDefault(c => c.Id == client.ClientTypeId));
     }
 }
コード例 #6
0
 public void AddLine(Line line)
 {
     if (line != null)
     {
         using (PhoneCompanyContext context = new PhoneCompanyContext())
         {
             try
             {
                 //if(line.Client != null)
                 //{
                 //    line.ClientId = line.Client.Id;
                 //    line.Client = null;
                 //}
                 //if (line.Package != null)
                 //{
                 //    line.PackageId = line.Package.Id;
                 //    line.Package = null;
                 //}
                 context.Lines.Add(line);
                 //context.Entry(line.Client).State = System.Data.Entity.EntityState.Unchanged;
                 //context.Entry(line.Package).State = System.Data.Entity.EntityState.Unchanged;
                 context.Entry(line).State = System.Data.Entity.EntityState.Added;
                 context.SaveChanges();
             }
             catch (Exception x)
             {
                 Debug.Write(x.Message);
             }
         }
     }
 }
コード例 #7
0
 public Client GetClientById(string Id)
 {
     using (PhoneCompanyContext context = new PhoneCompanyContext())
     {
         return(context.Clients.FirstOrDefault(c => c.Id == Id));
     }
 }
コード例 #8
0
 public IEnumerable <Package> GetPackages()
 {
     using (PhoneCompanyContext context = new PhoneCompanyContext())
     {
         var t = context.Packages.ToList();
         return(t);
     }
 }
コード例 #9
0
 public IEnumerable <Line> GetLinesofClient(Client c)
 {
     using (PhoneCompanyContext context = new PhoneCompanyContext())
     {
         var t = context.Lines.Where(l => l.ClientId == c.Id).ToList();
         return(t);
     }
 }
コード例 #10
0
 public IEnumerable <ClientType> GetClientTypes()
 {
     using (PhoneCompanyContext context = new PhoneCompanyContext())
     {
         var t = context.ClientTypes.ToList();
         return(t);
     }
 }
コード例 #11
0
 public IEnumerable <Line> GetLines()
 {
     using (PhoneCompanyContext context = new PhoneCompanyContext())
     {
         var t = context.Lines.ToList();
         return(t);
     }
 }
コード例 #12
0
 public IEnumerable <Line> GetLinesByClientId(string Id)
 {
     using (PhoneCompanyContext context = new PhoneCompanyContext())
     {
         //var x=context.Lines.Include(li=>li.Package).Where(l=>l.ClientId==Id).ToList();
         //var x = context.Clients.Include(c => c.Lines).Where(c => c.Id == Id).ToList();
         var t = context.Lines.Where(l => l.ClientId == Id).ToList();
         return(t);
     }
 }
コード例 #13
0
 public void AddClient(Client client)
 {
     if (client != null)
     {
         using (PhoneCompanyContext context = new PhoneCompanyContext())
         {
             context.Entry(client.TypeId).State = System.Data.Entity.EntityState.Unchanged;
             context.Entry(client).State        = System.Data.Entity.EntityState.Added;
             context.Clients.Add(client);
             context.SaveChanges();
         }
     }
 }
コード例 #14
0
 public void SendCall(SMS sMS)
 {
     if (sMS != null)
     {
         using (PhoneCompanyContext context = new PhoneCompanyContext())
         {
             context.Entry(sMS.Line).State = System.Data.Entity.EntityState.Unchanged;
             //context.Entry(sMS.Line.Package).State = System.Data.Entity.EntityState.Unchanged;
             context.Entry(sMS).State = System.Data.Entity.EntityState.Added;
             context.SMSs.Add(sMS);
             context.SaveChanges();
         }
     }
 }
コード例 #15
0
 public IEnumerable <Call> GetCallsOfLine(int lineId)
 {
     using (PhoneCompanyContext context = new PhoneCompanyContext())
     {
         List <Call> calls = new List <Call>();
         foreach (var item in context.Calls)
         {
             if (item.LineId == lineId)
             {
                 calls.Add(item);
             }
         }
         return(calls);
     }
 }
コード例 #16
0
 public IEnumerable <Client> GetClients()
 {
     using (PhoneCompanyContext context = new PhoneCompanyContext())
     {
         var t = context.Clients;
         if (t != null)
         {
             return(t.ToList());
         }
         else
         {
             return(null);
         }
     }
 }
コード例 #17
0
        /*
         * //public T ExecuteDbFunction<T>(Func<PhoneCompanyContext, T> functions)
         * //{
         * //    using (PhoneCompanyContext context = new PhoneCompanyContext())
         * //    {
         * //        var res = functions(context);
         * //        context.SaveChanges();
         * //        return res;
         * //    }
         * //}
         *
         * public T ExecuteDbAction(params Func<PhoneCompanyContext>[] actions)
         * {
         *  using (PhoneCompanyContext context = new PhoneCompanyContext())
         *  {
         *      foreach (var action in actions)
         *      {
         *          action(context);
         *      }
         *      context.SaveChanges();
         *  }
         * }
         *
         * public void ExecuteDbAction<T>( Func<PhoneCompanyContext,T> function)
         * {
         *  using (PhoneCompanyContext context = new PhoneCompanyContext())
         *  {
         *
         *      function(context);
         *      context.SaveChanges();
         *  }
         * }
         *
         * //public void SendCall2(Call call) => ExecuteDbAction((context) => Sendcallwithcontext(context, call));
         * public void Sendcallwithcontext(PhoneCompanyContext context, Call call)
         * {
         *  context.Entry(call.Line).State = System.Data.Entity.EntityState.Unchanged;
         *  context.Entry(call).State = System.Data.Entity.EntityState.Added;
         *  context.Calls.Add(call);
         * }
         *
         *
         *
         * public void SendCallANDSMS2(Call call, SMS sms)
         * {
         *  ExecuteDbAction((context) => Sendcallwithcontext(context, call), (context) => Sendcallwithcontext(context, sms));
         * }
         *
         *
         *
         *
         * private void Sendcallwithcontext(PhoneCompanyContext context, SMS sms)
         * {
         *  //adds sms to context
         * }
         */
        #endregion

        public IEnumerable <SMS> GetSMSsOfLine(int lineId)
        {
            using (PhoneCompanyContext context = new PhoneCompanyContext())
            {
                List <SMS> smss = new List <SMS>();
                foreach (var item in context.SMSs)
                {
                    if (item.LineId == lineId)
                    {
                        smss.Add(item);
                    }
                }
                return(smss);
            }
        }
コード例 #18
0
 public void AddPackageDetails(PackageInclude packageInclude)
 {
     if (packageInclude != null)
     {
         using (PhoneCompanyContext context = new PhoneCompanyContext())
         {
             try
             {
                 context.Entry(packageInclude.Package).State = System.Data.Entity.EntityState.Unchanged;
                 context.Entry(packageInclude).State         = System.Data.Entity.EntityState.Added;
                 context.PackageIncludes.Add(packageInclude);
                 context.SaveChanges();
             }
             catch (Exception x)
             {
                 Debug.Write(x.Message);
             }
         }
     }
 }
コード例 #19
0
 public void SendCall(Call call)
 {
     if (call != null)
     {
         using (PhoneCompanyContext context = new PhoneCompanyContext())
         {
             try
             {
                 //context.Entry(call.Line).State = System.Data.Entity.EntityState.Unchanged;
                 //context.Entry(call.Line.Package).State = System.Data.Entity.EntityState.Unchanged;
                 context.Entry(call).State = System.Data.Entity.EntityState.Added;
                 context.Calls.Add(call);
                 context.SaveChanges();
             }
             catch (Exception x)
             {
                 Debug.Write(x.Message);
                 throw;
             }
         }
     }
 }
コード例 #20
0
        public IEnumerable <Call> GetCallsOfClient(string clintId)
        {
            using (PhoneCompanyContext context = new PhoneCompanyContext())
            {
                List <Line> lines = GetLinesByClientId(clintId).ToList();
                List <Call> calls = new List <Call>();
                for (int i = 0; i < lines.Count; i++)
                {
                    //לא עובד!
                    //calls.AddRange(context.Calls.Where(c => c.LineId == lines[i].Id));

                    //כן עובד!
                    foreach (var item in context.Calls)
                    {
                        if (item.LineId == lines[i].Id)
                        {
                            calls.Add(item);
                        }
                    }
                }
                return(calls);
            }
        }