Example #1
0
 public void Add(Role role)
 {
     using (var dbContext = new SportStoreDbContext())
     {
         dbContext.RoleDbSet.Add(role);
         dbContext.SaveChanges();
     }
 }
Example #2
0
 public void Remove(PurchasedProduct purchasedProduct)
 {
     using (var dbContext = new SportStoreDbContext())
     {
         dbContext.PurchasedProductDbSet.Remove(purchasedProduct);
         dbContext.SaveChanges();
     }
 }
Example #3
0
 public void Remove(ShippingAddress shippingAddress)
 {
     using (var dbContext = new SportStoreDbContext())
     {
         var shippingAddressInRepository = dbContext.ShippingAddressDbSet.Find(shippingAddress.Id);
         dbContext.ShippingAddressDbSet.Remove(shippingAddressInRepository);
         dbContext.SaveChanges();
     }
 }
Example #4
0
 public void Update(Manufacturer manufacturer)
 {
     using (var dbContext = new SportStoreDbContext())
     {
         var manufacturerInRepository = dbContext.ManufacturerDbSet.Find(manufacturer.Id);
         dbContext.Entry(manufacturerInRepository).CurrentValues.SetValues(manufacturer);
         dbContext.SaveChanges();
     }
 }
Example #5
0
 public void Remove(Manufacturer manufacturer)
 {
     using (var dbContext = new SportStoreDbContext())
     {
         var manufacturerInRepository = dbContext.ManufacturerDbSet.Find(manufacturer.Id);
         dbContext.ManufacturerDbSet.Remove(manufacturerInRepository);
         dbContext.SaveChanges();
     }
 }
Example #6
0
 public void Remove(PaymentMethod payment)
 {
     using (var dbContext = new SportStoreDbContext())
     {
         var paymentMethodInRepository = dbContext.PaymentMethodDbSet.Find(payment.Id);
         dbContext.PaymentMethodDbSet.Remove(paymentMethodInRepository);
         dbContext.SaveChanges();
     }
 }
Example #7
0
 public void Update(PaymentMethod payment)
 {
     using (var dbContext = new SportStoreDbContext())
     {
         var paymentMethodInRepository = dbContext.PaymentMethodDbSet.Find(payment.Id);
         dbContext.Entry(paymentMethodInRepository).CurrentValues.SetValues(payment);
         dbContext.SaveChanges();
     }
 }
Example #8
0
 public void Update(PurchasedProduct purchasedProduct)
 {
     using (var dbContext = new SportStoreDbContext())
     {
         var purchasedProductInRepository = GetById(purchasedProduct.Id);
         dbContext.Entry(purchasedProductInRepository).CurrentValues.SetValues(purchasedProduct);
         dbContext.SaveChanges();
     }
 }
Example #9
0
 public void Update(ShippingAddress shippingAddress)
 {
     using (var dbContext = new SportStoreDbContext())
     {
         var shippingAddressInRepository = dbContext.ShippingAddressDbSet.Find(shippingAddress.Id);
         dbContext.Entry(shippingAddressInRepository).CurrentValues.SetValues(shippingAddress);
         dbContext.SaveChanges();
     }
 }
Example #10
0
        public void Remove(Cart cart)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                var cartInRepository = dbContext.CartDbSet.Include(i => i.Products).SingleOrDefault(c => c.Id == cart.Id);
                dbContext.CartDbSet.Remove(cartInRepository);

                dbContext.SaveChanges();
            }
        }
Example #11
0
        public void Remove(Review review)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                var reviewInRepository = dbContext.ReviewDbSet.Include(i => i.PurchasedProduct).Include(i => i.User).SingleOrDefault(r => r.Id == review.Id);

                dbContext.ReviewDbSet.Remove(reviewInRepository);
                dbContext.SaveChanges();
            }
        }
Example #12
0
        public void Remove(Role role)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                var roleInRepository = dbContext.RoleDbSet.Find(role.Name);
                dbContext.RoleDbSet.Remove(roleInRepository);

                dbContext.SaveChanges();
            }
        }
Example #13
0
        public void Update(Role role)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                var roleInRepository = dbContext.RoleDbSet.Find(role.Name);
                roleInRepository.Description = role.Description;

                dbContext.SaveChanges();
            }
        }
Example #14
0
        public void Add(Session session)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                session.User = dbContext.UserDbSet.Find(session.User.UserName);

                dbContext.SessionDbSet.Add(session);
                dbContext.SaveChanges();
            }
        }
Example #15
0
        public void Remove(User user)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                var userInRepository = dbContext.UserDbSet.Find(user.UserName);
                dbContext.UserDbSet.Remove(userInRepository);

                dbContext.SaveChanges();
            }
        }
Example #16
0
        public void Remove(Category category)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                var categoryInRepository = dbContext.CategoryDbSet.Include(i => i.CustomFields).SingleOrDefault(c => c.Id == category.Id);
                categoryInRepository.CustomFields.Clear();

                dbContext.CategoryDbSet.Remove(categoryInRepository);
                dbContext.SaveChanges();
            }
        }
Example #17
0
        public void Remove(Product product)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                var productInRepository = dbContext.ProductDbSet.Include(i => i.CustomFields).SingleOrDefault(p => p.Code == product.Code);
                productInRepository.CustomFields.Clear();

                dbContext.ProductDbSet.Remove(productInRepository);
                dbContext.SaveChanges();
            }
        }
Example #18
0
        public void Add(User user)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                user.Role = dbContext.RoleDbSet.Find(user.Role.Name);
                user.Cart = dbContext.CartDbSet.Find(user.Cart.Id);

                dbContext.UserDbSet.Add(user);
                dbContext.SaveChanges();
            }
        }
Example #19
0
        public void Add(Review review)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                review.PurchasedProduct = dbContext.PurchasedProductDbSet.Find(review.PurchasedProduct.Id);
                review.User             = dbContext.UserDbSet.Find(review.User.UserName);

                dbContext.ReviewDbSet.Add(review);

                dbContext.SaveChanges();
            }
        }
Example #20
0
        public void Update(Cart cart)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                var cartInRepository = dbContext.CartDbSet.Include(i => i.Products).SingleOrDefault(c => c.Id == cart.Id);

                foreach (var cartProduct in cart.Products)
                {
                    var productInCartInRepository = cartInRepository.Products.SingleOrDefault(p => p.Product.Code == cartProduct.Product.Code);

                    if (cartProduct.Quantity > 0)
                    {
                        if (productInCartInRepository != null)
                        {
                            productInCartInRepository.Quantity = cartProduct.Quantity;
                        }
                        else
                        {
                            var productInRepository = dbContext.ProductDbSet.Find(cartProduct.Product.Code);

                            cartInRepository.Products.Add(new ProductInCart()
                            {
                                Product     = productInRepository,
                                ProductCode = productInRepository.Code,
                                Quantity    = cartProduct.Quantity,
                            });
                        }
                    }
                    else
                    {
                        cartInRepository.Products.Remove(productInCartInRepository);
                    }
                }

                var productsInCartInRepositoryDeleted = cartInRepository.Products.FindAll(p => !cart.Products.Any(cp => cp.Product.Code == p.Product.Code));

                foreach (var productInCartInRepositoryDeleted in productsInCartInRepositoryDeleted)
                {
                    cartInRepository.Products.Remove(productInCartInRepositoryDeleted);
                }

                if (cartInRepository.Products.Count == 0)
                {
                    cartInRepository.Products.Clear();
                }

                dbContext.SaveChanges();
            }
        }
Example #21
0
        public void Update(Product product)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                var productInRepository = dbContext.ProductDbSet.Include(i => i.CustomFields.Select(ii => ii.CustomField)).SingleOrDefault(p => p.Code == product.Code);

                productInRepository.Name         = product.Name;
                productInRepository.Description  = product.Description;
                productInRepository.Manufacturer = dbContext.ManufacturerDbSet.Find(product.Manufacturer.Id);
                productInRepository.Price        = product.Price;
                productInRepository.Category     = dbContext.CategoryDbSet.Include(i => i.CustomFields).SingleOrDefault(c => c.Id == product.Category.Id);
                productInRepository.Stock        = product.Stock;

                //productInRepository.Photos = dbContext.CategoryDbSet.Find(product.Category.Name);

                // productInRepository.CustomFields
                if (product.CustomFields != null)
                {
                    foreach (var productCustomFieldValue in product.CustomFields)
                    {
                        var customFieldValueInRepository = productInRepository.CustomFields.SingleOrDefault(cf => cf.CustomField.Name == productCustomFieldValue.CustomField.Name);

                        if (customFieldValueInRepository != null)
                        {
                            customFieldValueInRepository.Value = productCustomFieldValue.Value;
                        }
                        else
                        {
                            productCustomFieldValue.CustomField     = TryFindCustomFieldInCategory(productInRepository.Category, productCustomFieldValue.CustomField.Name);
                            productCustomFieldValue.CustomFieldName = productCustomFieldValue.CustomField.Name;
                            productInRepository.CustomFields.Add(productCustomFieldValue);
                        }
                    }

                    var customFieldValuesInRepositoryToDelete = productInRepository.CustomFields.FindAll(cf => !product.CustomFields.Any(ccf => ccf.CustomField.Name == cf.CustomField.Name));

                    foreach (var customFieldValueInRepositoryToDelete in customFieldValuesInRepositoryToDelete)
                    {
                        productInRepository.CustomFields.Remove(customFieldValueInRepositoryToDelete);
                    }
                }
                else
                {
                    productInRepository.CustomFields.Clear();
                }

                dbContext.SaveChanges();
            }
        }
Example #22
0
        public void Update(User user)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                var userInRepository = dbContext.UserDbSet.Find(user.UserName);
                userInRepository.FirstName = user.FirstName;
                userInRepository.LastName  = user.LastName;
                userInRepository.Email     = user.Email;
                userInRepository.Address   = user.Address;
                userInRepository.Role      = dbContext.RoleDbSet.Find(user.Role.Name);
                userInRepository.Dots      = user.Dots;

                dbContext.SaveChanges();
            }
        }
Example #23
0
        public void Add(Purchase purchase)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                foreach (var purchasedProduct in purchase.Products)
                {
                    purchasedProduct.Product = dbContext.ProductDbSet.Find(purchasedProduct.Product.Code);
                }

                purchase.PaymentMethod   = dbContext.PaymentMethodDbSet.Find(purchase.PaymentMethod.Id);
                purchase.ShippingAddress = dbContext.ShippingAddressDbSet.Find(purchase.ShippingAddress.Id);

                dbContext.PurchaseDbSet.Add(purchase);
                dbContext.SaveChanges();
            }
        }
Example #24
0
        public void Set(string key, string value)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                var configEntry = dbContext.ConfigDbSet.SingleOrDefault(e => e.Key == key);

                if (configEntry == null)
                {
                    dbContext.ConfigDbSet.Add(new ConfigEntry()
                    {
                        Key   = key,
                        Value = value
                    });
                }
                else
                {
                    configEntry.Value = value;
                }

                dbContext.SaveChanges();
            }
        }
Example #25
0
        public void Add(Product product)
        {
            using (var dbContext = new SportStoreDbContext())
            {
                product.Category     = dbContext.CategoryDbSet.Include(i => i.CustomFields).SingleOrDefault(c => c.Id == product.Category.Id);
                product.Manufacturer = dbContext.ManufacturerDbSet.Find(product.Manufacturer.Id);

                // productInRepository.CustomFields
                if (product.CustomFields != null)
                {
                    foreach (var customFieldValue in product.CustomFields)
                    {
                        customFieldValue.CustomField     = TryFindCustomFieldInCategory(product.Category, customFieldValue.CustomField.Name);
                        customFieldValue.CustomFieldName = customFieldValue.CustomField.Name;
                    }
                }

                dbContext.ProductDbSet.Add(product);

                dbContext.SaveChanges();
            }
        }