Example #1
0
        public Customer Register(string email, string name, string address, DateTime birthDate)
        {
            if (birthDate.AddYears(18) <= DateTime.Now)
            {
                try
                {
                    var context = new OrderManagementDbContext();
                    context.Add(new Customer(email, name, address, birthDate));
                    context.SaveChanges();

                    var customer = context.Set <Customer>()
                                   .Last();
                    return(customer);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(new Customer());
                }
            }
            else
            {
                return(new Customer());
            }
        }
Example #2
0
        public bool AddBasket(string email, Basket basket)
        {
            try
            {
                var context = new OrderManagementDbContext();

                var result = context.Set <Customer>()

                             .SingleOrDefault(b => b.Email == email);
                if (result != null)
                {
                    basket.Customer = result;
                    context.Add(basket);

                    context.SaveChanges();
                }
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }