public IActionResult Index() { BudgetPost bPost = new BudgetPost(); bPost.Results = budgetDAL.GetAllPosts(); return(View(bPost)); }
public bool SaveNewPost(BudgetPost post) { try { using (SqlConnection conn = new SqlConnection(ConnString)) { conn.Open(); SqlCommand cmd = new SqlCommand(Insert_Budget_SQL, conn); cmd.Parameters.AddWithValue("@BudgetName", post.BudgetName); cmd.Parameters.AddWithValue("@BudgetCategory", post.BudgetCategory); int rowsaffected = cmd.ExecuteNonQuery(); if (rowsaffected == 1) { return(true); } else { return(false); } } } catch (SqlException) { return(false); } }
public List <BudgetPost> GetAllPosts() { List <BudgetPost> posts = new List <BudgetPost>(); using (SqlConnection conn = new SqlConnection(ConnString)) { conn.Open(); SqlCommand cmd = new SqlCommand(GET_ALL_Budgets_SQL, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { BudgetPost temp = new BudgetPost(); temp.BudgetId = Convert.ToInt32(reader["BudgetId"]); temp.BudgetCategory = Convert.ToString(reader["BudgetCategory"]); temp.BudgetName = Convert.ToString(reader["BudgetName"]); temp.IsActive = Convert.ToBoolean(reader["IsActive"]); temp.ImgBudgetId = temp.BudgetCategory; if (temp.IsActive) { posts.Add(temp); } } return(posts); } }
public IActionResult NewBudget(BudgetPost bPost) { try { bPost.ImgBudgetId = bPost.BudgetCategory; budgetDAL.SaveNewPost(bPost); SetTempCategory(bPost.BudgetId); } catch (NullReferenceException) { throw; } return(RedirectToAction("Index", "Budget")); }
public bool RemovePost(BudgetPost post) { try { using (SqlConnection conn = new SqlConnection(ConnString)) { conn.Open(); SqlCommand cmd = new SqlCommand(Remove_Budgets_SQL, conn); cmd.Parameters.AddWithValue("@BudgetId", post.BudgetId); int rowsaffected = cmd.ExecuteNonQuery(); if (rowsaffected == 1) { return(true); } else { return(false); } } } catch (SqlException) { return(false); } }
public IActionResult Remove(BudgetPost bPost) { budgetDAL.RemovePost(bPost); return(RedirectToAction("Index", "Budget")); }
public IActionResult BudgetSelect(BudgetPost bPost) { SetTempCategory(bPost.BudgetId); return(View(bPost)); }