public async Task <List <TimeSheet> > GetAllEmployeeTimeSheets(TimeSheetsViewModel model) { var employeeslist = await userManager.GetUsersInRoleAsync("Werknemer"); var employeesIds = employeeslist .Select(e => e.Id); return(await context.TimeSheets .Select(t => new TimeSheet { Id = t.Id, SheetID = t.SheetID, Project = t.Project, Month = t.Month, theDate = t.theDate, ProjectHours = t.ProjectHours, Overwork = t.Overwork, Sick = t.Sick, Absence = t.Absence, Approved = t.Approved, Other = t.Other, Submitted = t.Submitted, Comment = t.Comment, Training = t.Training, Url = t.Url, Data = t.Data, applicationUser = t.applicationUser }) .Where(t => employeesIds.Contains(t.Id) && t.Month.Equals(model.Month) && t.theDate.Year == model.theDate.Year) .ToListAsync()); }
// GET: Timesheets/Details/5 public ActionResult Details(int?id) { TimeSheetsViewModel model = new TimeSheetsViewModel(); MobileWorkDataEntities entities = new MobileWorkDataEntities(); try { Timesheets timesheetdetail = entities.Timesheets.Find(id); if (timesheetdetail == null) { return(HttpNotFound()); } // muodostetaan näkymämalli tietokannan rivien pohjalta TimeSheetsViewModel view = new TimeSheetsViewModel(); view.Id_Timesheet = timesheetdetail.Id_Timesheet; view.StartTime = timesheetdetail.StartTime.GetValueOrDefault(); view.StopTime = timesheetdetail.StopTime.GetValueOrDefault(); view.Comments = timesheetdetail.Comments; view.WorkComplete = timesheetdetail.WorkComplete; view.CreatedAt = timesheetdetail.CreatedAt.GetValueOrDefault(); view.LastModifiedAt = timesheetdetail.LastModifiedAt.GetValueOrDefault(); view.DeletedAt = timesheetdetail.DeletedAt.GetValueOrDefault(); view.Active = timesheetdetail.Active; view.Id_Employee = timesheetdetail.Id_Employee; view.FirstName = timesheetdetail.Employees?.FirstName; view.LastName = timesheetdetail.Employees?.LastName; view.Id_Customer = timesheetdetail.Customers?.Id_Customer; view.CustomerName = timesheetdetail.Customers?.CustomerName; ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null); view.Id_Contractor = timesheetdetail.Contractors?.Id_Contractor; view.CompanyName = timesheetdetail.Contractors?.CompanyName; ViewBag.CompanyName = new SelectList((from co in db.Contractors select new { Id_Contractor = co.Id_Contractor, CompanyName = co.CompanyName }), "Id_Contractor", "CompanyName", null); view.Id_WorkAssignment = timesheetdetail.WorkAssignments?.Id_WorkAssignment; view.Title = timesheetdetail.WorkAssignments?.Title; model = view; } finally { entities.Dispose(); } return(View(model)); }//details
public async Task <List <TimeSheet> > GetAllTraineeTimeSheets(TimeSheetsViewModel model) { //Hier wordt een lijst van timesheets aangemaakt van trainees specifiek, en alleen trainee-timesheets van de geselecteerde maand en het geselecteerde jaar. var traineeslist = await userManager.GetUsersInRoleAsync("Trainee"); var traineesIds = traineeslist .Select(e => e.Id); return(await context.TimeSheets .Select(t => new TimeSheet { Id = t.Id, SheetID = t.SheetID, Project = t.Project, Month = t.Month, theDate = t.theDate, ProjectHours = t.ProjectHours, Overwork = t.Overwork, Sick = t.Sick, Absence = t.Absence, Approved = t.Approved, Other = t.Other, Submitted = t.Submitted, Comment = t.Comment, Training = t.Training, Url = t.Url, Data = t.Data, applicationUser = t.applicationUser }) .Where(t => traineesIds.Contains(t.Id) && t.Month.Equals(model.Month) && t.theDate.Year == model.theDate.Year) .ToListAsync()); }
public ActionResult Create(TimeSheetsViewModel model) { MobileWorkDataEntities entities = new MobileWorkDataEntities(); Timesheets tsv = new Timesheets(); tsv.Id_Timesheet = model.Id_Timesheet; tsv.StartTime = model.StartTime; tsv.StopTime = model.StopTime; tsv.Comments = model.Comments; tsv.CreatedAt = DateTime.Now; tsv.LastModifiedAt = DateTime.Now; tsv.Active = model.Active; db.Timesheets.Add(tsv); int employeeId = int.Parse(model.FirstName); if (employeeId > 0) { Employees emp = db.Employees.Find(employeeId); tsv.Id_Employee = emp.Id_Employee; } int employeeLastId = int.Parse(model.LastName); if (employeeLastId > 0) { Employees emp = db.Employees.Find(employeeLastId); tsv.Id_Employee = emp.Id_Employee; } ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null); ViewBag.CompanyName = new SelectList((from co in db.Contractors select new { Id_Contractor = co.Id_Contractor, CompanyName = co.CompanyName }), "Id_Contractor", "CompanyName", null); try { db.SaveChanges(); } catch (Exception ex) { } return(RedirectToAction("Index")); }//create