Beispiel #1
0
        public IHttpResponse Add(IHttpRequest req)
        {
            var formData = req.FormData;

            var name     = formData["name"];
            var price    = formData["price"];
            var imageUrl = formData["imageUrl"];

            var cake = new Product
            {
                Name     = name,
                Price    = decimal.Parse(price),
                ImageUrl = imageUrl
            };

            using (var db = new ByTheCakeDbContext())
            {
                db.Products.Add(cake);
                db.SaveChanges();
            }

            this.ViewData["name"]       = name;
            this.ViewData["price"]      = price;
            this.ViewData["image"]      = imageUrl;
            this.ViewData["showResult"] = "block";

            return(this.FileViewResponse(@"cakes\add"));
        }
        public void SendOrder(string username, Dictionary <int, List <Product> > products)
        {
            var productIds = new List <int>();

            foreach (var kvp in products)
            {
                productIds.Add(kvp.Key);
            }

            using (var db = new ByTheCakeDbContext())
            {
                var user   = db.Users.SingleOrDefault(x => x.Username == username);
                var userId = user.Id;

                var order = new Order
                {
                    UserId         = userId,
                    DateOfCreation = DateTime.UtcNow,
                    OrderProducts  = productIds
                                     .Select(id => new OrderProduct
                    {
                        ProductId = id
                    })
                                     .ToList()
                };

                user.Orders.Add(order);

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

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


                db
                .Users
                .Add(user);

                db.SaveChanges();

                return(true);
            }
        }
Beispiel #4
0
        public void Create(string name, decimal price, string imageUrl)
        {
            using (var db = new ByTheCakeDbContext())
            {
                var product = new Product(name, price, imageUrl);

                db.Add(product);
                db.SaveChanges();
            }
        }
Beispiel #5
0
        public IHttpResponse FinishOrder(IHttpRequest req)
        {
            var session = req.Session;

            var userId = session.Get <int>(SessionStore.CurrentUserKey);

            var products = session.Get <ShoppingCart>(ShoppingCart.SessionKey).Orders;

            var productIds = products.Select(p => p.Id).ToList();

            using (var db = new ByTheCakeDbContext())
            {
                var order = new Order(userId);
                db.Orders.Add(order);
                db.SaveChanges();

                foreach (var product in products)
                {
                    int prodId     = product.Id;
                    int productQty = productIds.Count(id => id == prodId);

                    if (productQty > 0)
                    {
                        productIds.RemoveAll(id => id == prodId);

                        var productOrder = new ProductOrder(product.Id, order.Id, productQty);

                        db.ProductOrders.Add(productOrder);
                    }
                    if (productIds.Count == 0)
                    {
                        break;
                    }
                }

                db.SaveChanges();
            }

            req.Session.Get <ShoppingCart>(ShoppingCart.SessionKey).Orders.Clear();

            return(this.FileViewResponse(@"shopping\finish-order"));
        }
        public void SaveInDb(string name, decimal price, string imageUrl)
        {
            using (var db = new ByTheCakeDbContext())
            {
                var product = new Product();
                product.Name     = name;
                product.Price    = price;
                product.ImageUrl = imageUrl;

                db.Products.Add(product);
                db.SaveChanges();
            }
        }
        public void Add(ProductViewModel model)
        {
            using (var db = new ByTheCakeDbContext())
            {
                db.Products.Add(new Product
                {
                    Name     = model.Name,
                    Price    = model.Price,
                    ImageUrl = model.PictureUrl
                });

                db.SaveChanges();
            }
        }
Beispiel #8
0
        public void Create(string name, decimal price, string PictureUrl)
        {
            using (var db = new ByTheCakeDbContext())
            {
                var product = new Product
                {
                    Name     = name,
                    Price    = price,
                    ImageUrl = PictureUrl
                };

                db.Products.Add(product);
                db.SaveChanges();
            }
        }
Beispiel #9
0
        public void Create(string name, decimal price, string imageUrl)
        {
            using (var context = new ByTheCakeDbContext())
            {
                var product = new Product
                {
                    Name     = name,
                    Price    = price,
                    ImageUrl = imageUrl
                };

                context.Add(product);
                context.SaveChanges();
            }
        }
        public void CreateProduct(string name, decimal price, string imageUrl)
        {
            using (ByTheCakeDbContext database = new ByTheCakeDbContext())
            {
                Product product = new Product
                {
                    Name     = name,
                    Price    = price,
                    ImageUrl = imageUrl
                };

                database.Products.Add(product);
                database.SaveChanges();
            }
        }
Beispiel #11
0
        public void Create(string name, decimal price, string imageUrl)
        {
            using (var db = new ByTheCakeDbContext())
            {
                var product = new Data.Models.Product()
                {
                    Name     = name,
                    Price    = price,
                    ImageUrl = imageUrl
                };

                db.Add(product);
                db.SaveChanges();
            }
        }
Beispiel #12
0
        public bool Create(string username, string password)
        {
            using (var db = new ByTheCakeDbContext())
            {
                if (db.Users.Any(x => x.Username == username))
                {
                    return(false);
                }

                var user = new User(username, password);
                db.Add(user);
                db.SaveChanges();
            }

            return(true);
        }
Beispiel #13
0
        public IHttpResponse Register(IHttpRequest request)
        {
            this.ViewData["showError"]   = "none";
            this.ViewData["authDisplay"] = "none";

            var formData = request.FormData;

            const string formNameKey     = "name";
            const string formUsernameKey = "username";
            const string formPassKey     = "password";
            const string formConfirmKey  = "confirm";

            if (!formData.ContainsKey(formNameKey) || !formData.ContainsKey(formPassKey) ||
                !formData.ContainsKey(formUsernameKey) || !formData.ContainsKey(formConfirmKey))
            {
                return(new BadRequestResponse());
            }

            string name     = formData[formNameKey];
            string username = formData[formUsernameKey];
            string password = formData[formPassKey];
            string confirm  = formData[formConfirmKey];

            if (HasWrongFields(name, username, password, confirm))
            {
                return(this.FileViewResponse(@"account\register"));
            }

            if (password != confirm)
            {
                this.ViewData["error"]     = "Password does not match the confirm password.";
                this.ViewData["showError"] = "block";
                return(this.FileViewResponse(@"account\register"));
            }

            string passwordHash = PasswordUtilities.GetHash(password);

            User user = new User(name, username, passwordHash, DateTime.UtcNow);

            using (var db = new ByTheCakeDbContext())
            {
                db.Users.Add(user);
                db.SaveChanges();
            }

            return(new RedirectResponse(@"/login"));
        }
        public void CreateOrder(int userId, IEnumerable <int> productIds)
        {
            using (var db = new ByTheCakeDbContext())
            {
                var order = new Order
                {
                    UserId       = userId,
                    CreationDate = DateTime.UtcNow,
                    Products     = productIds.Select(id => new OrderProduct {
                        ProductId = id
                    }).ToList()
                };

                db.Orders.Add(order);
                db.SaveChanges();
            }
        }
Beispiel #15
0
        public void CreateOrder(int userId, IEnumerable <int> ids)
        {
            using (var db = new ByTheCakeDbContext())
            {
                var order = new Order
                {
                    UserId        = userId,
                    CreationDate  = DateTime.Now,
                    OrderProducts = ids.Select(p => new OrderProduct()
                    {
                        ProductId = p
                    }).ToList(),
                };

                db.Add(order);
                db.SaveChanges();
            }
        }
        public void CreateOrder(int userId, Dictionary <int, int> products)
        {
            using (var db = new ByTheCakeDbContext())
            {
                var order = new Order
                {
                    UserId       = userId,
                    CreationTime = DateTime.UtcNow,
                    Products     = products.Keys.Select(id => new OrderProduct
                    {
                        ProductId = id,
                        Quantity  = products[id]
                    }).ToList()
                };

                db.Add(order);
                db.SaveChanges();
            }
        }
        public void CreateOrder(int userId, IDictionary <int, int> productIdWithQuantity)
        {
            using (ByTheCakeDbContext database = new ByTheCakeDbContext())
            {
                Order order = new Order
                {
                    UserId       = userId,
                    CreationDate = DateTime.UtcNow,
                    Products     = productIdWithQuantity
                                   .Select(pq => new OrderProduct
                    {
                        ProductId = pq.Key,
                        Quantity  = pq.Value
                    })
                                   .ToList()
                };

                database.Orders.Add(order);
                database.SaveChanges();
            }
        }
Beispiel #18
0
        public bool Success()
        {
            using (var db = new ByTheCakeDbContext())
            {
                if (db.Users.Any(x => x.Username == username))
                {
                    return(false);
                }

                var user = new User();
                user.Username = username;

                password                = BCrypt.Net.BCrypt.HashPassword(password);
                user.Password           = password;
                user.DateOfRegistration = DateTime.UtcNow;

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

                return(true);
            }
        }
Beispiel #19
0
        public bool Add(ProductViewModel cake)
        {
            using (var db = new ByTheCakeDbContext())
            {
                if (db.Products.Any(p => p.Name == cake.Name))
                {
                    return(false);
                }

                var product = new Product()
                {
                    Name     = cake.Name,
                    Price    = cake.Price,
                    ImageUrl = cake.ImageUrl,
                };

                db.Products.Add(product);
                db.SaveChanges();

                return(true);
            }
        }
Beispiel #20
0
        public bool CreateUser(string fullName, string username, string password)
        {
            using (ByTheCakeDbContext database = new ByTheCakeDbContext())
            {
                if (database.Users.Any(u => u.Username == username))
                {
                    return(false);
                }

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

                database.Users.Add(user);
                database.SaveChanges();

                return(true);
            }
        }
Beispiel #21
0
        public bool Create(string name, string username, string password)
        {
            using (var context = new ByTheCakeDbContext())
            {
                if (context.Users.Any(u => u.Username == username))
                {
                    return(false);
                }

                var user = new User
                {
                    Name             = name,
                    Username         = username,
                    Password         = PasswordUtilities.ComputeHash(password),
                    RegistrationDate = DateTime.UtcNow
                };

                context.Add(user);
                context.SaveChanges();

                return(true);
            }
        }
Beispiel #22
0
        public bool Create(string username, string password)
        {
            using (var context = new ByTheCakeDbContext())
            {
                // Check is username already exists
                if (context.Users.Any(u => u.Username == username))
                {
                    return(false);
                }

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

                context.Add(user);
                context.SaveChanges();

                return(true);
            }
        }