Пример #1
0
        public async Task <IActionResult> AddOrder(OrderForAddDto orderForAddDto)
        {
            orderForAddDto.CreatedAt = DateTime.Now;
            var OrderToCreate = _mapper.Map <Order>(orderForAddDto);

            _repo.Add(OrderToCreate);
            await _repo.SaveAll();

            return(Ok());
        }
Пример #2
0
        public async Task <IActionResult> AddOrder([FromBody] OrderForAddDto OrderDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            List <OrderFileName> filesToAdd = new List <OrderFileName>();

            if (OrderDto.Files != null)
            {
                for (int i = 0; i < OrderDto.Files.Length; i++)
                {
                    filesToAdd.Add(new OrderFileName
                    {
                        FileData = new FileData
                        {
                            Id = OrderDto.Files[i]
                        },
                        FileName = OrderDto.FileNames[i]
                    });
                }
            }


            Order orderToCreate = new Order(
                OrderDto.Company,
                OrderDto.OrderDate,
                OrderDto.DeliveryDate,
                OrderDto.OrderedBy,
                OrderDto.PurchaseNumber,
                OrderDto.Width,
                OrderDto.Height,
                OrderDto.Length,
                new UnitType()
            {
                Name = OrderDto.UnitType
            },
                OrderDto.Products,
                filesToAdd,
                OrderDto.Status
                );

            bool result = await _repo.AddOrder(orderToCreate);

            if (result)
            {
                User currentUser = _userManager.FindByNameAsync(User.Identity.Name).Result;
                result = await _eventLogRepo.AddEventLog(EventType.Created, "bestilling", "Købsnummer: " + orderToCreate.PurchaseNumber.ToString(), orderToCreate.Id, currentUser);
            }
            return(result ? StatusCode(201) : BadRequest());
        }
Пример #3
0
        public async Task <IActionResult> NewOrderClient(OrderForAddDto order)
        {
            var orderForAdd = mapper.Map <Orders>(order);

            orderForAdd.OrderStatus = CustomEnums.OrderStatus.Created;

            orderRepo.Add(orderForAdd);

            if (await orderRepo.SaveAll())
            {
                await bus.Publish(new OrderCreatedEvent());

                return(CreatedAtAction("GetOrder", new { orderId = orderForAdd.OrderId }, order));
            }
            return(BadRequest("Could not add order"));
        }