예제 #1
0
        public HttpResponseMessage GetProductBrands(ProductBrandRequest <string> request)
        {
            HttpResponseMessage responseMessage = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK
            };
            BaseResponse <List <ProductBrandAPIViewModel> > response = new BaseResponse <List <ProductBrandAPIViewModel> >();

            try
            {
                // Domain
                var domain = new ProductBrandDomain();
                response = domain.GetProductBrand(request);
            }
            catch (ApiException e)
            {
                // catch ApiException
                responseMessage.StatusCode = e.StatusCode;
                response = BaseResponse <List <ProductBrandAPIViewModel> > .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus);
            }
            catch (Exception ex)
            {
                responseMessage.StatusCode = HttpStatusCode.InternalServerError;
                response = BaseResponse <List <ProductBrandAPIViewModel> > .Get(false, ex.ToString(), null, ResultEnum.InternalError);
            }

            //return
            responseMessage.Content = new JsonContent(response);
            return(responseMessage);

            throw new NotImplementedException();
        }
예제 #2
0
        public List <ProductBrandAPIViewModel> GetProductBrand(ProductBrandRequest <string> request)
        {
            var repo  = DependencyUtils.Resolve <IProductBrandRepository>();
            int index = (int)request.Page;
            int range = (index - 1) * (int)request.Limit;


            //var pro = repo.Get().AsEnumerable()
            //    .Where(p => (request.Name == null ||p.Name.ToUpper().Contains(request.Name.ToUpper()))).
            //    Select(p => new ProductBrandAPIViewModel(p)).ToList();
            var pro = repo.Get()
                      .Where(p => (request.Name == null || p.Name.ToUpper().Contains(request.Name.ToUpper())));

            if (request.Ids != null)
            {
                var listId = request.Ids.Split(',');
                // filter Id
                pro = from p in pro
                      where listId.Contains(p.ProductBrandId.ToString())
                      select p;
            }
            // OrderBy by Id of ProductBrand , page and limit
            pro = pro.OrderBy(p => p.ProductBrandId).Skip(range).Take(request.Limit.Value);
            var productBrandVM = pro.ToList().Select(p => new ProductBrandAPIViewModel(p)).ToList();

            return(productBrandVM);
        }
예제 #3
0
        public BaseResponse <List <ProductBrandAPIViewModel> > GetProductBrand(ProductBrandRequest <string> request)
        {
            var service = this.Service <IProductBrandService>();
            var list    = service.GetProductBrand(request);

            if (list == null)
            {
                throw ApiException.Get(false, ConstantManager.MES_PRODUCTBRAND_NOTFOUND, ResultEnum.ProductBrandNotFound, HttpStatusCode.BadRequest);
            }
            return(BaseResponse <List <ProductBrandAPIViewModel> > .Get(true, ConstantManager.MES_PRODUCTBRAND_OK, list, ResultEnum.Success));
        }