public DE.Order SaveOrder(DE.Order order) { if (order == null) { throw new ArgumentNullException("order"); } try { var salesOrderHeader = new SalesOrderHeader(); Mapper.Map(order, salesOrderHeader); using (var context = new SalesOrderContext()) { using (var transactionScope = this.GetTransactionScope()) { context.SalesOrderHeaders.Add(salesOrderHeader); context.SaveChanges(); transactionScope.Complete(); } } return(order); } catch (Exception e) { throw new RepositoryException( string.Format(CultureInfo.CurrentCulture, Strings.ErrorSavingOrderWithTrackingId, order.TrackingId), e); } }
public DE.Order GetPendingOrderByTrackingId(Guid trackingId) { if (Guid.Empty.Equals(trackingId)) { throw new ArgumentNullException("trackingId"); } try { IMongoQuery query = null; var collection = GetDatabase().GetCollection <OrderHistory>(MongoCollection); query = Query.And( Query <OrderHistory> .EQ(e => e.OrderCode, trackingId), Query <OrderHistory> .EQ(e => e.Status, DE.OrderStatus.Pending)); var mongoHistory = collection.Find(query).FirstOrDefault(); if (mongoHistory == null) { return(null); } var orderHistory = new DE.OrderHistory(); var domainOrderItems = new List <DE.OrderItem>(); Mapper.Map(mongoHistory, orderHistory); if (mongoHistory.Items != null) { Mapper.Map(mongoHistory.Items, domainOrderItems); domainOrderItems.ForEach(i => orderHistory.AddOrderItem(i)); } if (orderHistory != null) { var newOrder = new DE.Order() { BillToAddress = orderHistory.BillToAddress, CreditCard = orderHistory.CreditCard, CustomerId = orderHistory.CustomerId, DueDate = orderHistory.DueDate, Freight = orderHistory.Freight, OrderDate = orderHistory.OrderDate, ShippingAddress = orderHistory.ShippingAddress, Status = orderHistory.Status, TrackingId = orderHistory.TrackingId, }; foreach (var shoppingCartItem in orderHistory.OrderItems) { newOrder.AddOrderItem(new DE.OrderItem() { Product = shoppingCartItem.Product, Quantity = (short)shoppingCartItem.Quantity, UnitPrice = shoppingCartItem.UnitPrice }); } return(newOrder); } return(null); } catch (Exception e) { throw new RepositoryException(string.Format(CultureInfo.CurrentCulture, Strings.ErrorRetrievingOrderByTrackingId, trackingId), e); } }