Ejemplo n.º 1
0
        public ActionResult AddCategory()
        {
            var userName = GetUserName();
            var category = new Category
            {
                Id = Guid.NewGuid(),
                Name = "New Category",
                Owner = _db.Users.First(u => u.UserName == userName)
            };

            _db.Categories.Add(category);
            _db.SaveChanges();

            return SafeJson(category);
        }
Ejemplo n.º 2
0
        public ActionResult AddRule(Category category)
        {
            var userName = GetUserName();
            var match = _db.Categories
                            .Where(t => t.Owner.UserName == userName)
                            .First(c => c.Id == category.Id);
            var rule = new Rule
            {
                Id = Guid.NewGuid(),
                Name = "New Rule",
                Pattern = "^[a-zA-Z0-9]*$",
                Result = match
            };

            if (match.Rules == null) match.Rules = new List<Rule>();

            match.Rules.Add(rule);
            _db.SaveChanges();

            return SafeJson(rule);
        }
Ejemplo n.º 3
0
        public ActionResult SaveCategory(Category category)
        {
            _db.Categories.AddOrUpdate(category);

            if (category.Rules != null)
            {
                foreach (var rule in category.Rules)
                {
                    _db.Rules.AddOrUpdate(rule);
                }
            }

            _db.SaveChanges();

            return SafeJson(true);
        }
Ejemplo n.º 4
0
        public ActionResult RemoveCategory(Category category)
        {
            var userName = GetUserName();
            var match = _db.Categories
                            .Where(t => t.Owner.UserName == userName)
                            .FirstOrDefault(c => c.Id == category.Id);
            if (match == null) return SafeJson(false);

            foreach (var transaction in _db.Transactions)
            {
                if (transaction.Category == match)
                    transaction.Category = null;
            }

            _db.Categories.Remove(match);
            _db.SaveChanges();

            return SafeJson(true);
        }