public static void addSubcategories(int categoryId, String names) { String[] nameList = names.Split(';'); using (DB_entities db = new DB_entities()) { using (TransactionScope scope = new TransactionScope()) { foreach (String name in nameList) { if (name == "") { break; } subcategory subcateg = new subcategory(); subcateg.name = name; subcateg.category_id = categoryId; try { db.subcategories.Add(subcateg); db.SaveChanges(); } catch (Exception ex) { Log.error("addSubcategories - Insert.cs", DateTime.Now, ex); } } scope.Complete(); } } }
public ActionResult Create(income income) { try { subcategory subCat = SubCategoryRepository.GetBySubCategoryID(income.subCategoryID); if (income.bankAccountID == 0) { income.bankAccountID = subCat.bankAccountID; } if (income.Title == null) { income.Title = subCat.SubCategoryName; } if (income.Comment == null) { income.Comment = ""; } if (ModelState.IsValid) { db.incomes.Add(income); db.SaveChanges(); IncomeRepository.AddRecord(income); TempData["Message2"] = "Income added successfully."; return(RedirectToAction("Create")); } } catch (Exception ex) { TempData["Message2"] = "Error adding income"; } GetData(); return(PartialView(income)); }
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 int AddSubCategory(subcategory subcategory) { try { int id = context.subcategories.Count() + 1; subcategory.subcategoryID = id; subcategory.created_on = DateTime.Now; int result = 0; int flag = 0; List <subcategory> subcategoryList = context.subcategories.ToList(); foreach (var item in subcategoryList) { if (item.subcategoryName == subcategory.subcategoryName) { flag = 1; return(result); } } if (flag == 0) { context.subcategories.Add(subcategory); result = context.SaveChanges(); } return(result); } catch (SqlException) { throw; } catch (Exception) { throw; } }
public ActionResult Edit(income income) { try { subcategory subCat = SubCategoryRepository.GetBySubCategoryID(income.subCategoryID); if (income.bankAccountID == 0) { income.bankAccountID = subCat.bankAccountID; } if (income.Comment == null) { income.Comment = ""; } income.Title = subCat.SubCategoryName; income.bankAccountID = subCat.bankAccountID; if (ModelState.IsValid) { db.Entry(income).State = EntityState.Modified; db.SaveChanges(); TempData["Message2"] = "Record update successfully."; GetData(); return(RedirectToAction("Create")); } } catch (Exception ex) { TempData["Message2"] = "Error editing record."; } GetData(); return(PartialView(income)); }
public ActionResult Delete(int SubCategoryID) { ViewBag.SubCategoryID = SubCategoryID; subcategory subcategory = SubCategoryRepository.GetBySubCategoryID(SubCategoryID); 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; } 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 id) { subcategory subcategory = db.subcategories.Find(id); db.subcategories.Remove(subcategory); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Name,catId")] subcategory subcategory) { if (ModelState.IsValid) { db.Entry(subcategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(subcategory)); }
public ActionResult Edit([Bind(Include = "subcatId,CatId,Subcategoryname")] subcategory subcategory) { if (ModelState.IsValid) { db.Entry(subcategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CatId = new SelectList(db.categories, "categoryId", "categoryName", subcategory.CatId); return(View(subcategory)); }
public ActionResult Create([Bind(Include = "Id,Name,catId")] subcategory subcategory) { if (ModelState.IsValid) { db.subcategories.Add(subcategory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(subcategory)); }
public async Task <ActionResult> Edit([Bind(Include = "IdSubCategory,Name,IdCategory")] subcategory subcategory) { if (ModelState.IsValid) { db.Entry(subcategory).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(subcategory)); }
public ActionResult Create([Bind(Include = "subcatId,CatId,Subcategoryname")] subcategory subcategory) { if (ModelState.IsValid) { db.subcategories.Add(subcategory); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CatId = new SelectList(db.categories, "categoryId", "categoryName", subcategory.CatId); return(View(subcategory)); }
public async Task <ActionResult> Create([Bind(Include = "Name,IdCategory")] subcategory subcategory) { if (ModelState.IsValid) { db.subcategory.Add(subcategory); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(subcategory)); }
public ActionResult Edit([Bind(Include = "id,categoryid,subcategoryname,description")] subcategory subcategory) { if (ModelState.IsValid) { db.Entry(subcategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.categories = new SelectList(db.categories, "id", "categoryname", subcategory.category); return(View(subcategory)); }
public ActionResult Create([Bind(Include = "id,categoryid,subcategoryname,description")] subcategory subcategory) { if (ModelState.IsValid) { db.subcategories.Add(subcategory); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.categoryid = new SelectList(db.categories, "id", "categoryname", subcategory.category); return(View(subcategory)); }
// GET: subcategory/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } subcategory subcategory = await db.subcategory.FindAsync(id); if (subcategory == null) { return(HttpNotFound()); } return(View(subcategory)); }
public string PayeeCategory(string Payee) { payee payee = PayeeRepository.GetPayeeByName(Payee); if (payee == null) { return(""); } subcategory catgy = SubCategoryRepository.GetBySubCategoryID(payee.SubCategoryID); catgy.DisplayName = SubCategoryRepository.GetDisplayName(catgy.subCategoryID); return(catgy.DisplayName); }
// GET: subcategories/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } subcategory subcategory = db.subcategories.Find(id); if (subcategory == null) { return(HttpNotFound()); } return(View(subcategory)); }
public ActionResult DeleteConfirmed(int id) { try { subcategory subcategory = db.subcategories.Find(id); db.subcategories.Remove(subcategory); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { Session["error"] = "Cannot Delete This Category"; return(RedirectToAction("Index")); } }
// GET: CascadeDropDownLists/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } subcategory subcategory = db.subcategories.Find(id); if (subcategory == null) { return(HttpNotFound()); } ViewBag.CatId = new SelectList(db.categories, "categoryId", "categoryName", subcategory.CatId); return(View(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 async Task <ActionResult> Activate(int id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } subcategory subcategory = await db.subcategory.FindAsync(id); if (subcategory == null) { return(HttpNotFound()); } subcategory.DeletionDatetime = null; await db.SaveChangesAsync(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public ActionResult Edit(int SubCategoryID, int BudgetYear = 0) { subcategory subcategory = SubCategoryRepository.GetBySubCategoryID(SubCategoryID); subcategory.category = CategoryRepository.GetCategoryByID(subcategory.categoryID); subcategory.BudgetYear = BudgetYear; GetData(subcategory.category.CategoryName); ViewBag.ParentCategoryName = ""; bool HasParent = SubCategoryItemRepository.HasParent(subcategory.subCategoryID); if (HasParent) { int parentCategoryID = SubCategoryItemRepository.GetCategoryByChild(subcategory.subCategoryID).ParentCategoryID; ViewBag.ParentCategoryName = SubCategoryRepository.GetBySubCategoryID(parentCategoryID).SubCategoryName; } return(PartialView(subcategory)); }
// GET: subcategories/Edit/5 public ActionResult Edit(int?id) { if (Session["uid"] == null) { return(RedirectToAction("AdminLogin", "Administrators")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } subcategory subcategory = db.subcategories.Find(id); if (subcategory == null) { return(HttpNotFound()); } ViewBag.categories = new SelectList(db.categories, "id", "categoryname", subcategory.category); return(View(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 Create(expense expense) { try { subcategory subCat = SubCategoryRepository.GetBySubCategoryID(expense.subCategoryID); if (expense.bankAccountID == 0) { expense.bankAccountID = subCat.bankAccountID; } if (expense.Comment == null) { expense.Comment = ""; } if (ModelState.IsValid) { db.expenses.Add(expense); db.SaveChanges(); ExpenseRepository.AddRecord(expense); TempData["Message2"] = "Expense added successfully."; if (expense.PendingBillID > 0) { bill bill = db.bills.Find(expense.PendingBillID); bill.Status = "Processing"; db.SaveChanges(); BillRepository.AddRecord(bill); } GetData(); @ViewBag.ExpenseType = ""; return(RedirectToAction("Create", "Expense", new { payeeID = 0 })); } } catch (Exception ex) { TempData["Message2"] = "Error adding expense"; } GetData(); @ViewBag.ExpenseType = ""; return(PartialView(expense)); }
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 ActionResult Edit(expense expense, string RequestType) { try { subcategory subCat = SubCategoryRepository.GetBySubCategoryID(expense.subCategoryID); if (expense.bankAccountID == 0) { expense.bankAccountID = subCat.bankAccountID; } if (expense.Comment == null) { expense.Comment = ""; } if (ModelState.IsValid) { db.Entry(expense).State = EntityState.Modified; db.SaveChanges(); TempData["Message2"] = string.Format("{0} record update successfully.", expense.Payee); GetData(); if (RequestType == "CommittedUpdate") { return(RedirectToAction("List", "Expense", new { code = "DateRangeSearch", bDate = DateTime.Today.Date.AddDays(-10), eDate = DateTime.Today.Date })); } else { return(RedirectToAction("Create")); } } } catch (Exception ex) { TempData["Message2"] = string.Format("Error editing {0} record.", expense.Payee); } GetData(); return(PartialView(expense)); }
// GET: reviews/Details/5 public ActionResult Details(int?id) { /* var t = ( * from x in db.Reviews where (x.productId = id) select x * ); * return View(t);*/ if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } product pro = db.Products.Find(id); var a = pro.catId; category cat = db.categories.FirstOrDefault(x => x.Id == a); ViewBag.catname = cat.Name; var b = pro.subcatId; subcategory scat = db.subcategories.FirstOrDefault(x => x.Id == b); ViewBag.scatname = scat.Name; Review rev = db.Reviews.Find(id); var rev1 = db.Reviews.Where(d => d.productId == id); rev1 = rev1.OrderByDescending(x => x.dape_post); var c = rev1.Count(); ViewData["reviewcount"] = c; ViewBag.pass = rev1; var tup = new Tuple <product, Review>(pro, rev); // if (rev== null) // { // return HttpNotFound(); // } return(View(tup)); }