Good Day to all master of asp.net MVC,
what problem with my code always same the 'EXPENSE' and 'BALANCE'
but diffrenet departmentid see my screenshot and code below
here is my code
private readonly RoleDataContext _roleDataContext = new RoleDataContext();
private readonly RoleAuthentication authenticate = new RoleAuthentication();
private readonly BudgetContext BudgetDb = new BudgetContext();
private readonly DepartmentContext DepartmentDB = new DepartmentContext();
private readonly EmployeeContext _employeeContext = new EmployeeContext();
//
// GET: /Budget/
public ActionResult Index(string Deptcode, int month = 1, int year = 2017)
{
//check if the user has an Account
if (!RoleAuthentication.HasAccount(User.Identity.GetUserName()))
{
return RedirectToAction("Create", "Employee");
}
//check if the user is a requestor
if (!RoleAuthentication.IsAuthenticated(User.Identity.GetUserName(), "6"))
{
return RedirectToAction("Index", "Budget");
}
//this is for authentication
var reqContext = new RequestContext();
var InvContext = new InventoryContext();
var TRANSACTIONSISSUED = new List<TRANSACTIONISSUEDITEM>();
var DepartmentContext = new DepartmentContext();
var ListTrans = InvContext.Transactions();
var Requests = InvContext.Transactions();
var Employeedb = new EmployeeContext();
var Employee = Employeedb.Find(User.Identity.GetUserName());
var budgetDb = new BudgetContext();
var DeptBudget = budgetDb.List().ToList();
TRANSACTIONSISSUED = InvContext.IssuedItems();
ViewBag.Message = "";
var YearSelected = new List<string>();
ViewBag.month = month;
ViewBag.year = year;
var List = (from b in BudgetDb.List()
join i in DepartmentDB.DistinctBudgetDeptList()
on b.DEPARTMENTID.Trim() equals i.DEPARTMENTID.Trim()
into a
from d in a.DefaultIfEmpty(new BudgetViewModel())
select new BudgetViewModel
{
MONTH = b.MONTH,
YEAR = b.YEAR,
DEPARTMENTID = b.DEPARTMENTID,
DEPARTMENTNAME = d.DEPARTMENTNAME,
DATETIME = b.DATETIME,
BUDGET = b.BUDGET
}).Where(c => c.YEAR == year && c.MONTH == month).ToList();
var Budget = BudgetDb.List()
.Where(c => c.YEAR == 2017 && c.MONTH == month )
.Select(i => i.BUDGET).FirstOrDefault();
var Expences = (from i in TRANSACTIONSISSUED
join r in ListTrans
on i.REQUESTNO.Trim() equals r.REQUESTNO.Trim()
where r.DATETIME.Month == month && r.DATETIME.Year == year
select new
{
Cost = i.COST,
Qty = i.QTY
}).Sum(e => e.Cost * e.Qty);
var Balance = Budget - Expences;
ViewBag.Budget = Budget;
ViewBag.Expences = Expences;
ViewBag.Balance = Balance;
return View(List.ToList());
}Thank you