Example #1
0
 public void AddOrder(Order order, UserOrderContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context),
                                         "You must provide a context");
     }
     if (this.Orders == null)
     {
         this.Orders = new List <Order>();
     }
     this.Orders.Add(order);
     context.SaveChanges();
 }
Example #2
0
        public void UpdateOrder(string trackingId, string name, string street, string city, string state, string zipCode, UserOrderContext context)
        {
            var user = context.Users.Include(u => u.Orders).Single(u => u.UserId == this.UserId);

            if (user != null)
            {
                var order = user.Orders.Where(x => x.OrderId == this.OrderId).FirstOrDefault();
                if (order != null)
                {
                    order.TrackingId = trackingId;
                    order.Name       = name;
                    order.Street     = street;
                    order.City       = city;
                    order.State      = state;
                    order.ZipCode    = zipCode;
                }


                context.Users.Update(user);
                context.SaveChanges();
            }
        }