示例#1
0
        public Category Add(string name)
        {
            var category = new Category
            {
                Name = name
            };

            this.categories.Add(category);
            this.categories.SaveChanges();

            return category;
        }
        public static IEnumerable<Category> GenerateFundbotCategories()
        {
            var region = new Category { Name = "Region" };
            var assetClass = new Category { Name = "Asset Class" };
            var currency = new Category { Name = "Currency" };

            region.Values.Add(new CategoryValue { Category = region, Name = "CAD"});
            region.Values.Add(new CategoryValue { Category = region, Name = "USD" });
            region.Values.Add(new CategoryValue { Category = region, Name = "INTL" });

            assetClass.Values.Add(new CategoryValue { Category = assetClass, Name = "Equity" });
            assetClass.Values.Add(new CategoryValue { Category = assetClass, Name = "Bonds" });
            assetClass.Values.Add(new CategoryValue { Category = assetClass, Name = "Preferred" });

            currency.Values.Add(new CategoryValue { Category = currency, Name = "CAD" });
            currency.Values.Add(new CategoryValue { Category = currency, Name = "USD" });

            return new List<Category> { region, assetClass, currency };
        }
 public void HardDeleteCategory(Category category)
 {
     this.categories.HardDelete(category);
     this.categories.Save();
 }
 public void AddCategory(Category category)
 {
     this.categories.Add(category);
     this.categories.Save();
 }
        public void GetCategoriesAndWeights(out IEnumerable<Category> categories, out IEnumerable<CategoryWeight> categoryWeights)
        {
            var region = new Category { Name = RegionName };
            var assetClass = new Category { Name = AssetClassName };
            var currency = new Category { Name = CurrencyName };

            var weights = new List<CategoryWeight>();

            while (_csvReader.ReadNextRecord())
            {
                Security security;
                string currencyText, regionText, assetClassText;

                if (_csvReader.HasHeaders)
                {
                    security = new Security { Symbol = _csvReader["Symbol"] };
                    currencyText = _csvReader["Currency"];
                    regionText = _csvReader["Region"];
                    assetClassText = _csvReader["AssetClass"];
                }
                else
                {
                    security = new Security { Symbol = _csvReader[0] };
                    currencyText = _csvReader[1];
                    regionText = _csvReader[2];
                    assetClassText = _csvReader[3];
                }

                if (!region.Values.Any(v => v.Name.Equals(regionText, StringComparison.InvariantCultureIgnoreCase)))
                    region.Values.Add(new CategoryValue { Category = region, Name = regionText });
                if (!assetClass.Values.Any(v => v.Name.Equals(assetClassText, StringComparison.InvariantCultureIgnoreCase)))
                    assetClass.Values.Add(new CategoryValue { Category = assetClass, Name = assetClassText });
                if (!currency.Values.Any(v => v.Name.Equals(currencyText, StringComparison.InvariantCultureIgnoreCase)))
                    currency.Values.Add(new CategoryValue { Category = currency, Name = currencyText });

                var regionValue = region.Values.Single(v => v.Name.Equals(regionText, StringComparison.InvariantCultureIgnoreCase));
                var assetClassValue = assetClass.Values.Single(v => v.Name.Equals(assetClassText, StringComparison.InvariantCultureIgnoreCase));
                var currencyValue = currency.Values.Single(v => v.Name.Equals(currencyText, StringComparison.InvariantCultureIgnoreCase));

                weights.Add(new CategoryWeight
                {
                    Security = security,
                    Value = regionValue,
                    Weight = 100M
                });
                weights.Add(new CategoryWeight
                {
                    Security = security,
                    Value = assetClassValue,
                    Weight = 100M
                });
                weights.Add(new CategoryWeight
                {
                    Security = security,
                    Value = currencyValue,
                    Weight = 100M
                });
            }

            categories = new List<Category> { region, assetClass, currency };
            categoryWeights = weights;
        }
 public IQueryable<Project> AllProjectsByCategory(Category category)
 {
     var categoryId = category.Id;
     return this.projects.All()
         .Where(project => project.CategoryId == categoryId);
 }
 public void Delete(Category model)
 {
     this.categories.Delete(model);
     this.categories.Save();
 }
 public void Add(Category model)
 {
     this.categories.Add(model);
     this.categories.Save();
 }