private void UpdateBuyer(OrderEdit order, OrderEntity orderEntity) { // Get Buyer Information of this order BuyerEntity buyerEntity = _dbContext.Buyers.SingleOrDefault(buyer => buyer.Id == orderEntity.BuyerId); // Update Buyer Information buyerEntity.FirstName = order.Buyer.FirstName; buyerEntity.LastName = order.Buyer.LastName; buyerEntity.Email = order.Buyer.Email; buyerEntity.Phone = order.Buyer.Phone; // Get Shipping Information of this order ShippingAddressEntity shippingAddressEntity = _dbContext.ShippingAddresses .SingleOrDefault (shippingAddress => shippingAddress.Id == orderEntity.ShippingAddressId); // Update Shipping Address shippingAddressEntity.AddressLine1 = order.ShippingAddress.AddressLine1; shippingAddressEntity.AddressLine2 = order.ShippingAddress.AddressLine2; shippingAddressEntity.City = order.ShippingAddress.City; shippingAddressEntity.State = order.ShippingAddress.State; shippingAddressEntity.Zip = order.ShippingAddress.Zip; _dbContext.SaveChanges(); }
private (int buyerId, int shippingAddressId) CreateBuyer(Order order) { // Add Buyer Information var buyer = new BuyerEntity { FirstName = order.Buyer.FirstName, LastName = order.Buyer.LastName, Email = order.Buyer.Email, Phone = order.Buyer.Phone, }; _dbContext.Buyers.Add(buyer); // Add Shipping Address var shippingAddress = new ShippingAddressEntity { AddressLine1 = order.ShippingAddress.AddressLine1, AddressLine2 = order.ShippingAddress.AddressLine2, City = order.ShippingAddress.City, State = order.ShippingAddress.State, Zip = order.ShippingAddress.Zip }; _dbContext.ShippingAddresses.Add(shippingAddress); _dbContext.SaveChanges(); return(buyer.Id, shippingAddress.Id); }