Exemplo n.º 1
0
        public domain.User ReadUser(string email)
        {
            //var rUser = _db.User.Where(u => u.Email == email).Include(u => u.Order).FirstOrDefault<User>();
            User rUser = new User();

            try
            {
                rUser = _db.User.First(u => u.Email == email);
            }
            catch (Exception e)
            {
                Exception o = e;
                System.Console.WriteLine($"Welcome {email}!");
                System.Console.WriteLine();
                return(CreateUser(email));
            }

            rUser = _db.User.First(u => u.Email == email);

            domain.User eUser = new domain.User();
            eUser.Id          = rUser.UserId;
            eUser.Email       = rUser.Email;
            eUser.LastOrdered = rUser.LastOrdered;
            eUser.Orders      = ReadOrders(rUser.UserId, "User");

            System.Console.WriteLine($"Welcome back {email}!");
            System.Console.WriteLine();
            return(eUser);
        }
Exemplo n.º 2
0
        // public void UpdatePizza(domain.Pizza pizza, int orderId)
        // {
        //   var newPizza = new Pizza();

        //   newPizza.Name = pizza.Name;

        //   newPizza.Crust = new Crust()
        //   {
        //     Type = pizza.Crust.Type,
        //     Price = (decimal)pizza.Crust.Price
        //   };

        //   newPizza.Size = new Size()
        //   {
        //     Name = pizza.Size.Name,
        //     Price = (decimal)pizza.Size.Price
        //   };

        //   newPizza.OrderId = orderId;

        //   _db.Pizza.Add(newPizza);

        //   foreach (domain.Topping t in pizza.Toppings)
        //   {
        //     var pizzaTopping = new PizzaTopping();
        //     pizzaTopping.Pizza = newPizza;
        //     Topping newTop = new Topping()
        //     {
        //       Name = t.Name,
        //       Price = (decimal)t.Price
        //     };
        //     pizzaTopping.Topping = newTop;
        //     _db.PizzaTopping.Add(pizzaTopping);
        //   }

        //   _db.SaveChanges();
        // }
        public void UpdateUser(domain.User user, int storeId, string store, DateTime date)
        {
            var entUser = new User();

            entUser.UserId       = user.Id;
            entUser.Email        = user.Email;
            entUser.CurrentStore = store;
            entUser.LastOrdered  = date;
            List <Order> eOrders = new List <Order>();

            foreach (domain.Order order in user.Orders)
            {
                var eOrder = new Order();
                eOrder.OrderId     = order.OrderId;
                eOrder.UserId      = user.Id;
                eOrder.StoreId     = storeId;
                eOrder.Status      = order.Status;
                eOrder.DateCreated = order.Date;
                eOrders.Add(eOrder);

                // foreach (domain.Pizza p in order.Pizzas)
                // {
                //   UpdatePizza(p, eOrder.OrderId);
                // }
            }

            entUser.Order = eOrders;

            _db.User.Update(entUser);
            _db.SaveChanges();
        }
Exemplo n.º 3
0
        public domain.User CreateUser(string email)
        {
            var entUser = new User();

            domain.User newUser = new domain.User();
            entUser.Email = email;
            newUser.Email = email;

            _db.Add(entUser);
            _db.SaveChanges();
            newUser.Id = entUser.UserId;

            return(newUser);
        }
Exemplo n.º 4
0
        public IActionResult SaveUser(PizzaBox.Domain.Models.User model)
        {
            // retreive last saved user from users table
            var user = _ctx.Users.Select(u => u).OrderByDescending(o => o.EntityId).FirstOrDefault();

            // assignment of PK value
            if (user != null)
            {
                model.EntityId = user.EntityId + 1;
            }
            else
            {
                model.EntityId = 1;
            }
            model.SelectedStore = 1;

            sqlClient.SaveUser(model);
            return(RedirectToAction("Index", "Store"));
        }
        public void CreateUser(domain.User user)
        {
            var dbUser       = new User();
            var userlist     = ReadAllUsers();
            var userNameList = new List <string>();

            foreach (var u in userlist)
            {
                userNameList.Add(u.name);
                System.Console.WriteLine(u.name);
            }
            if (userNameList.Contains(user.name))
            {
            }
            else
            {
                dbUser.Name = user.name;
                _db.User.Add(dbUser);
            }
            _db.SaveChanges();
        }