public Models.Order AddOrder(Models.Order order, Models.AppUser user, Models.Location location)
        {
            _context.Orders.Add(
                new Entities.Order {
                Total      = order.Total,
                LocationId = GetLocationID(location),
                UserId     = GetUserID(user),
            }
                );
            _context.SaveChanges();
            //get the order that was just created
            List <Entities.Order> orders = new List <Entities.Order>();

            foreach (Entities.Order o in _context.Orders)
            {
                orders.Add(o);
            }
            IEnumerable <Entities.Order> SortedOrders = from o in orders
                                                        group o by o.Id into sorto
                                                        select sorto.OrderByDescending(os => os.Id).First();

            int recentOrderId = SortedOrders.Max(x => x.Id);

            Entities.Order recentOrder = GetOrderById(recentOrderId);

            foreach (Models.Products prod in order.ProductList)
            {
                int prodId = GetProductID(prod);
                AddLineItem(prod, recentOrderId);
            }
            _context.SaveChanges();
            return(order);
        }
 public Models.AppUser AddUser(Models.AppUser user)
 {
     _context.Users.Add(
         new Entities.User {
         UserName    = user.UserName,
         Phone       = user.Phone,
         UserAddress = user.Address,
         UserType    = user.userType
     }
         );
     _context.SaveChanges();
     return(user);
 }
        public int GetUserID(Models.AppUser user)
        {
            List <Entities.User> users = new List <Entities.User>();

            foreach (Entities.User r in _context.Users)
            {
                users.Add(r);
            }
            int useId = (from Use in users
                         where Use.Phone == user.Phone
                         select Use.Id).FirstOrDefault();

            return(useId);
        }
示例#4
0
 public Models.Order CreateOrder(List <Models.Products> items, Models.AppUser cust, Models.Location loc)
 {
     Models.Order newOrder = new Models.Order(items, cust, loc);
     return(_repo.AddOrder(newOrder, newOrder.Customer, newOrder.Location));
 }
 public Models.AppUser CreateUser(string nameInput, string phoneInput, string addressInput)
 {
     Models.AppUser user1 = new Models.AppUser(nameInput, addressInput, phoneInput);
     user1.userType = "Customer";
     return(_repo.AddUser(user1));
 }