Exemplo n.º 1
0
        // Wysyła zamówienie do antykwariatu.
        public ContentResult <int> SendOrder(string username, SendOrderDto dto, bool onlinePayment)
        {
            var orderStatusId = onlinePayment ? 2 : 4;
            var orderStatus   = context.OrderStatuses.Single(x => x.Id == orderStatusId);
            var orderUser     = context.Users.Single(x => x.Name == username);
            var orderBooks    = context.Books.Where(x => dto.BooksIds.Contains(x.Id));

            var newOrder = new Order
            {
                UserEmail     = orderUser.Email,
                UserId        = orderUser.Id,
                OrderStatusId = orderStatus.Id,
                Date          = System.DateTime.Now
            };

            context.Orders.Add(newOrder);
            foreach (var book in orderBooks)
            {
                book.OrderId      = newOrder.Id;
                book.HadEverOrder = true;
            }

            context.SaveChanges();

            return(new ContentResult <int>
            {
                Content = newOrder.Id
            });
        }
Exemplo n.º 2
0
        public IActionResult OrderForOnlineCollection([FromBody] SendOrderDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var username = User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier).Value;

            var orderId = orderService.SendOrder(username, dto, true).Content;

            return(Ok(new { OrderId = orderId }));
        }