Exemplo n.º 1
0
        public ActionResult <ApiResponse <CustomerProductResponse> > Get([FromQuery] string identificationNumber)
        {
            //Check identificationNumber Field
            if (string.IsNullOrEmpty(identificationNumber))
            {
                return(BadRequest(new ApiResponse {
                    Code = (int)ApiResponseCodes.ValidationError, ErrorMessage = "IdentificationNumber Required"
                }));
            }

            //Check IdentificationNo IsExist
            bool isExistCustomer = _customerRepository.FindFirstBy(p => p.IdentificationNumber.Equals(identificationNumber)).ResponseCode == (int)EntityResponseCodes.NoRecordFound;

            if (isExistCustomer)
            {
                return(BadRequest(new ApiResponse {
                    Code = (int)ApiResponseCodes.ValidationError, ErrorMessage = " Identification Number Is Not Exist!"
                }));
            }

            var serviceEntityProductResponse = _customerProductRepository.GetSelectedProductsByIdentificationNumber(identificationNumber);

            if (serviceEntityProductResponse.ResponseCode == (int)Enums.EntityResponseCodes.Successfull)
            {
                return(Ok(new ApiResponse <IEnumerable <CustomerProductResponse> >((int)ApiResponseCodes.Ok, serviceEntityProductResponse.EntityDataList.Select(x => new CustomerProductResponse
                {
                    ProductId = x.Product.ProductId,
                    ProductName = x.Product.ProductName,
                    Description = x.Product.Description,
                    Price = x.Product.Price
                }))));
            }

            throw new ApiException((int)ApiResponseCodes.DbError, serviceEntityProductResponse.ResponseMessage);
        }