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); }
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); }
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); }
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); }