public string GetDisplayName(int subCategoryID) { subcategory s = myRecords.FirstOrDefault(e => e.subCategoryID == subCategoryID); using (churchdatabaseEntities context = new churchdatabaseEntities()) { subcategoryitem item = context.subcategoryitems.FirstOrDefault(e => e.ChildCategoryID == s.subCategoryID); if (item != null) { subcategory child = myRecords.FirstOrDefault(e => e.subCategoryID == item.ChildCategoryID); subcategory parent = myRecords.FirstOrDefault(e => e.subCategoryID == item.ParentCategoryID); if (parent.ShortTitle == "") { s.DisplayName = string.Format("{0}-{1}", parent.SubCategoryName, child.SubCategoryName); } else { s.DisplayName = string.Format("{0}-{1}", parent.ShortTitle, child.SubCategoryName); } } else { //s.DisplayName = s.SubCategoryName; if (s.ShortTitle != "") { s.DisplayName = string.Format("{0}-{1}", s.ShortTitle, s.SubCategoryName); } else { s.DisplayName = s.SubCategoryName; } } } return(s.DisplayName); }
public ActionResult Edit(subcategory subcategory, int SubCategoryParentID = 0) { try { if (SubCategoryParentID > 0) { subcategory ParentCategory = db.subcategories.Find(SubCategoryParentID); subcategory.bankAccountID = ParentCategory.bankAccountID; subcategory.categoryID = ParentCategory.categoryID; } if (ModelState.IsValid) { db.Entry(subcategory).State = EntityState.Modified; db.SaveChanges(); TempData["Message2"] = string.Format("record update successfully."); if (SubCategoryParentID > 0) { subcategoryitem item = new subcategoryitem(); item.ParentCategoryID = SubCategoryParentID; item.ChildCategoryID = subcategory.subCategoryID; db.subcategoryitems.Add(item); db.SaveChanges(); } return(RedirectToAction("List", new { CategoryType = subcategory.category.CategoryName, budgetYear = subcategory.BudgetYear })); } } catch (Exception ex) { TempData["Message2"] = string.Format("Error editing record."); } return(PartialView(subcategory)); }
public ActionResult Create(subcategory subcategory, int SubCategoryParentID = 0) { subcategory subcat = db.subcategories.FirstOrDefault(e => e.SubCategoryName == subcategory.SubCategoryName && e.categoryID == subcategory.categoryID); if (subcat != null) { TempData["Message2"] = string.Format("Category <{0}> already exist", subcat.SubCategoryName); return(RedirectToAction("Index")); } try { if (SubCategoryParentID > 0) { subcategory ParentCategory = db.subcategories.Find(SubCategoryParentID); subcategory.bankAccountID = ParentCategory.bankAccountID; subcategory.categoryID = ParentCategory.categoryID; } if (ModelState.IsValid) { db.subcategories.Add(subcategory); db.SaveChanges(); SubCategoryRepository.AddRecord(subcategory); TempData["Message2"] = "Category created successfully."; if (SubCategoryParentID > 0) { subcategoryitem item = new subcategoryitem(); item.ParentCategoryID = SubCategoryParentID; item.ChildCategoryID = subcategory.subCategoryID; db.subcategoryitems.Add(item); db.SaveChanges(); } return(RedirectToAction("Create", new { CategoryType = subcategory.CategoryType })); } } catch (Exception ex) { TempData["Message2"] = "Error creating category"; } subcategory.category = CategoryRepository.GetCategoryByID(subcategory.categoryID); GetData(subcategory.category.CategoryName); return(PartialView(subcategory)); }
public ActionResult Edit(subcategory subcategory, int SubCategoryParentID = 0) { try { if (SubCategoryParentID > 0) { subcategory ParentCategory = db.subcategories.Find(SubCategoryParentID); subcategory.bankAccountID = ParentCategory.bankAccountID; subcategory.categoryID = ParentCategory.categoryID; } IEnumerable <subcategoryitem> oldItems = SubCategoryItemRepository.GetCategoryByChildren(subcategory.subCategoryID); //Remove old subcatergory item listing if (oldItems != null) { foreach (var i in oldItems.ToList()) { SubCategoryItemRepository.DeleteRecord(i); } } if (ModelState.IsValid) { db.Entry(subcategory).State = EntityState.Modified; db.SaveChanges(); TempData["Message2"] = string.Format("record update successfully."); if (SubCategoryParentID > 0) { subcategoryitem item = new subcategoryitem(); item.ParentCategoryID = SubCategoryParentID; item.ChildCategoryID = subcategory.subCategoryID; db.subcategoryitems.Add(item); db.SaveChanges(); } return(RedirectToAction("List", new { CategoryType = subcategory.category.CategoryName, budgetYear = subcategory.BudgetYear })); } } catch (Exception ex) { TempData["Message2"] = string.Format("Error editing record."); } return(PartialView(subcategory)); }
public ActionResult DeleteConfirmed(int SubCategoryID, int BudgetYear = 0) { subcategory subcategory = SubCategoryRepository.GetBySubCategoryID(SubCategoryID); subcategory.category = CategoryRepository.GetCategoryByID(subcategory.categoryID); string CategoryName = subcategory.category.CategoryName; budget budget = BudgetRepository.GetBudgetByCategory(SubCategoryID); subcategoryitem child = SubCategoryItemRepository.GetCategoryByChild(SubCategoryID); int parentCount = SubCategoryItemRepository.GetCategoryByParent(SubCategoryID).Count(); if ((budget != null) || (child != null) || (parentCount > 0)) { TempData["Message2"] = string.Format("Can not delete record! Budget items attached to this category"); } else { SubCategoryRepository.DeleteRecord(subcategory); } return(RedirectToAction("List", new { CategoryType = CategoryName, budgetYear = BudgetYear })); }
public void DeleteRecord(subcategoryitem record) { myRecords.Remove(record); context.subcategoryitems.Remove(record); context.SaveChanges(); }
public subcategoryitem GetCategoryByChild(int childID) { record = myRecords.FirstOrDefault(e => e.ChildCategoryID == childID); return(record); }
public void AddRecord(subcategoryitem Record) { myRecords.Add(record); }