Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public async Task <Response> CreateBuyer(NewUserRequest request)
        {
            BuyerEntity newBuyer = _mapper.Map <BuyerEntity>(request);

            try
            {
                _context.Buyers.Add(newBuyer);
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = ex.Message
                });
            }
            return(new Response()
            {
                IsOperationSucceeded = true, SuccessOrFailureMessage = this.getSuccessMessage()
            });
        }