Esempio n. 1
0
        public async Task PostOrderTest()
        {
            OrderPatchDetailsDTO newOrder = new OrderPatchDetailsDTO()
            {
                Size         = "50x50",
                Amount       = 1,
                OrderTime    = new DateTime(),
                Deadline     = DateTime.Now.AddDays(1),
                OrderComment = "New order #1",
                Type         = Order.ProductType.FOLT,
                Pattern      = System.IO.File.ReadAllBytes("../../../TestPictures/folt.png"),
                Fonts        = "Arial",
                PatternPlace = "mellkas"
            };
            var numOfOrders = DbContent.Count();
            var Response    = await OrdersController.PostOrder(newOrder);

            var NewOrder = db.GetDbContext().Orders.Find(numOfOrders + 1);

            Assert.IsNotNull(NewOrder);
            Assert.AreEqual(NewOrder.OrderId, numOfOrders + 1);
            Assert.AreEqual(NewOrder.OrderState, Order.State.WAITING_FOR_ANSWER);
            Assert.AreEqual(NewOrder.Type, Order.ProductType.FOLT);
            Assert.AreEqual(NewOrder.Amount, 1);
            Assert.AreEqual(NewOrder.OrderComment, "New order #1");
        }
Esempio n. 2
0
        private async Task <Order> MapPatchDetailsToOrderAsync(OrderPatchDetailsDTO orderDTO, Order order)
        {
            order.Size         = orderDTO.Size;
            order.Amount       = orderDTO.Amount;
            order.Deadline     = orderDTO.Deadline <= DateTime.Now ? DateTime.Now : orderDTO.Deadline;
            order.Pattern      = orderDTO.Pattern;
            order.OrderComment = orderDTO.OrderComment;
            order.OrderTime    = orderDTO.OrderTime <= DateTime.Now ? DateTime.Now : orderDTO.OrderTime;
            order.Fonts        = orderDTO.Fonts;
            order.Type         = orderDTO.Type;
            order.PatternPlace = orderDTO.PatternPlace;
            order.User         = await _userManager.GetUserAsync(HttpContext.User);

            return(order);
        }
Esempio n. 3
0
        private Boolean IsValidPOST(OrderPatchDetailsDTO orderDTO)
        {
            if ((orderDTO.Amount < 0 || orderDTO.Amount > 5000) ||
                orderDTO.Deadline < DateTime.Now || orderDTO.Deadline == null ||
                orderDTO.Fonts == null ||
                orderDTO.Pattern == null || orderDTO.Pattern.Length == 0 ||
                orderDTO.PatternPlace == null || orderDTO.PatternPlace == "" ||
                orderDTO.Size == null || orderDTO.Size == "" ||
                (orderDTO.Type != Order.ProductType.FOLT && orderDTO.Type != Order.ProductType.MINTA &&
                 orderDTO.Type != Order.ProductType.PULCSI))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 4
0
        public async Task <ActionResult <Order> > PostOrder(OrderPatchDetailsDTO orderDTO)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (user == null)
            {
                return(Unauthorized("Error accessing orders because of incorrect authority level!"));
            }

            Order order = new Order();

            orderDTO.OrderTime = DateTime.Now;
            if (!IsValidPOST(orderDTO))
            {
                return(BadRequest("Error processing new order due to unprocessable input!"));
            }
            order = await MapPatchDetailsToOrderAsync(orderDTO, order);

            _context.Orders.Add(order);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetOrder), new { id = order.OrderId }, ConvertToOrderDetailsDTO(order)));
        }