Exemplo n.º 1
0
 public IEnumerable <Client> GetAllClients()
 {
     using (var dbContext = new BFUContext())
     {
         return(dbContext.Clients.ToList());
     }
 }
Exemplo n.º 2
0
 public IEnumerable <Product> GetAllProducts()
 {
     using (var dbContext = new BFUContext())
     {
         return(dbContext.Products.ToList());
     }
 }
Exemplo n.º 3
0
 public IEnumerable <Product> GetForeignProducts(long id)
 {
     using (var dbContext = new BFUContext())
     {
         return(dbContext.Products.ToList().FindAll(pr => pr.OwnerId != id));
     }
 }
Exemplo n.º 4
0
 public Product FindProduct(long id)
 {
     using (var dbContext = new BFUContext())
     {
         return(dbContext.Products.FirstOrDefault(p => p.Id == id));
     }
 }
Exemplo n.º 5
0
 public void AddProduct(Product product)
 {
     using (var dbContext = new BFUContext())
     {
         dbContext.Products.Add(product);
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 6
0
 public void AddClient(Client client)
 {
     using (var dbContext = new BFUContext())
     {
         dbContext.Clients.Add(client);
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 7
0
 public void Sale(long prodId)
 {
     using (var dbContext = new BFUContext())
     {
         Product pr = FindProduct(prodId);
         pr.SaleProduct();
         dbContext.Entry(pr).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 8
0
 public void ChangeClient(Client client)
 {
     using (var dbContext = new BFUContext())
     {
         Client cl = FindClient(client.Id);
         cl = client;
         dbContext.Entry(cl).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 9
0
 public void TakeFromCart(long id)
 {
     using (var dbContext = new BFUContext())
     {
         Product pr = FindProduct(id);
         pr.ProductReturn();
         dbContext.Entry(pr).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 10
0
 public void DeleteProduct(long id)
 {
     using (var dbContext = new BFUContext())
     {
         var pr = FindProduct(id);
         dbContext.Entry(pr).State = EntityState.Modified;
         dbContext.Products.Remove(pr);
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 11
0
 public void ChangeProduct(Product product)
 {
     using (var dbContext = new BFUContext())
     {
         Product pr = FindProduct(product.Id);
         pr = product;
         dbContext.Entry(pr).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 12
0
 public void DeleteAllProducts()
 {
     using (var dbContext = new BFUContext())
     {
         foreach (var p in dbContext.Products)
         {
             dbContext.Products.Remove(p);
         }
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 13
0
 public void DeleteAllClients()
 {
     using (var dbContext = new BFUContext())
     {
         foreach (var c in dbContext.Clients)
         {
             dbContext.Clients.Remove(c);
         }
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 14
0
 public bool CheckUsername(string name)
 {
     using (var dbContext = new BFUContext())
     {
         foreach (var c in dbContext.Clients)
         {
             if (c.UserName == name)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 15
0
 public Client FindClient(string name)
 {
     using (var dbContext = new BFUContext())
     {
         foreach (var c in dbContext.Clients)
         {
             if (c.UserName == name)
             {
                 return(c);
             }
         }
         return(null);
     }
 }
Exemplo n.º 16
0
 public Client FindClient(long id)
 {
     using (var dbContext = new BFUContext())
     {
         foreach (var c in dbContext.Clients)
         {
             if (c.Id == id)
             {
                 return(c);
             }
         }
         return(null);
     }
 }
Exemplo n.º 17
0
 public void DeleteClient(int id)
 {
     using (var dbContext = new BFUContext())
     {
         foreach (var c in dbContext.Clients)
         {
             if (c.Id == id)
             {
                 dbContext.Clients.Remove(c);
             }
         }
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 18
0
 public void ReturnToSale()
 {
     using (var dbContext = new BFUContext())
     {
         foreach (var p in dbContext.Products)
         {
             if ((DateTime.Now - p.DateBay) >= TimeSpan.FromMinutes(2) && p.Sold == 2)
             {
                 p.ProductReturn();
                 dbContext.Entry(p).State = EntityState.Modified;
             }
         }
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 19
0
 public Product PutToCart(long prodId, long userId)
 {
     using (var dbContext = new BFUContext())
     {
         Product pr = FindProduct(prodId);
         pr.Sold    = 1;
         pr.DateBay = DateTime.Now;
         if (userId != 0)
         {
             pr.UserId = userId;
         }
         dbContext.Entry(pr).State = EntityState.Modified;
         dbContext.SaveChanges();
         return(pr);
     }
 }
Exemplo n.º 20
0
        public List <Product> CreateCart(long?id)
        {
            var cartProducts = new List <Product>();

            using (var dbContext = new BFUContext())
            {
                foreach (var p in dbContext.Products)
                {
                    if ((p.Sold == 1 && p.UserId == id) || (p.Sold == 1 && p.UserId == null && id == null))
                    {
                        cartProducts.Add(p);
                    }
                }
            }
            return(cartProducts);
        }