I need to generate some hour accounts if they don't exist and tried to make the method as easy as possible. Unfortunately I'm stuck at the following.
This is how I would check / create an account for every month:
// January
if (!_db.Stundenkonto.Any(x => x.MitarbeiterId == mitarbeiterId && x.Jahr == jahr && x.Monat == 1))
{
HrsAccount acc = new HrsAccount
{
AccountId = new Guid(),
UserId = loggedInUser,
Month = 1 <<--- This is where I'd need the number of the Enum (1),
HoursToWork = model.data[0].january <<--- Here I'd need the name of the Enum
HoursWorked = model.data[1].january <<-- Same here
}
}
So as you can see I need number AND value of the Enum. I tried:
foreach (MonthEnum month in Enum.GetValues(typeof(MonthEnum)))
{
HrsAccount acc = new HrsAccount
{
AccountId = new Guid(),
UserId = loggedInUser,
Month = (double)month,
HoursToWork = model.data[0].month <<-- Gives errors
HoursWorked = model.data[1].month <<-- on these two
}
}
Is it possible to get this working as I need it?
Edit: Sorry here is the Enum:
public enum MonthEnum
{
january = 1,
february,
march,
april,
may,
june,
july,
august,
september,
oktober,
november,
december
}
model.data
are 4 arrays. They are all the same except one holds the hours the employee has to work, the other one how much the employee worked. The others are just calculations of those so they look like this:
model.data[0]
: <<-- Hours he has to work
january: 60,
february: 120,
january: 120
march: 175,
april: 165,
may: 176,
june: 186,
july: 176,
august: 176,
september: 140,
october: 120,
november: 110,
december: 146
model.data[1]
<<-- how much he actually worked
model.data[2]
<<-- how many hrs were paid
model.data[3]
<<-- difference between hrs he should work and hrs he worked
model.data[4]
<<-- difference last month