Example #1
0
 public static BookOrder ToModel(this IBookOrder order, bool details = false)
 {
     if(order == null)
     return null;
       var ord = new BookOrder() {
     Id = order.Id, CreatedOn = order.CreatedOn, Total = order.Total, Status = order.Status,  UserId = order.User.Id, UserName = order.User.DisplayName
       };
       if(details)
     ord.Items = order.Lines.Select(l => l.ToModel()).ToList();
       return ord;
 }
Example #2
0
        public static BookOrder ToModel(this IBookOrder order, bool details = false)
        {
            if (order == null)
            {
                return(null);
            }
            var ord = new BookOrder()
            {
                Id = order.Id, CreatedOn = order.CreatedOn, Total = order.Total, Status = order.Status, UserId = order.User.Id, UserName = order.User.DisplayName
            };

            if (details)
            {
                ord.Items = order.Lines.Select(l => l.ToModel()).ToList();
            }
            return(ord);
        }
Example #3
0
 public BookOrder UpdateOrder(BookOrder order)
 {
     var session = OpenSession();
       var cart = GetOpenOrder(session, LockOptions.ForUpdate, create: true);
       foreach (var item in order.Items) {
     Context.ThrowIf(item.Quantity < 0, ClientFaultCodes.InvalidValue, "Quantity", "Quantity may not be negative.");
     Context.ThrowIf(item.Quantity > 10, ClientFaultCodes.InvalidValue, "Quantity", "Quantity may not be more than 10.");
     var orderLine = cart.Lines.FirstOrDefault(ln => ln.Book.Id == item.Book.Id);
     if (orderLine == null) {
       if (item.Quantity > 0) {
     var bk = session.GetEntity<IBook>(item.Book.Id);
     Context.ThrowIfNull(bk, ClientFaultCodes.ObjectNotFound, "Book", "Book not found.");
     cart.Add(bk, item.Quantity);
     continue;
       }
     } else //orderLine != null
       if (item.Quantity == 0)
     session.DeleteEntity(orderLine);
       else
     orderLine.Quantity = item.Quantity;
       }
       cart.ScheduleUpdateTotal();
       session.SaveChanges();
       EntityHelper.RefreshEntity(cart); //to make sure total from database is refreshed in entity
       return cart.ToModel(details: true);
 }