public static void Add(int productId, string name, string value)
        {
            using (var dbContext = new DataContext())
            {
                int nameId = 0;
                int valueId = 0;
                var paramName = dbContext.ParamNames.FirstOrDefault(s => s.Name.Equals(name));
                var paramValue = dbContext.ParamValues.FirstOrDefault(s => s.Name.Equals(value));
                if (paramName == null)
                {
                    paramName = dbContext.ParamNames.Add(new ParamName() { Name = name });
                    dbContext.SaveChanges();
                }
                nameId = paramName.ParamNameId;

                if (paramValue == null)
                {
                    paramValue = dbContext.ParamValues.Add(new ParamValue() { Name = value });
                    dbContext.SaveChanges();
                }
                valueId = paramValue.ParamValueId;

                dbContext.Parameters.Add(new Parameter()
                {
                    ParamValueId = valueId,
                    ParamNameId = nameId,
                    ProductId = productId
                });
                dbContext.SaveChanges();
            }
        }
Example #2
0
        public static List<Tag> GetTagsFromString(String StringOfTags)
        {
            using (var dbContext = new DataContext())
            {
                String[] StrTags = StringOfTags.ToLower().Split(new Char[] { ',' });
                List<Tag> list = new List<Tag>();

                foreach (var tag in StrTags)
                {
                    var tags = dbContext.Tags.Where(s => s.Name == tag);
                    if (tags.Count() == 0)
                    {
                        dbContext.Tags.Add(new Tag { Name = tag, Value = 1 });
                        dbContext.SaveChanges();
                    }
                    else
                    {
                        tags.ToList()[0].Value++;
                        dbContext.SaveChanges();
                    }
                    list.Add(dbContext.Tags.FirstOrDefault(s => s.Name == tag));
                }
                return list;
            }
        }
 public void Edit(Category category)
 {
     using (var dbContext = new DataContext())
     {
         dbContext.Entry(category).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
 public void Add(Category category)
 {
     using (var dbContext = new DataContext())
     {
         dbContext.Categories.Add(category);
         dbContext.SaveChanges();
     }
 }
Example #5
0
 public void Edit(Product product)
 {
     using (var dbContext = new DataContext())
     {
         dbContext.Entry(product).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
Example #6
0
 public static void Add(Basket basket)
 {
     using (var dbContext = new DataContext())
     {
         dbContext.Baskets.Add(basket);
         dbContext.SaveChanges();
     }
 }
Example #7
0
 public static void Add(Adress adress)
 {
     using (var dbContext = new DataContext())
     {
         dbContext.Adresses.Add(adress);
         dbContext.SaveChanges();
     }
 }
Example #8
0
 public static void Edit(Adress adress)
 {
     using (var dbContext = new DataContext())
     {
         dbContext.Entry(adress).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
Example #9
0
 public void Delete(int id)
 {
     using (var dbContext = new DataContext())
     {
         User user = dbContext.Users.Find(id);
         dbContext.Users.Remove(user);
         dbContext.SaveChanges();
     }
 }
Example #10
0
 public static void Delete(int id)
 {
     using (var dbContext = new DataContext())
     {
         var adress = dbContext.Adresses.Find(id);
         dbContext.Adresses.Remove(adress);
         dbContext.SaveChanges();
     }
 }
Example #11
0
 public void Delete(int id)
 {
     using (var dbContext = new DataContext())
     {
         Category category = dbContext.Categories.Find(id);
         dbContext.Categories.Remove(category);
         dbContext.SaveChanges();
     }
 }
Example #12
0
 public void Delete(int id)
 {
     using (var dbContext = new DataContext())
     {
         Product product = dbContext.Products.Find(id);
         dbContext.Products.Remove(product);
         dbContext.SaveChanges();
     }
 }
Example #13
0
 public void Edit(int id, int idParent)
 {
     using (var dbContext = new DataContext())
     {
         Category category = Find(id);
         category.Parent = Find(idParent);
         dbContext.Entry(category).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
Example #14
0
 public static void Delete(int productId, int userId)
 {
     using (var dbContext = new DataContext())
     {
         var basket = dbContext.Baskets.Where(s => s.UserId == userId)
             .First(s => s.ProductId == productId);
         dbContext.Baskets.Remove(basket);
         dbContext.SaveChanges();
     }
 }
Example #15
0
 public int AddOrderProduct(OrderProduct orderProduct)
 {
     using (var dbContext = new DataContext())
     {
         int id = dbContext.OrderProducts.Add(orderProduct).Id;
         var product = dbContext.Store.Find(orderProduct.ProductId);
         product.Quantity--;
         dbContext.Entry(product).State = EntityState.Modified;
         dbContext.SaveChanges();
         return id;
     }
 }
Example #16
0
        public static void Delete(int id)
        {
            using (var dbContext = new DataContext())
            {
                Picture pic = dbContext.Pictures.Find(id);

                var product = dbContext.Products.Find(pic.ProductId);
                product.Picture.Remove(pic);
                dbContext.Pictures.Remove(pic);
                dbContext.Entry(product).State = EntityState.Modified;
                dbContext.SaveChanges();
            }
        }
Example #17
0
 public static void Add(Picture picture)
 {
     using (var dbContext = new DataContext())
     {
         dbContext.Pictures.Add(picture);
         var product = dbContext.Products.Find(picture.ProductId);
         List<Picture> listPicture = product.Picture.ToList();
         listPicture.Add(picture);
         product.Picture = listPicture;
         dbContext.Entry(product).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
Example #18
0
        public void Add(Product product, String StringTags)
        {
            using (var dbContext = new DataContext())
            {
                foreach (var tag in TagRepository.GetTagsFromString(StringTags))
                {
                    product.Tags.Add(dbContext.Tags.Find(tag.TagId));
                }

                dbContext.Products.Add(product);
                dbContext.SaveChanges();
            }
        }
Example #19
0
 public int Add(Order order)
 {
     using (var dbContext = new DataContext())
     {
         dbContext.Orders.Add(order);
         dbContext.SaveChanges();
         int id = dbContext.Orders
             .Where(s => s.UserId == order.UserId)
             .Where(s => s.TotalPrice == order.TotalPrice)
             .FirstOrDefault(s => s.AdressId == order.AdressId).OrderId;
         return id;
     }
 }
 public static void Delete(int idProduct, int idValue, int idName)
 {
     using (var dbContext = new DataContext())
     {
         var param = dbContext.Parameters
             .Where(s => s.ParamNameId == idName)
             .Where(s => s.ParamValueId == idValue)
             .First(s => s.ProductId == idProduct);
         if (param != null)
         {
             dbContext.Parameters.Remove(param);
         }
         dbContext.SaveChanges();
     }
 }
        public static void Add(String text, int productId, int userId)
        {
            using (var dbContext = new DataContext())
            {
                var listProduct = new List<Product>();

                var comment = new Description() {
                    TextDescription = text,
                    Data = DateTime.Now,
                    UserId = userId
                };
                var product = dbContext.Products.Find(productId);
                product.Descriptions.Add(comment);

                var user = dbContext.Users.Find(userId);
                user.Descriptions.Add(comment);
                dbContext.Entry(user).State = EntityState.Modified;

                dbContext.Descriptions.Add(comment);
                dbContext.Entry(product).State = EntityState.Modified;
                dbContext.SaveChanges();
            }
        }