public ActionResult AddSpendingCategory(SpendingCategoryModel model) { // Is the category a new category bool unique = true; if (ModelState.IsValid) { List <string> categories = GetCategories(GetIdUsingName(User.Identity.Name)); foreach (string category in categories) { if (category == model.Category) { unique = false; } } if (unique) { model.Id = GetIdUsingName(User.Identity.Name); AddCategory(model); } ViewBag.Unique = unique; ViewBag.Success = unique; ViewBag.hasCategories = true; } else { // Don't raise any flags and let normal error reporting take over ViewBag.Unique = true; ViewBag.Success = false; } return(View()); }
public static void AddCategory(SpendingCategoryModel model) { ExecuteDb("INSERT INTO main.Categories (Id, Category) VALUES (@Id, @Category)", model); }