Esempio n. 1
0
        public bool LoginUser(string fullName, string password)
        {
            using (var db = new CellDbContext())
            {
                if (!db.Users.Any())
                {
                    UserDb _user = new UserDb()
                    {
                        Id       = 0,
                        FullName = "admin",
                        Password = "******"
                    };
                    _user.ToDTO();
                    db.Users.Add(_user);
                    db.SaveChanges();
                }
                if (db.Users.Select(a => a.FullName == fullName).FirstOrDefault() &&
                    db.Users.Select(a => a.Password == password).FirstOrDefault())
                {
                    return(true);
                }

                else
                {
                    return(false);
                }
            }
        }
 public bool UpdatePackage(Package package)
 {
     using (var db = new CellDbContext())
     {
         try
         {
             PackageDb packageToUpdate = db.Packages.SingleOrDefault(p => p.Id == package.Id);
             db.Entry(package).State = System.Data.Entity.EntityState.Modified;
             packageToUpdate         = package.FromDTO();
             db.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             return(false);
         }
     }
 }
Esempio n. 3
0
 public bool UpdateClient(Client client)
 {
     using (var db = new CellDbContext())
     {
         try
         {
             ClientDb clientToUpdate = db.Clients.SingleOrDefault(c => c.ClientId == client.ClientId);
             db.Entry(client).State = System.Data.Entity.EntityState.Modified;
             clientToUpdate         = client.FromDTO();
             db.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             return(false);
         }
     }
 }
Esempio n. 4
0
 public bool UpdateClientLine(Line line)
 {
     using (var db = new CellDbContext())
     {
         try
         {
             LineDb lineToUpdate = db.Lines.SingleOrDefault(l => l.ClientId == line.ClientId);
             db.Entry(lineToUpdate).State = System.Data.Entity.EntityState.Modified;
             lineToUpdate = line.FromDTO();
             db.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             return(false);
         }
     }
 }
Esempio n. 5
0
 public bool RemoveClientLine(string number)
 {
     using (var db = new CellDbContext())
     {
         try
         {
             LineDb lineToRemove = db.Lines.SingleOrDefault(l => l.Number == number);
             db.Lines.Remove(lineToRemove);
             db.Entry(lineToRemove).State = System.Data.Entity.EntityState.Deleted;
             db.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             return(false);
         }
     }
 }
Esempio n. 6
0
 public Client AddClient(Client client)
 {
     using (var db = new CellDbContext())
     {
         try
         {
             ClientDb newClient = client.FromDTO();
             db.Clients.Add(newClient);
             db.Entry(newClient).State = System.Data.Entity.EntityState.Added;
             db.SaveChanges();
             return(newClient.ToDTO());
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             return(null);
         }
     }
 }
Esempio n. 7
0
 public bool RemoveClient(string clientId)
 {
     using (var db = new CellDbContext())
     {
         try
         {
             ClientDb clientToRemove = db.Clients.SingleOrDefault(c => c.ClientId == clientId);
             db.Clients.Remove(clientToRemove);
             db.Entry(clientToRemove).State = System.Data.Entity.EntityState.Deleted;
             db.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             return(false);
         }
     }
 }
 public bool UpdateClientType(ClientType clientType)
 {
     using (var db = new CellDbContext())
     {
         try
         {
             ClientTypeDb TypeToUpdate = db.ClientTypes.Where(c => c.TypeName == clientType.TypeName).FirstOrDefault();
             TypeToUpdate.ToDTO();
             db.Entry(TypeToUpdate).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             return(false);
         }
     }
 }
 public Package AddPackage(Package package)
 {
     using (var db = new CellDbContext())
     {
         try
         {
             PackageDb newPackage;
             PackageDb packageDb = package.FromDTO();
             newPackage = db.Packages.Add(packageDb);
             db.Entry(package).State = System.Data.Entity.EntityState.Added;
             db.SaveChanges();
             return(newPackage.ToDTO());
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             return(null);
         }
     }
 }
Esempio n. 10
0
 public Line AddClientLine(Line line, string clientId)
 {
     using (var db = new CellDbContext())
     {
         try
         {
             LineDb newLine = line.FromDTO();
             newLine.ClientId        = clientId;
             newLine                 = db.Lines.Add(newLine);
             db.Entry(newLine).State = System.Data.Entity.EntityState.Added;
             db.SaveChanges();
             return(newLine.ToDTO());
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             return(null);
         }
     }
 }
 public ClientType AddClientType(ClientType clientType)
 {
     using (var db = new CellDbContext())
     {
         try
         {
             ClientTypeDb newType;
             ClientTypeDb typeDb = clientType.FromDTO();
             newType = db.ClientTypes.Add(typeDb);
             db.Entry(newType).State = System.Data.Entity.EntityState.Added;
             db.SaveChanges();
             return(newType.ToDTO());
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             return(null);
         }
     }
 }