Exemple #1
0
        public ActionResult Category(CategoryTypeEnum type)
        {
            var result      = new List <CategoryViewModel>();
            int MAX_ARTICLE = Int16.Parse(ConfigurationManager.AppSettings["MaximumItemsPerPage"]);

            var entities = categoryRepository
                           .GetMany(c => c.Type == type)
                           .ToList();

            foreach (Category c in entities)
            {
                var list = articleRepository
                           .GetMany(a => a.CategoryID == c.ID && a.Status == ArticleStatus.Public)
                           .OrderByDescending(a => a.CreateAt)
                           .Take(MAX_ARTICLE)
                           .ToList();

                var item = list.Count() > 0
                        ? list.Select(l => l.ToViewModel()).ToList()
                        : new List <ArticleViewModel>();

                result.Add(new CategoryViewModel
                {
                    ID       = c.ID,
                    Name     = c.Name,
                    Articles = item
                });
            }
            return(PartialView(result));
        }
Exemple #2
0
        // Get all categories
        public IEnumerable <AppCategory> GetAllCategories(CategoryTypeEnum type)
        {
            IEnumerable <AppCategory> categories = null;

            switch (type)
            {
            case CategoryTypeEnum.All:
                categories = _categoryRepose.GetAllCategories().Select(_ => new AppCategory()
                {
                    Id              = _.Id,
                    CategoryName    = _.Name,
                    ParentId        = _.CategoryParentId,
                    ParentCategory  = _.ParentCategory == null ? null : _.ParentCategory.ToAppCategory(),
                    ChildCount      = (_.ChildCategory != null) ? _.ChildCategory.Count() : 0,
                    ChildCategories = _.ChildCategory == null ? null : _.ChildCategory.Select(cat => new AppCategory()
                    {
                        Id = cat.Id, CategoryName = cat.Name, ParentId = cat.CategoryParentId
                    }),
                });
                break;

            case CategoryTypeEnum.ParentOnly:
                categories = _categoryRepose.GetParentCategories().Select(_ => new AppCategory()
                {
                    Id              = _.Id,
                    CategoryName    = _.Name,
                    ParentId        = _.CategoryParentId,
                    ParentCategory  = _.ParentCategory == null ? null : _.ParentCategory.ToAppCategory(),
                    ChildCount      = (_.ChildCategory != null) ? _.ChildCategory.Count() : 0,
                    ChildCategories = _.ChildCategory == null ? null : _.ChildCategory.Select(cat => new AppCategory()
                    {
                        Id = cat.Id, CategoryName = cat.Name, ParentId = cat.CategoryParentId
                    }),
                });
                break;

            case CategoryTypeEnum.ChildOnly:
                categories = _categoryRepose.GetChildCategories().Select(_ => new AppCategory()
                {
                    Id              = _.Id,
                    CategoryName    = _.Name,
                    ParentId        = _.CategoryParentId,
                    ParentCategory  = _.ParentCategory == null ? null : _.ParentCategory.ToAppCategory(),
                    ChildCount      = (_.ChildCategory != null) ? _.ChildCategory.Count() : 0,
                    ChildCategories = _.ChildCategory == null ? null : _.ChildCategory.Select(cat => new AppCategory()
                    {
                        Id = cat.Id, CategoryName = cat.Name, ParentId = cat.CategoryParentId
                    }),
                });
                break;

            default:
                break;
            }
            return(categories.ToList <AppCategory>());
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceCategory" /> class.
 /// </summary>
 /// <param name="name">name (required).</param>
 /// <param name="categoryType">categoryType (required) (default to CategoryTypeEnum.Manufacturer).</param>
 public DeviceCategory(string name = default(string), CategoryTypeEnum categoryType = CategoryTypeEnum.Manufacturer)
 {
     // to ensure "name" is required (not null)
     if (name == null)
     {
         throw new ArgumentNullException("name is a required property for DeviceCategory and cannot be null");
     }
     this.Name         = name;
     this.CategoryType = categoryType;
 }
        public async Task <List <HandlerServiceResult> > BuildStatistics(User user, CategoryTypeEnum type = CategoryTypeEnum.None)
        {
            var result = new List <HandlerServiceResult>
            {
                new HandlerServiceResult
                {
                    Message    = "Here's your statistics:",
                    StatusCode = StatusCodeEnum.Ok
                }
            };

            var categories = await _categoryDocumentService.GetByUserIdAsync(user.Id);

            if (type != CategoryTypeEnum.None)
            {
                categories = categories.Where(c => c.Type == type && c.Configured).ToList();
            }

            foreach (var category in categories)
            {
                if (category.Type == CategoryTypeEnum.Income)
                {
                    result.Add(new HandlerServiceResult
                    {
                        Message = $"{category.Name}: +{BuildAmountWithCurrency((float) category.IncomeForThisMonthInCents / 100, category.Currency)} this month; " +
                                  $"+{BuildAmountWithCurrency((float) category.IncomeInCents / 100, category.Currency)} for all time.\n",
                        StatusCode = StatusCodeEnum.Ok
                    });
                }
                else
                {
                    result.Add(new HandlerServiceResult
                    {
                        Message = $"{category.Name}: -{BuildAmountWithCurrency((float)category.ExpenseForThisMonthInCents / 100, category.Currency)} this month; " +
                                  $"-{BuildAmountWithCurrency((float)category.ExpenseInCents / 100, category.Currency)} for all time.\n",
                        StatusCode = StatusCodeEnum.Ok
                    });
                }
            }

            return(result);
        }
Exemple #5
0
        public void Serialize(List <Category> categories, CategoryTypeEnum CategoryType)
        {
            Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer();
            serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;
            serializer.Formatting        = Formatting.Indented;

            try
            {
                using (StreamWriter sw = new StreamWriter(string.Format("json/{0}-{1}.json", CategoryType, DateTime.UtcNow.ToString("yyyy-MM-dd"))))
                    using (JsonWriter writer = new JsonTextWriter(sw))
                    {
                        serializer.Serialize(writer, categories);
                    }

                Log.Information("{CategoryType} successfully written to JSON file", CategoryType);
            }
            catch (Exception ex)
            {
                Log.Error("An error ocurred while trying to write the JSON file: {Ex}", ex);
            }
        }
        private async Task <List <HandlerServiceResult> > ConfigureOperationType(CategoryTypeEnum type, User user)
        {
            HandlerServiceResult nextQuestion;

            var categories = await _categoryDocumentService.GetByUserIdAsync(user.Id);

            categories = categories.Where(c => c.Configured && c.Type == type).ToList();

            if (categories.Count > 0)
            {
                var operation = new Operation
                {
                    Configured = false,
                    Id         = _operationDocumentService.GenerateNewId()
                };

                await _operationDocumentService.InsertAsync(operation);

                user.Context = new Context
                {
                    OperationId  = operation.Id,
                    CategoryType = type,
                    CurrentNode  = _tree
                };

                nextQuestion = await _questionService.BuildQuestion(user);
            }
            else
            {
                nextQuestion = _resultService.BuildOperationTypeCleanCategoryList();
            }

            await _userDocumentService.UpdateAsync(user);

            return(new List <HandlerServiceResult> {
                nextQuestion
            });
        }
Exemple #7
0
        public static string ToDisplay(this CategoryTypeEnum type)
        {
            switch (type)
            {
            case CategoryTypeEnum.measure:
                return("Measures / Propositions");

            case CategoryTypeEnum.federal:
                return("Federal");

            case CategoryTypeEnum.state:
                return("State");

            case CategoryTypeEnum.legislative:
                return("Legislative");

            case CategoryTypeEnum.judicial:
                return("Judicial");

            default:
                return("Undefined");
            }
        }
        public void FilterCategoryList()
        {
            if (SelectedCategoryType != null)
            {
                List <CategoryViewModel> result = null;
                CategoryTypeEnum         ctenum = (CategoryTypeEnum)SelectedCategoryType.Id;
                switch (ctenum)
                {
                case CategoryTypeEnum.measure:
                    result = CategoryList.Where(n => n.CategoryTypeId == ctenum &&
                                                n.SubcategoryTypeId == CategorySubTypeEnum.undefined && !n.Delete)?.OrderBy(n => n.Sequence)?.ToList();
                    break;

                case CategoryTypeEnum.federal:
                    result = CategoryList.Where(n => n.CategoryTypeId == ctenum && !n.Delete)?.OrderBy(n => n.Sequence)?.ToList();
                    break;

                case CategoryTypeEnum.state:
                    result = CategoryList.Where(n => n.CategoryTypeId == ctenum &&
                                                n.SubcategoryTypeId == CategorySubTypeEnum.undefined && !n.Delete)?.OrderBy(n => n.Sequence)?.ToList();
                    break;

                case CategoryTypeEnum.legislative:
                    result = CategoryList.Where(n => n.CategoryTypeId == ctenum &&
                                                n.SubcategoryTypeId == CategorySubTypeEnum.undefined && !n.Delete)?.OrderBy(n => n.Sequence)?.ToList();
                    break;

                case CategoryTypeEnum.judicial:
                    result = CategoryList.Where(n => n.CategoryTypeId == ctenum &&
                                                !n.Delete)?.OrderBy(n => n.Sequence)?.ToList();
                    break;
                }
                FilteredCategoryList = new ObservableCollection <CategoryViewModel>(result);
                SelectedCategory     = FilteredCategoryList.FirstOrDefault();
                ResetIndex();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ItemCategoryAttributes" /> class.
 /// </summary>
 /// <param name="name">Kategori adı (required).</param>
 /// <param name="bgColor">Renk.</param>
 /// <param name="textColor">Yazı rengi.</param>
 /// <param name="categoryType">Kategori tipi (required).</param>
 /// <param name="parentId">parentId.</param>
 public ItemCategoryAttributes(string name = default(string), string bgColor = default(string), string textColor = default(string), CategoryTypeEnum categoryType = default(CategoryTypeEnum), int?parentId = default(int?))
 {
     // to ensure "name" is required (not null)
     if (name == null)
     {
         throw new InvalidDataException("name is a required property for ItemCategoryAttributes and cannot be null");
     }
     else
     {
         this.Name = name;
     }
     // to ensure "categoryType" is required (not null)
     if (categoryType == null)
     {
         throw new InvalidDataException("categoryType is a required property for ItemCategoryAttributes and cannot be null");
     }
     else
     {
         this.CategoryType = categoryType;
     }
     this.BgColor   = bgColor;
     this.TextColor = textColor;
     this.ParentId  = parentId;
 }
 /// <summary>
 /// tmCategory
 /// </summary>
 /// <returns>ID of new row inserted to database.</returns>
 private int SetCategory(string name, int attributeDBID, CategoryTypeEnum categoryType, bool xCategory, bool includeNullCategory, long categoryOrd, int attributeIdentifier)
 {
     string tableName = "tmCategory";
     string autoIncrementColumn = GetAutoIncrementColumnName(tableName);
     int autoIncrementValue = GetTableAutoIncrementValue(tableName, 1);
     string query = "INSERT INTO " + tableName + " (" + autoIncrementColumn
         + ",Name,QuantityID,CategorySubTypeID,BoolTypeID"
         + ",XCategory,IncludeNULL,wSavedCountUsed,Ord) VALUES "
         + "(" + autoIncrementValue + ","
         + "'" + name + "',"
         + attributeDBID + ","
         + constants.CategoryTypeEnumDictionary[categoryType] + ","
         + "1," //BoolTypeID = No bool
         + constants.GetBool(xCategory) + ","
         + constants.GetBool(includeNullCategory) + ","
         + constants.wSavedCountUsed + "," //wSavedCountUsed
         + categoryOrd
         + ")";
     this.categories[attributeIdentifier].Add(name, autoIncrementValue);
     this.categoriesOrds[attributeIdentifier].Add(categoryOrd, name);
     ExecuteInsertQuery(query, tableName);
     return autoIncrementValue;
 }
Exemple #11
0
 public async Task <IEnumerable <DTO.Category> > GetCategories(CategoryTypeEnum categoryType)
 {
     return(_mapperService.Map <IEnumerable <DTO.Category> >(categoryType == CategoryTypeEnum.Expense ? await _categoryBusiness.GetExpenseCategories() : await _categoryBusiness.GetIncomeCategories()));
 }
Exemple #12
0
 public ActionResult Announcement(CategoryTypeEnum type)
 {
     return(Category(type));
 }