Exemplo n.º 1
0
        public static bool AddProductImages(string[] Images)
        {
            int idProduct = Convert.ToInt32(Images[(Images.Length) - 1]);

            using (Baby_BEntities1 db = new Baby_BEntities1())
            {
                for (int i = 0; i < Images.Length - 1; i++)
                {
                    ProductImage im = new ProductImage();
                    im.IdProduct = idProduct;
                    im.PathImage = ConstsValues.IMAGE_PATH + Path.GetFileName(Images[i]);
                    db.ProductImage.Add(im);
                }
                try
                {
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
 public static List <shopping> GetShopping(int id)
 {
     using (Baby_BEntities1 db = new Baby_BEntities1())
     {
         List <shopping>     f        = new List <shopping>();
         List <ShoppingCart> userList = db.ShoppingCart.Where(s => s.IdUser == id).ToList();
         if (userList != null)
         {
             foreach (var item in userList)
             {
                 f.Add(new shopping
                 {
                     NameProduct       = item.NameProduct,
                     Category          = item.Category,
                     Subcategory       = item.Subcategory,
                     AmountOfPurchases = item.AmountOfPurchases,
                     ImageOfProduct    = item.ImageOfProduct,
                     Company           = item.Company,
                     DateAdded         = item.DateAdded,
                     Color             = item.Color,
                     Price             = item.Price,
                     size = item.size,
                     DiscountPercentage = item.DiscountPercentage,
                 });
                 //shopping n = new shopping() {NameProduct=item.NameProduct,Color=item.Color };
                 //f[f.Count] = new shopping();
                 //f[f.Count] = n;
             }
             return(f);
         }
         return(null);
     }
 }
Exemplo n.º 3
0
 public static int GetUser(string mail, string password)
 {
     using (Baby_BEntities1 db = new Baby_BEntities1())
     {
         Users user = db.Users.Where(u => u.EMail == mail && u.UserPassword == password).First();
         if (user == null)
         {
             return(0);
         }
         return(user.IdUser);
     }
 }
Exemplo n.º 4
0
 public static int Register(Users register)
 {
     using (Baby_BEntities1 db = new Baby_BEntities1())
     {
         try
         {
             db.Users.Add(register);
             db.SaveChanges();
             int id = db.Users.Where(c => c.EMail == register.EMail && c.UserPassword == register.UserPassword).Select(c => c.IdUser).FirstOrDefault();
             return(id);
         }
         catch (Exception e)
         {
             //throw new Exception();
             return(0);
         }
     }
 }
Exemplo n.º 5
0
        public static List <Product> GetAllProducts(int IdCategory)
        {
            List <Product>          L             = new List <Product>();
            List <int>              IdSubCategory = new List <int>();
            List <Dto.ProductImage> Images        = new List <Dto.ProductImage>();
            List <ProductImage>     ProductImages = new List <ProductImage>();

            using (Baby_BEntities1 db = new Baby_BEntities1())
            {
                IdSubCategory = db.SubCategory.Where(u => u.IdCategory == IdCategory).Select(o => o.IdSubCategory).ToList();

                foreach (var item in db.Products)
                {
                    for (int i = 0; i < IdSubCategory.Count(); i++)
                    {
                        if (item.IdSubcategory == IdSubCategory[i])
                        {
                            Images.Clear();
                            ProductImages = db.ProductImage.Where(o => o.IdProduct == item.IdProduct).ToList();
                            Dto.ProductImage im = new Dto.ProductImage();
                            im.PathImage = ProductImages[0].PathImage;
                            Images.Add(im);

                            Product p = new Product();
                            p.Price              = item.Price;
                            p.NameProduct        = item.NameProduct;
                            p.IdProduct          = item.IdProduct;
                            p.DescriptionProduct = item.DescriptionProduct;
                            ProductImages        = db.ProductImage.Where(o => o.IdProduct == item.IdProduct).ToList();
                            p.ProductImage       = Images;
                            L.Add(p);
                        }
                    }
                }
            }
            return(L);
        }