Ejemplo n.º 1
0
 public List <ProductDA> findAll()
 {
     using (appstoreEntities db = new appstoreEntities())
     {
         return(db.Products.ToList().Select(p => new ProductDA(p)).ToList());
     }
 }
Ejemplo n.º 2
0
 public List <UserDA> findAll()
 {
     using (appstoreEntities db = new appstoreEntities())
     {
         return(db.Users.ToList().Select(p => new UserDA(p)).ToList());
     }
 }
Ejemplo n.º 3
0
 public ProductDA addProduct(ProductDA pd)
 {
     using (appstoreEntities db = new appstoreEntities())
     {
         var rec = ProductDA.Convert(pd);
         db.Products.Add(rec);
         db.SaveChanges();
         return(new ProductDA(rec));
     }
 }
Ejemplo n.º 4
0
 public void deleteProduct(int id)
 {
     using (appstoreEntities db = new appstoreEntities())
     {
         Product product = db.Products.Find(id);
         if (product != null)
         {
             db.Products.Remove(product);
             db.SaveChanges();
         }
     }
 }
Ejemplo n.º 5
0
 public UserDA login(UserDA user)
 {
     using (appstoreEntities db = new appstoreEntities())
     {
         var result = db.Users.SingleOrDefault(p => p.Name == user.Name);
         if (result != null && result.Password == user.Password)
         {
             return(new UserDA(result));
         }
         return(new UserDA {
         });
     }
 }
Ejemplo n.º 6
0
        public UserDA addUser(UserDA user)
        {
            using (appstoreEntities db = new appstoreEntities())
            {
                var result = db.Users.SingleOrDefault(p => p.Name == user.Name);
                if (result == null)
                {
                    var rec = UserDA.Convert(user);
                    db.Users.Add(rec);
                    db.SaveChanges();
                    return(user);
                }

                return(new UserDA {
                });
            }
        }
Ejemplo n.º 7
0
 public ProductDA changeProduct(string id, ProductDA product)
 {
     using (appstoreEntities db = new appstoreEntities())
     {
         if (id == product.Id.ToString())
         {
             var result = db.Products.SingleOrDefault(p => p.Id == product.Id);
             if (result != null)
             {
                 var rec = ProductDA.Update(result, product);
                 db.SaveChanges();
                 return(new ProductDA(rec));
             }
         }
         return(new ProductDA {
         });
     }
 }