Esempio n. 1
0
        public void AddPizza(Logins login, IPizza pizza)
        {
            var currentOrder = CurrentOrder((User)login);

            currentOrder.Add(pizza);
            context.IncompletePizza.Add(PizzaMapper.Map(pizza, login));
            context.SaveChanges();
        }
Esempio n. 2
0
 public IPizza GetCurrentPizza(Logins login, int id)
 {
     return(PizzaMapper.Map(
                _GetCurrentPizza(login, id)
                , PizzaMapper.Map(context.Incomplete
                                  .Include(o => o.Store)
                                  .Where(o => o.Userid == login.Id).FirstOrDefault())));
 }
Esempio n. 3
0
 private Models.IncompletePizza _GetCurrentPizza(Logins login, int id)
 {
     return(context.IncompletePizza
            .Include(o => o.Crust)
            .Include(o => o.SizeNavigation)
            .Include(o => o.IncompleteToppings)
            .ThenInclude(o => o.Topping)
            .Where(o => o.Id == login.Id && o.PizzaId == id)
            .FirstOrDefault());
 }
Esempio n. 4
0
        public void CreateLogon(string username, string password)
        {
            if (Logins == null)
            {
                Logins = new Collection <UserLogin>();
            }
            if (Logins.Any(c => c.Username == username))
            {
                throw new UserAlreadyExistsException(username);
            }

            Logins.Add(UserLogin.Create(username, password.Encrypt(), this));
        }
Esempio n. 5
0
 public IOrder GetOrder(long id, Logins login)
 {
     return(PizzaMapper.Map(context.Orders
                            .Include(o => o.Store)
                            .ThenInclude(o => o.IdNavigation)
                            .Include(o => o.User)
                            .ThenInclude(o => o.IdNavigation)
                            .Include(o => o.Pizza)
                            .ThenInclude(o => o.PizzaToppings)
                            .ThenInclude(o => o.Topping)
                            .Include(o => o.Pizza)
                            .ThenInclude(o => o.Crust)
                            .Include(o => o.Pizza)
                            .ThenInclude(o => o.SizeNavigation)
                            .Where(o => o.Id == id).Where(o => (o.Storeid == login.Id) || (o.Userid == login.Id)).FirstOrDefault()));
 }
Esempio n. 6
0
        public void UpdatePizza(Logins login, int id, Pizza newPizza)
        {
            var pizza = _GetCurrentPizza(login, id);

            pizza.CrustId = newPizza.Crust.Id;
            pizza.Size    = newPizza.Size.Id;
            pizza.IncompleteToppings.Clear();
            foreach (var tid in newPizza.Toppings.Select(t => t.Id).Distinct())
            {
                pizza.IncompleteToppings.Add(new IncompleteToppings()
                {
                    Toppingid = tid, Amount = (byte)(from top in newPizza.Toppings where tid == top.Id select top).Count()
                });
            }
            context.SaveChanges();
        }
Esempio n. 7
0
 public IEnumerable <IOrder> GetOrders(Logins login)
 {
     if (login.IsStore)
     {
         return(context.Orders.Where(o => o.Storeid == login.Id)
                .Include(o => o.User)
                .ThenInclude(o => o.IdNavigation)
                .Include(o => o.Pizza)
                .Select(o => PizzaMapper.Map(o)));
     }
     else
     {
         return(context.Orders.Where(o => o.Userid == login.Id)
                .Include(o => o.Store)
                .ThenInclude(o => o.IdNavigation)
                .Include(o => o.Pizza)
                .Select(o => PizzaMapper.Map(o)));
     }
 }
Esempio n. 8
0
        internal static IncompletePizza Map(IPizza pizza, Logins login)
        {
            var retVar = new IncompletePizza()
            {
                Id      = login.Id,
                PizzaId = pizza.Id,
                CrustId = pizza.Crust.Id,
                Size    = pizza.Size.Id,
            };

            foreach (var Id in (from topping in pizza.Toppings
                                select topping.Id).Distinct())
            {
                retVar.IncompleteToppings.Add(new IncompleteToppings()
                {
                    Amount = (byte)(from t in pizza.Toppings
                                    where t.Id == Id
                                    select t).Count(),
                    Toppingid = Id,
                });
            }
            return(retVar);
        }
Esempio n. 9
0
 public Order CurrentOrderLazy(Logins login)
 {
     return(PizzaMapper.Map(context.Incomplete.Include(o => o.Store)
                            .Where(o => o.Userid == login.Id).FirstOrDefault()));
 }
Esempio n. 10
0
 public bool IsValidPassword(string username, string password)
 {
     return(Logins.Any(c => c.Username == username && c.Password == password.Encrypt()));
 }