Пример #1
0
        private string GetStringCategoryFromEnum(CategoriesInformation.CategoriesEnum category)
        {
            var converted = CategoriesInformation.Categories.
                            ToArray()[(int)category];

            return(converted);
        }
Пример #2
0
        public CategoryArticleViewModel GetCategoryArticleModel(CategoriesInformation.CategoriesEnum category)
        {
            var converted      = GetStringCategoryFromEnum(category);
            var model          = new CategoryArticleViewModel();
            var additionalInfo = CategoriesInformation.GetAdditionalInformation(converted);

            model.PreviewModels        = PreviewArticleModels(converted);
            model.SortBar              = new SortBindingModel();
            model.SortBar.SortByValues = new string[] { "Most recent", "Price (ascending)", "Price (descending)" };
            var passArr = new string[] { "Any" };

            if (additionalInfo != null)
            {
                Array.Resize(ref passArr, additionalInfo.Length + 1);
                Array.Copy(additionalInfo, 0, passArr, 1, additionalInfo.Length);
            }
            model.SortBar.TypeDropDownValues = passArr;
            return(model);
        }
Пример #3
0
        public CategoryArticleViewModel GetSorted_CAM(CategoriesInformation.CategoriesEnum category, SortBindingModel model)
        {
            var converted   = GetStringCategoryFromEnum(category);
            var returnModel = new CategoryArticleViewModel();

            IEnumerable <ArticleDataModel> queryModel = context.Articles
                                                        .Where(a => a.Category == converted);

            System.Diagnostics.Debug.WriteLine(string.Format("Search => {0} / Order => {1} / PriceF => {2} / PriceT => {3} / Category => {4} / querymodelISNULL = {5} / Type = {6}",
                                                             model.Search != null ? model.Search : "NULL", model.SortBy, model.PriceLimitationFrom, model.PriceLimitationTo, converted, queryModel != null ? "No" : "Yes", model.Type));

            #region querryModel != null
            if (queryModel != null)
            {
                if (model.Type != null && model.Type != "Any")
                {
                    IEnumerable <ArticleDataModel> temp;
                    temp = queryModel
                           .Where(a => a.Type == model.Type);
                    if (temp != null)
                    {
                        queryModel = temp;
                    }
                }
                if (model.Search != null && model.Search != string.Empty)
                {
                    IEnumerable <ArticleDataModel> temp;
                    temp = queryModel
                           .Where(a => a.Name.Contains(model.Search));
                    if (temp != null && temp.Count() > 0)
                    {
                        queryModel = temp;
                    }
                }

                switch (model.SortBy)
                {
                case "Most recent":
                {
                    queryModel = queryModel
                                 .OrderByDescending(a => a.UploadDate);
                }
                break;

                case "Price (ascending)":
                {
                    queryModel = queryModel
                                 .OrderBy(a => a.Price);
                }
                break;

                case "Price (descending)":
                {
                    queryModel = queryModel
                                 .OrderByDescending(a => a.Price);
                }
                break;
                }

                if (model.PriceLimitationTo != 0)
                {
                    queryModel = queryModel
                                 .Where(a => (a.Price >= model.PriceLimitationFrom && a.Price <= model.PriceLimitationTo));
                }
            }
            #endregion

            var mapped = MapArticles(queryModel);
            returnModel.PreviewModels = mapped;
            returnModel.SortBar       = new SortBindingModel()
            {
                SortByValues = new string[] { "Most recent", "Price (ascending)", "Price (descending)" }
            };

            return(returnModel);
        }