public async Task <IActionResult> Post([FromBody] OrderModel order)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _manager.AddOrderAsync(order);

            _logger.LogInformation("Creating order records");
            return(CreatedAtAction(nameof(GetOrderById), new { id = order.OrderId }, order));
        }
Пример #2
0
        public async Task <IActionResult> CreateOrderAsync([FromBody] Order o)
        {
            var mappedorder = _mapper.Map <DAL.Entities.Order>(o);

            //o = new Order
            //{
            //    Costumer = new Costumer { Name = "Name" },
            //    StartDate = DateTime.Now.AddDays(-1),
            //    EndDate = DateTime.Now.AddDays(1),
            //    Rooms = new List<Room>
            //    {
            //       new Kitchen(){ Price = 100  },
            //       new Bedroom(){ Price = 100  },
            //       new Shower(){ Price = 100  }
            //    }

            //};

            //var mappedorder = new DAL.Entities.Order
            //{
            //    Costumer = new DAL.Entities.Costumer { Name = o.Costumer.Name },
            //    StartDate = o.StartDate,
            //    EndDate = o.EndDate
            //};

            List <DAL.Entities.Room> mappedrooms = new List <DAL.Entities.Room>();

            mappedrooms = _mapper.Map <List <DAL.Entities.Room> >(o.Rooms);

            var neworder = await _orderService.AddOrderAsync(mappedorder, mappedrooms);

            if (neworder == null)
            {
                return(NotFound("No free room in the time interval"));
            }

            var mappedneworder = _mapper.Map <Order>(neworder);

            return(CreatedAtRoute("GetOrderById", new { id = mappedneworder.Id }, mappedneworder));
        }