Walang Forever Ответов: 1

Какая проблема с моим кодом


Добрый день всем, вах проблема с моим кодом
aslways же результат на счет, но баланс в порядке..
Контроллер
public ActionResult Index(string DepName, 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 Expences = (from i in TRANSACTIONSISSUED
                         join r in ListTrans
                         on i.REQUESTNO.Trim() equals r.REQUESTNO.Trim()
                         where  r.DEPARTMENT.Trim() == Employee.DEPTCODE.Trim() &&
                         r.DATETIME.Month == month && r.DATETIME.Year == year
                         select new EXpenseTransactionViewModel
                         {
                             Month = r.DATETIME.Month,
                             Year = r.DATETIME.Year,
                             Cost = i.COST,
                             Qty = i.QTY
                         }).ToList();

              foreach(BudgetViewModel item in List)
              {
                  double Expense = Expences.Where(e => e.Month == item.MONTH && e.Year == item.YEAR).Sum(e => e.Cost * e.Qty);
                  item.BALANCE = item.BUDGET- Expense;
                  item.EXPENCES = Expense;
              }


         return View(List.ToList());
      }


Смотреть
@model IEnumerable<WarehouseRtoRSystem.Models.BudgetViewModel>

@{
    ViewBag.Title = "Index";
}


<div class="w3-white">
    <div class="w3-container w3-teal header w3-text-white w3-card w3-border">
        <div class="w3-col m12 ">
            <br />
        </div>
        <h2 class="">Budget</h2>
        <p class="w3-blockquote"></p>
        <div class="w3-col m12 ">
            <br />
        </div>

    </div>
    <div class="w3-container">
        <div class="w3-col m12 ">
            <br />
        </div>
        <div class="w3-col m12 ">
            <br />
        </div>

        @using (Html.BeginForm())
        {
            @ViewBag.Message

            <label>Month </label>
            <select id="month" name="month">
                @{ string[] Months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; }
                @for (var i = 0; i < 12; i++)
                {
                    var m = i + 1;
                    if (Convert.ToInt32(ViewBag.month) == m)
                    {
                        <option value=@m selected>@Months[i]</option>
                    }
                    else
                    {
                        <option value=@m>@Months[i]</option>
                    }
                }

            </select>

            <label>YEAR</label>

            <select id="year" name="year">
                @for (var c = 0; c < 1000; c++)
                {
                    var yr = c + 2017;
                    if (Convert.ToInt32(ViewBag.year) == yr)
                    {
                        <option value=@yr selected>
                            @yr
                        </option>
                    }
                    else
                    {
                        <option value=@yr> @yr</option>
                    }
                }
            </select>
            <input type="submit" value="Filter" class="btn btn-default" />
        }
        <br />
        <div class="w3-col m12 ">
            <span> @Html.ActionLink("Update Budget", "Create", "Budget", new { @class = "btn btn-success" })</span>
            <br />
            <br />
        </div>
        <div class="w3-col m12 table-responsive" style="height: 300px">
            <table class="table w3-white w3-striped w3-border">
                <tr class="w3-teal ">
                    <th>
                        DATE INSERTED
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.DEPARTMENTID)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.DEPARTMENTNAME)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.BUDGET)
                    </th>

                    <th>EXPENCE</th>

                    <th>BALANCE</th>
                    
                </tr>

                @foreach (var item in Model)
                {
                    <tr>
                        <td>
                            @Html.DisplayFor(modelItem => item.DATETIME)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.DEPARTMENTID)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.DEPARTMENTNAME)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.BUDGET)
                        </td>

                        <td>
                            @Html.DisplayFor(modelItem => item.EXPENCES)
                           
                        </td>
                        <td>
                             @Html.DisplayFor(modelItem => item.BALANCE)
                        </td>


                    </tr>
                }

            </table>
        </div>

        <div class="w3-col m12 ">
            @Html.ActionLink("Export to Excel", "GenerateExcels", "Budget", new { @class = "w3-btn btn-success" })

        </div>
        <div class="w3-col m12 ">
            <br />
        </div>
    </div>
   
        <div class="w3-col m12 ">
            <br />
        </div>
        <div class="w3-col m12 ">
            <br />
        </div>
        <div class="w3-col m12 ">
            <br />
        </div>
       <div class="w3-col m12 ">
            <br />
        </div>
        <div class="w3-col m12 ">
            <br />
        </div>
        <div class="w3-col m12 ">
            <br />
        </div>
   
</div>


Что я уже пробовал:

Смотрите мой код выше, какая проблема с моим кодом смотрите мою загруженную картинку
спасибо
Показывает: наиболее удивительных изображений в Интернете[^]

Richard MacCutchan

Пожалуйста, отредактируйте свой вопрос и объясните, в чем проблема.

1 Ответов

Рейтинг:
2

RAJU Kanumuri

Привет,

Из-за приведенной ниже строки одни и те же расходы применяются ко всем статьям.Расходы
пункт.Расходы = расходы;
Попробуйте рассчитать расходы в приведенном ниже цикле
foreach (элемент BudgetViewModel в списке)



Спасибо