I have an object with basically three important parameters I need to for total calculation. So for example my object is as below :
[
{'Id':1,'ResourceId':1,'StartDate':'01-01-2017','Hours':8,'TotalHrs':8},
{'Id':2,'ResourceId':1,'StartDate':'01-01-2017','Hours':4,'TotalHrs':4},
{'Id':3,'ResourceId':1,'StartDate':'01-03-2017','Hours':4,'TotalHrs':4},
{'Id':4,'ResourceId':1,'StartDate':'01-03-2017','Hours':4,'TotalHrs':4},
{'Id':5,'ResourceId':2,'StartDate':'01-01-2017','Hours':2,'TotalHrs':2},
{'Id':6,'ResourceId':2,'StartDate':'01-01-2017','Hours':4,'TotalHrs':4},
{'Id':7,'ResourceId':2,'StartDate':'01-03-2017','Hours':2,'TotalHrs':2},
]
So, currently the TotalHrs parameter is of the same value as the Hours parameter.
I want it to be total for a particular ResourceId and Startdate. i.e If in the array if the ResourceId and Startdate matches the TotalHrs parameter should be total of the value from Hours parameter.
So the final array becomes.
[
{'Id':1,'ResourceId':1,'StartDate':'01-01-2017','Hours':8,'TotalHrs':12},
{'Id':2,'ResourceId':1,'StartDate':'01-01-2017','Hours':4,'TotalHrs':12},
{'Id':3,'ResourceId':1,'StartDate':'01-03-2017','Hours':4,'TotalHrs':8},
{'Id':4,'ResourceId':1,'StartDate':'01-03-2017','Hours':4,'TotalHrs':8},
{'Id':5,'ResourceId':2,'StartDate':'01-01-2017','Hours':2,'TotalHrs':6},
{'Id':6,'ResourceId':2,'StartDate':'01-01-2017','Hours':4,'TotalHrs':6},
{'Id':7,'ResourceId':2,'StartDate':'01-03-2017','Hours':2,'TotalHrs':2},
]
Hence in the above example, ResourceId
: 1 and StartDate
: 01-01-2017 has two occurrences with Hours value as 8 and 4, so there TotalHrs becomes 8+4=12.
Also, I don't want to group by, I want the same number of elements in the resulting array but with an updated value for TotalHrs
.