Exemple #1
0
        public async Task <IResult> ListAttributes(DataHelperModel dataHelper, bool getAll)
        {
            var result = new Result
            {
                Operation = Operation.Read,
                Status    = Status.Success
            };

            try
            {
                var listAttr = _productAttributeRepository.ListAttributes(dataHelper.Search, getAll);
                if (!getAll)
                {
                    var list        = DataSortExtention.SortBy(listAttr, dataHelper.SortColumn, dataHelper.SortOrder);
                    var resultCount = list.Count();
                    var pagedList   = DataCount.Page(list, dataHelper.PageNumber, dataHelper.PageSize);
                    var resultList  = await pagedList.ToListAsync();

                    var pdtAttrViewModels = new List <ProductAttributeViewModel>();
                    pdtAttrViewModels = resultList.Select(p =>
                    {
                        var pdtAttrViewModel = new ProductAttributeViewModel();
                        pdtAttrViewModel.MapFromModel(p);
                        return(pdtAttrViewModel);
                    }).ToList();
                    ResultModel resultModel = new ResultModel();
                    resultModel.ProductAttributeResult = pdtAttrViewModels;
                    resultModel.TotalCount             = resultCount;
                    if (resultList.Count == 0)
                    {
                        result.Status     = Status.Fail;
                        result.StatusCode = HttpStatusCode.BadRequest;
                        result.Message    = "No records present.";
                        return(result);
                    }
                    result.Body = resultModel;
                }
                else
                {
                    var attributeList = await listAttr.ToListAsync();

                    result.Body = attributeList;
                }
                result.Status     = Status.Success;
                result.StatusCode = HttpStatusCode.OK;
                return(result);
            }
            catch (Exception e)
            {
                result.Status     = Status.Error;
                result.Message    = e.Message;
                result.StatusCode = HttpStatusCode.InternalServerError;

                return(result);
            }
        }
        public async Task <IResult> ListProductAttributeValue(int id, DataHelperModel dataHelper)
        {
            var result = new Result
            {
                Operation = Operation.Read,
                Status    = Status.Success
            };

            try
            {
                var attributeValues = _productRepository.GetProductAttributeValuesList(id);
                if (attributeValues.Count() == 0)
                {
                    result.Status     = Status.Fail;
                    result.StatusCode = HttpStatusCode.BadRequest;
                    result.Message    = "Attributes do not exist for the product.";
                    return(result);
                }
                var list = attributeValues;
                list = DataSortExtention.SortBy(list, dataHelper.SortColumn, dataHelper.SortOrder);
                var resultCount = list.Count();
                var pagedList   = DataCount.Page(list, dataHelper.PageNumber, dataHelper.PageSize);
                var resultList  = await pagedList.ToListAsync();

                var pdtAttrValue = new List <ProductAttributeValueViewModel>();
                pdtAttrValue = resultList.Select(p =>
                {
                    var pdtAttrValueView = new ProductAttributeValueViewModel();
                    pdtAttrValueView.MapFromModel(p);
                    return(pdtAttrValueView);
                }).ToList();
                ResultModel resultModel = new ResultModel();
                resultModel.ProductAttributeValueResult = pdtAttrValue;
                resultModel.TotalCount = resultCount;
                if (resultList.Count == 0)
                {
                    result.Status     = Status.Fail;
                    result.StatusCode = HttpStatusCode.BadRequest;
                    result.Message    = "No records present.";
                    return(result);
                }

                result.Status     = Status.Success;
                result.StatusCode = HttpStatusCode.OK;
                result.Body       = resultModel;
                return(result);
            }
            catch (Exception e)
            {
                result.Status     = Status.Error;
                result.Message    = e.Message;
                result.StatusCode = HttpStatusCode.InternalServerError;

                return(result);
            }
        }
        public IResult GetProductByCategoryForCustomer(int id, DataHelperModel dataHelper)
        {
            var result = new Result
            {
                Operation = Operation.Read,
                Status    = Status.Success
            };

            try
            {
                var productList = _productRepository.GetProductByCategoryForCustomer(id, dataHelper.Search);
                var list        = productList;
                if (list.Count() == 0)
                {
                    result.Status     = Status.Fail;
                    result.StatusCode = HttpStatusCode.BadRequest;
                    result.Message    = "No records present.";
                    return(result);
                }

                list = DataSortExtention.SortBy(list, dataHelper.SortColumn, dataHelper.SortOrder);
                var resultCount = list.Count();
                var pagedList   = DataCount.Page(list, dataHelper.PageNumber, dataHelper.PageSize);
                var resultList  = pagedList.ToList();
                var pdtViewList = new List <ProductViewModel>();
                pdtViewList = resultList.Select(p =>
                {
                    var pdtview = new ProductViewModel();
                    pdtview.MapFromModel(p);
                    return(pdtview);
                }).ToList();
                var resultModel = new ResultModel()
                {
                    ProductResult = pdtViewList,
                    TotalCount    = resultCount,
                };

                result.Status     = Status.Success;
                result.StatusCode = HttpStatusCode.OK;
                result.Body       = resultModel;
                return(result);
            }
            catch (Exception e)
            {
                result.Status     = Status.Error;
                result.Message    = e.Message;
                result.StatusCode = HttpStatusCode.InternalServerError;

                return(result);
            }
        }
Exemple #4
0
        public IResult GetUserList(DataHelperModel dataHelper)
        {
            var result = new Result()
            {
                Operation = Operation.Read,
                Status    = Status.Success
            };

            try
            {
                int userId   = _specificClaim.GetSpecificClaim("Id");
                var userList = _userRepository.GetUserList(userId, dataHelper.Search);
                if (userList.Count() == 0)
                {
                    result.Status     = Status.Fail;
                    result.StatusCode = HttpStatusCode.BadRequest;
                    result.Message    = "noUserPresent";
                    return(result);
                }
                var list = userList;
                list = DataSortExtention.SortBy(list, dataHelper.SortColumn, dataHelper.SortOrder);
                var resultCount    = list.Count();
                var pagedList      = DataCount.Page(list, dataHelper.PageNumber, dataHelper.PageSize);
                var resultList     = pagedList.ToList();
                var userViewModels = new List <UserViewModel>();
                userViewModels = resultList.Select(r =>
                {
                    var userViewModel = new UserViewModel();
                    userViewModel.MapFromModel(r);
                    userViewModel.Roles = r.Roles.Select(x => x.RoleId).ToArray();
                    return(userViewModel);
                }).ToList();

                ResultModel resultModel = new ResultModel();
                resultModel.UserResult = userViewModels;
                resultModel.TotalCount = resultCount;

                result.Status     = Status.Success;
                result.StatusCode = HttpStatusCode.OK;
                result.Body       = resultModel;
                return(result);
            }
            catch (Exception e)
            {
                result.Status     = Status.Error;
                result.Message    = e.Message;
                result.StatusCode = HttpStatusCode.InternalServerError;
                return(result);
            }
        }
        public async Task <IResult> GetProductReviewList(int id, DataHelperModel dataHelper)
        {
            var result = new Result()
            {
                Operation = Operation.Read,
                Status    = Status.Success
            };

            try
            {
                var rating = _productRepository.GetReviewList(id);
                if (rating.Count() == 0)
                {
                    result.Status     = Status.Fail;
                    result.StatusCode = HttpStatusCode.BadRequest;
                    result.Message    = "Ratings do not exist for the product.";
                    return(result);
                }
                var list = rating;
                list = DataSortExtention.SortBy(list, dataHelper.SortColumn, dataHelper.SortOrder);
                var resultCount = list.Count();
                var pagedList   = DataCount.Page(list, dataHelper.PageNumber, dataHelper.PageSize);
                var resultList  = await pagedList.ToListAsync();

                var ratingViewModel = new List <ProductRatingReviewViewModel>();
                ratingViewModel = resultList.Select(r =>
                {
                    var ratingViewObj = new ProductRatingReviewViewModel();
                    ratingViewObj.MapFromModel(r);
                    return(ratingViewObj);
                }).ToList();
                ResultModel resultModel = new ResultModel();
                resultModel.ProductRatingReviewResult = ratingViewModel;
                resultModel.TotalCount = resultCount;

                result.Status     = Status.Success;
                result.StatusCode = HttpStatusCode.OK;
                result.Body       = resultModel;
                return(result);
            }
            catch (Exception e)
            {
                result.Status     = Status.Success;
                result.StatusCode = HttpStatusCode.InternalServerError;
                result.Body       = e;
                result.Message    = e.Message;
                return(result);
            }
        }
        public async Task <IResult> GetCategoryList(DataHelperModel dataHelper, bool getParent, bool getAll)
        {
            var result = new Result
            {
                Operation = Operation.Read,
                Status    = Status.Success
            };

            try
            {
                var categoryList = _categoryRepository.GetCategoryList(dataHelper.Search);
                if (getAll != true)
                {
                    var list = categoryList;
                    list = DataSortExtention.SortBy(list, dataHelper.SortColumn, dataHelper.SortOrder);
                    var resultCount = list.Count();
                    var pagedList   = DataCount.Page(list, dataHelper.PageNumber, dataHelper.PageSize);
                    var resultList  = await pagedList.ToListAsync();

                    var categoryViewList = new List <CategoryViewModel>();
                    categoryViewList = resultList.Select(c =>
                    {
                        var categoryView = new CategoryViewModel();
                        categoryView.MapFromModel(c);
                        return(categoryView);
                    }).ToList();
                    ResultModel resultModel = new ResultModel();
                    resultModel.CategoryResult = categoryViewList;
                    resultModel.TotalCount     = resultCount;
                    if (resultList.Count == 0)
                    {
                        result.Status     = Status.Fail;
                        result.StatusCode = HttpStatusCode.BadRequest;
                        result.Message    = "No records present.";
                        return(result);
                    }
                    result.Status     = Status.Success;
                    result.StatusCode = HttpStatusCode.OK;
                    result.Body       = resultModel;
                    return(result);
                }
                else
                {
                    if (getParent)
                    {
                        categoryList = categoryList.Where(x => x.ChildCategory == null).OrderBy(x => x.CategoryName);
                        var categories = await categoryList.ToListAsync();

                        result.Body       = categoryList;
                        result.Status     = Status.Success;
                        result.StatusCode = HttpStatusCode.OK;
                        return(result);
                    }
                    else
                    {
                        categoryList = categoryList.Where(c => c.ParentCategory != true).OrderBy(x => x.CategoryName);
                        var categories = await categoryList.ToListAsync();

                        result.StatusCode = HttpStatusCode.OK;
                        result.Body       = categoryList;
                        result.Status     = Status.Success;
                        return(result);
                    }
                }
            }
            catch (Exception e)
            {
                result.Status     = Status.Error;
                result.Message    = e.Message;
                result.StatusCode = HttpStatusCode.InternalServerError;
                return(result);
            }
        }