My problem:
I need to add 'overtime' for all previous months from the beginning of the year to the month selected.
My table at sql server:
Overtime : varchar(20)
Id | Login | Year | Month | Day | Overtime
---+-------+------+-------+-----+----------
1 | MIPA | 2020 | 1 | 1 | 08:00
2 | MIPA | 2020 | 1 | 2 | 08:00
3 | MIPA | 2020 | 1 | 3 | 07:30
4 | MIPA | 2020 | 1 | 4 | 12:00
...
30 | MIPA | 2020 | 1 | 30 | 04:00
...
41 | MIPA | 2020 | 2 | 1 | 08:00
42 | MIPA | 2020 | 2 | 2 | 08:00
43 | MIPA | 2020 | 2 | 3 | 07:30
44 | MIPA | 2020 | 2 | 4 | 12:00
...
52 | MIPA | 2020 | 2 | 25 | 04:00
//so if the user chose March (3) and year: 2020(in dropdownlist). This function must extract the aggregated information from the overtime column of the previous months of the selected year. (that is, in the example for January (1) and February (2) and for 2020)
Controller:
[HttpPost]
public async Task<ActionResult> PartialTableEcp()
{
int numberMonth= 3;
int numberYear= 2020;
int numberOfDays= 31;
var userName = _httpContextAccessor.HttpContext.User.Identity.Name;
var existingRecords = _tableEcpContext.Karta
.Where(x => x.Login == userName &&
x.Year == numberYear &&
x.Month == numberMonth-1) .Select(i => new{
i.Overtime
}).ToList();
and now there is a problem how to sum all these values .. preferably in HHH: mm format
var thisValue = that this value would be written to the variable var;
var viewModel = new ParentView { Model1 = karta };
return PartialView("_TableViewEcp", viewModel);
}
Model:
public partial class Karta_Model
{
[Key]
public int Id { get; set; }
public string? Login { get; set; }
public int Year { get; set; }
public int Month{ get; set; }
public int? DayOfMonth { get; set; }
public string? Overtime { get; set; }
}
public partial class ParentView
{
public List<Karta_Model> Model1 { get; set; }
}
What I have tried:
anyone have an idea?
what I wrote is at the top