public async Task <IActionResult> List(int?PageIndex) { List <EmployeeWorkplacePositionFullModel> empl = new List <EmployeeWorkplacePositionFullModel>(); AppUser user = await userManager.FindByNameAsync(User.Identity.Name); int companyId = await context.WorkPlaces.Where(x => x.EmployeeId == user.EmployeeId && x.ExitDate == null).Select(x => x.Branch.CompanyId).FirstOrDefaultAsync(); var employeeId = context.WorkPlaces.Where(x => x.Branch.CompanyId == companyId && x.ExitDate == null).Select(x => x.EmployeeId); foreach (var item in employeeId) { var employees = await context.Employees.Where(x => x.Id == item) .Join(context.WorkPlaces.Where(w => w.ExitDate == null), e => e.Id, w => w.EmployeeId, (employee, workplace) => new { employee, workplace }) .Join(context.Branches, x => x.workplace.BranchId, b => b.Id, (x, b) => new { x, b }) .Join(context.Companies, v => v.b.CompanyId, c => c.Id, (v, c) => new { v, c }) .Join(context.Positions, t => t.v.x.workplace.PositionId, p => p.Id, (model, position) => new { model, position }) .Join(context.Departments, z => z.position.DepartmentId, d => d.Id, (z, department) => new EmployeeWorkplacePositionFullModel { E_id = z.model.v.x.employee.Id, Ename = z.model.v.x.employee.Name, Surname = z.model.v.x.employee.Surname, FatherName = z.model.v.x.employee.FatherName, workplaceId = z.model.v.x.workplace.Id, EntryDate = z.model.v.x.workplace.EntryDate, Attendances = z.model.v.x.employee.Attendances.Where(x => x.EmployeeId == z.model.v.x.employee.Id).ToList(), BranchName = z.model.v.b.Name, IsHead = z.model.v.b.IsHead, CompanyName = z.model.c.Name, PositionName = z.position.Namme, DepartmentName = department.Name }).ToListAsync(); empl.AddRange(employees); } int Page = 2; EmployeeAttendance_Model employeeAttendance_Model = new EmployeeAttendance_Model { EmployeeWorkplacePositionFullModel = Pagination <EmployeeWorkplacePositionFullModel> .Create(empl, PageIndex ?? 1, Page), Pagination = Pagination <EmployeeWorkplacePositionFullModel> .Create(empl, PageIndex ?? 1, Page), Month = DateTime.Now.Month, Year = DateTime.Now.Year, Days = Enumerable.Range(1, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)).ToList() }; return(View(employeeAttendance_Model)); }
public IActionResult Create(EmployeeAttendance_Model Attendancemodel) { if (ModelState.IsValid) { Attendance attendance = new Attendance { Date = Attendancemodel.Attendance.Date, EmployeeId = Attendancemodel.Attendance.EmployeeId, Permission = Attendancemodel.Attendance.Permission, Reason = Attendancemodel.Attendance.Reason }; context.Attendances.AddAsync(attendance); context.SaveChangesAsync(); return(RedirectToAction("List")); } return(View()); }