public void Create(string name, decimal price, string imageUrl)
        {
            using (var db = new ByTheCakeContext())
            {
                var product = new Product
                {
                    Name     = name,
                    Price    = price,
                    ImageUrl = imageUrl
                };

                db.Add(product);
                db.SaveChanges();
            }
        }
Esempio n. 2
0
        public void CreateOrder(int userId, IEnumerable <int> productIds)
        {
            using (var db = new ByTheCakeContext())
            {
                var order = new Order
                {
                    UserId       = userId,
                    CreationDate = DateTime.UtcNow,
                    Products     = productIds
                                   .Select(id => new OrderProduct
                    {
                        ProductId = id
                    })
                                   .ToList()
                };

                db.Add(order);
                db.SaveChanges();
            }
        }
Esempio n. 3
0
        public bool Create(string username, string password)
        {
            using (var db = new ByTheCakeContext())
            {
                if (db.Users.Any(u => u.Username == username))
                {
                    return(false);
                }

                var user = new User
                {
                    Username         = username,
                    Password         = password,
                    RegistrationDate = DateTime.UtcNow
                };

                db.Add(user);
                db.SaveChanges();

                return(true);
            }
        }