public async Task <ResponseBase> PostAsync(OrderRequest orderRequest, string userId)
        {
            if (orderRequest == null)
            {
                _responseBase.AddMessage(Message.REQUEST_NAO_PODE_SER_VAZIO);
                return(_responseBase);
            }

            var order = CreateOrder(orderRequest, userId);
            var itens = CreateItens(orderRequest.Itens, order.Id);

            if (order.IsFailure || itens.Any(f => f.IsFailure))
            {
                foreach (var item in itens.Select(f => f.Errors))
                {
                    _responseBase.AddMessages(mensages: item);
                }

                _responseBase.AddMessages(order.Errors);

                return(_responseBase);
            }

            await _orderRepository.PostAsync(order);

            return(_responseBase);
        }
        public async Task <ResponseBase> AddAsync(UserRequest userRequest)
        {
            var userInfo = _mapper.Map <UserInfo>(userRequest);

            userInfo.UserId = Guid.NewGuid().ToString();

            var user = Create(userInfo, userRequest.Password);

            if (user.IsFailure)
            {
                _responseBase.AddMessages(user.Errors);
                return(_responseBase);
            }
            await _userRepository.PostAsync(user);

            return(_responseBase);
        }
示例#3
0
        public async Task <ResponseBase> PostAsync(ProductRequest productRequest)
        {
            if (productRequest == null)
            {
                _responseBase.AddMessage(Message.REQUEST_NAO_PODE_SER_VAZIO);
                return(_responseBase);
            }
            productRequest.Id = Guid.NewGuid().ToString();
            var product = CreateProduct(productRequest);

            if (product.IsFailure)
            {
                _responseBase.AddMessages(product.Errors);
                return(_responseBase);
            }

            await _productRepository.PostAsync(product);

            return(_responseBase);
        }