Ejemplo n.º 1
0
        public GetOrderDTO GetOrderById(int orderId)
        {
            Order order = null;

            _uow.TryExecuteTransaction(() =>
            {
                order = _uow.Repository <Order>().Get(orderId);
            });

            if (order == null)
            {
                return(null);
            }

            var getOrderDto = new GetOrderDTO
            {
                OrderDate       = order.OrderDate,
                TransactionCost = order.PaymentTransaction.TransactionCost,
                Articles        = order.Articles.Select(x => new GetArticleDTO
                {
                    Name  = x.Name,
                    Price = x.Price
                }).ToList()
            };

            return(getOrderDto);
        }
Ejemplo n.º 2
0
        // GET: api/Orders/5
        public HttpResponseMessage GetOrders(int orderId, string lang)
        {
            HttpResponseMessage responseMessage;
            JSend json;
            var   token  = Request.Headers.SingleOrDefault(x => x.Key == "token").Value.First();
            var   userId = db.Tokens.First(u => u.TokenString.Equals(token))?.UserId;

            var order = db.Orders.FirstOrDefault(o => o.OrderId == orderId && o.UserId == userId);

            if (order != null)
            {
                var productsOrdersList = db.ProductsOrders.Where(o => o.OrderId == order.OrderId);
                var productList        = productsOrdersList.Select(product => db.Products.FirstOrDefault(p => p.ProductId == product.ProductId && product.OrderId == order.OrderId)).ToList();

                var result = new GetOrderDTO()
                {
                    UserDetails = new UserUpdateDetails
                    {
                        FirstName     = order.FirstName,
                        LastName      = order.LastName,
                        State         = order.State,
                        StreetAddress = order.Address,
                        City          = order.City,
                        ZipCode       = order.ZipCode,
                        Phone         = order.Phone,
                        Email         = order.Email
                    },
                    PaymentMethod = order.PaymentMethod,
                    Currency      = order.Currency,
                    Subtotal      = order.Subtotal,
                    Shipping      = order.Shipping,
                    Products      = new List <OrderProductInfo>(),
                    Invoice       = order.Invoice,
                    Sent          = order.Sent
                };

                foreach (var product in productList)
                {
                    var productsOrder = productsOrdersList.FirstOrDefault(p => p.ProductId == product.ProductId);
                    result.Products.Add(new OrderProductInfo
                    {
                        Name      = ComputeName(product, lang),
                        Price     = productsOrder.ProductPrice,
                        ProductId = product.ProductId,
                        Amount    = productsOrder.Amount,
                        Image     = new ProductsImagesController().GetProductsImage(product.ProductId)
                    });
                }

                responseMessage = Request.CreateResponse(HttpStatusCode.OK, result);
            }
            else
            {
                json            = new JSendMessage("fail", "No items found");
                responseMessage = Request.CreateResponse(HttpStatusCode.NotFound, json);
            }

            return(responseMessage);
        }
Ejemplo n.º 3
0
        public async Task <GetOrderDTO> GetOrder(int orderId)
        {
            GetOrderDTO order = await this
                                .Where(o => o.Id == orderId)
                                .ProjectTo <GetOrderDTO>()
                                .FirstOrDefaultAsync();

            return(order);
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> DeleteOrder(int id)
        {
            Order order = _context.Orders.Include(b => b.OrderDetails).First(c => c.Id == id);

            _context.Orders.Remove(order);

            GetOrderDTO orderDTOs = _mapper.Map <GetOrderDTO>(order);

            await _context.SaveChangesAsync();

            return(Ok(orderDTOs));
        }
        public async Task <int> ReOrder(int orderId)
        {
            try
            {
                var ordersRepository = this._unitOfWork.GetRepository <IOrdersRepository>();

                GetOrderDTO orderDTO = await ordersRepository.GetOrder(orderId);

                List <OrderLine> orderLines = orderDTO.OrderLines
                                              .Select(p => new OrderLine
                {
                    ProductId   = p.Id,
                    Quantity    = p.Quantity,
                    ProductName = p.ProductName
                })
                                              .ToList();

                var order = new Order
                {
                    CreatedOn   = DateTime.Now,
                    OrderStatus = OrderStatus.Accepted,
                    UserId      = orderDTO.UserId,
                    OrderLines  = orderLines
                };

                await this._unitOfWork.DbContext.Orders.AddAsync(order);

                await this._unitOfWork.DbContext.SaveChangesAsync();

                CommitTransactionModel response = this._unitOfWork.CommitTransactions();

                return(order.Id);
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ExceptionMessages.ReOrderMessage, ex);
            }
        }
        public HttpResponseMessage GetOrder(HttpRequestMessage request, [FromBody] GetOrderDTO orderDTO)
        {
            OrdersApiModel           ordersWebApiModel = new OrdersApiModel();
            TransactionalInformation transaction       = new TransactionalInformation();
            OrdersBusinessService    ordersBusinessService;
            CustomersBusinessService customersBusinessService;

            ordersWebApiModel.IsAuthenicated = true;

            ordersBusinessService = new OrdersBusinessService(ordersDataService);
            List <Shipper> shippers = ordersBusinessService.GetShippers(out transaction);

            if (transaction.ReturnStatus == false)
            {
                ordersWebApiModel.ReturnMessage    = transaction.ReturnMessage;
                ordersWebApiModel.ReturnStatus     = transaction.ReturnStatus;
                ordersWebApiModel.ValidationErrors = transaction.ValidationErrors;
                var badResponse = Request.CreateResponse <OrdersApiModel>(HttpStatusCode.BadRequest, ordersWebApiModel);
                return(badResponse);
            }

            Order order = ordersBusinessService.GetOrder(orderDTO.OrderID, out transaction);

            if (transaction.ReturnStatus == false)
            {
                ordersWebApiModel.ReturnMessage    = transaction.ReturnMessage;
                ordersWebApiModel.ReturnStatus     = transaction.ReturnStatus;
                ordersWebApiModel.ValidationErrors = transaction.ValidationErrors;
                var badResponse = Request.CreateResponse <OrdersApiModel>(HttpStatusCode.BadRequest, ordersWebApiModel);
                return(badResponse);
            }

            customersBusinessService = new CustomersBusinessService(customersDataService);
            Customer customer = customersBusinessService.GetCustomer(order.CustomerID, out transaction);

            if (transaction.ReturnStatus == false)
            {
                ordersWebApiModel.ReturnMessage    = transaction.ReturnMessage;
                ordersWebApiModel.ReturnStatus     = transaction.ReturnStatus;
                ordersWebApiModel.ValidationErrors = transaction.ValidationErrors;
                var badResponse = Request.CreateResponse <OrdersApiModel>(HttpStatusCode.BadRequest, ordersWebApiModel);
                return(badResponse);
            }

            List <OrderDetails> orderDetails = ordersBusinessService.GetOrderDetails(orderDTO.OrderID, out transaction);

            if (transaction.ReturnStatus == false)
            {
                ordersWebApiModel.ReturnMessage    = transaction.ReturnMessage;
                ordersWebApiModel.ReturnStatus     = transaction.ReturnStatus;
                ordersWebApiModel.ValidationErrors = transaction.ValidationErrors;
                var badResponse = Request.CreateResponse <OrdersApiModel>(HttpStatusCode.BadRequest, ordersWebApiModel);
                return(badResponse);
            }

            ordersWebApiModel.ReturnStatus  = transaction.ReturnStatus;
            ordersWebApiModel.ReturnMessage = transaction.ReturnMessage;
            ordersWebApiModel.Customer      = customer;
            ordersWebApiModel.Order         = order;
            ordersWebApiModel.Shippers      = shippers;
            ordersWebApiModel.OrderDetails  = orderDetails;

            var response = Request.CreateResponse <OrdersApiModel>(HttpStatusCode.OK, ordersWebApiModel);

            return(response);
        }