Beispiel #1
0
        public async Task <IActionResult> CreateOrder([FromBody] SaveOrderResource model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var engineer = await _engineerRepository.GetAsync(model.EngineerId, UserId);

            if (engineer == null)
            {
                throw new ArgumentNullException();
            }

            var newOrder = new Order(model.OrderDate, model.EngineerId, UserId, OrderItems(model));

            _orderRepository.Add(newOrder);
            await _unitOfWork.CompleteAsync();

            return(StatusCode(201));
        }
        public async Task <SaveEngineerResource> GetById(int id)
        {
            var engineer = await _engineerRepository.GetAsync(id, UserId);

            return(_mapper.Map <Engineer, SaveEngineerResource>(engineer));
        }