/* GET: Hours * public async Task<IActionResult> Index() * { * return View(await _context.Hour.ToListAsync()); * }*/ // GET: Hours/Details/5 public async Task <IActionResult> Details(int?id, int?Selectbilling, int?approval, int?description, int?clients, int?projects, int?month, int?year) { GetSessions(); if (ViewBag.Email == null) { return(ExpiredSession()); } try { if (id == null) { return(NotFound()); } var hour = await _context.Hour .FirstOrDefaultAsync(m => m.Id == id); if (hour == null) { return(NotFound()); } int empId = ViewBag.Id; var accessLevel = ViewBag.AcessLevel; ViewBag.Month = month; ViewBag.Year = year; ViewBag.Approval = approval; ViewBag.Description = description; ViewBag.Clients = clients; ViewBag.Projects = projects; var horas = await _hourService.FindAllPerEmployeeAsync(ViewBag.Id, Selectbilling, approval, description, clients, projects, month, year); var clientes = await _clientService.FindAllAsync(accessLevel, empId); var projetos = await _projectService.FindProjectAsync(empId, accessLevel); var descriptions = await _context.Description.Where(x => x.Active == 1).ToListAsync(); var localities = await _context.Locality.Where(x => x.Active == 1).ToListAsync(); //var funcionarios = await _employeeService.FindEmployeesActivesAsync(); var viewModel = new HourFormViewModel { Hour = hour, Projects = projetos, Clients = clientes, Description = descriptions, Locality = localities }; return(View(viewModel)); } catch (Exception e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
public async Task <IActionResult> Index(int?Selectbilling, int?approval, int?description, int?clients, int?projects, int?employees, int?month, int?year) { GetSessions(); if (ViewBag.Email == null) { return(ExpiredSession()); } try { ViewBag.Month = month; ViewBag.Year = year; ViewBag.Billing = Selectbilling; ViewBag.Approval = approval; ViewBag.Description = description; ViewBag.Clients = clients; ViewBag.Projects = projects; ViewBag.Employees = employees; int empId = ViewBag.Id; var accessLevel = ViewBag.AcessLevel; //var result = await _hourService.FindAllAsync(month, year); var horas = await _hourService.FindAllAsync(Selectbilling, approval, description, clients, projects, employees, month, year, empId, accessLevel); var clientes = await _clientService.FindAllAsync(accessLevel, empId); var projetos = await _projectService.FindProjectAsync(empId, accessLevel); var funcionarios = await _employeeService.FindAllAsync(); var Description = await _context.Description.Where(x => x.Active == 1).ToListAsync(); var localities = await _context.Locality.Where(x => x.Active == 1).ToListAsync(); var status = await _hourService.FindStatus("horas"); //var funcionarios = await _employeeService.FindAllAsync(); var viewModel = new HourFormViewModel { Hours = horas, Projects = projetos, Clients = clientes, Employees = funcionarios, Description = Description, Locality = localities, Status = status }; return(View(viewModel)); } catch (Exception e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
// GET: Hours/Create public async Task <IActionResult> Create(int?Selectbilling, int?approval, int?description, int?clients, int?projects, int?employees, int?month, int?year) { GetSessions(); if (ViewBag.Email == null) { return(ExpiredSession()); } try { int empId = ViewBag.Id; int accessLevel = ViewBag.AcessLevel; ViewBag.Month = month; ViewBag.Year = year; ViewBag.Billing = Selectbilling; ViewBag.Approval = approval; ViewBag.Description = description; ViewBag.Clients = clients; ViewBag.Projects = projects; ViewBag.Employees = employees; var clientes = await _clientService.FindAllAsync(accessLevel, empId); var projetos = await _projectService.FindAllAsync(accessLevel, empId); var funcionarios = await _employeeService.FindEmployeesActivesAsync(); //var projectsTeam = await _projectTeamService.FindAllAsync(); var descriptions = await _context.Description.Where(x => x.Active == 1).ToListAsync(); var localities = await _context.Locality.Where(x => x.Active == 1).ToListAsync(); //var funcionarios = await _employeeService.FindEmployeesActivesAsync(); var viewModel = new HourFormViewModel { Projects = projetos, Clients = clientes, Employees = funcionarios, Description = descriptions, Locality = localities }; return(View(viewModel)); } catch (Exception e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
public async Task <IActionResult> DetailsModeAdmin(int?id, int Employee_Id, int?Selectbilling, int?approval, int?description, int?clients, int?projects, int?employees, int?month, int?year) { GetSessions(); if (ViewBag.Email == null) { return(ExpiredSession()); } try { int empId = Employee_Id; var accessLevel = ViewBag.AcessLevel; if (id == null) { return(NotFound()); } ViewBag.Month = month; ViewBag.Year = year; ViewBag.Billing = Selectbilling; ViewBag.Approval = approval; ViewBag.Description = description; ViewBag.Clients = clients; ViewBag.Projects = projects; ViewBag.Employees = employees; var hour = await _context.Hour.FindAsync(id); var clientes = await _clientService.FindAllAsync(id, Employee_Id); var projetos = await _projectService.FindProjectAsync(empId, accessLevel); var funcionarios = await _employeeService.FindAllAsync(); var viewModel = new HourFormViewModel { Hour = hour, Projects = projetos, Employees = funcionarios, Clients = clientes }; return(View(viewModel)); } catch (Exception e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
// GET: Hours/Edit/5 public async Task <IActionResult> Edit(int?id, int?approval, int?description, int?clients, int?projects, int?month, int?year) { GetSessions(); if (ViewBag.Email == null) { return(ExpiredSession()); } try { int empId = ViewBag.Id; var accessLevel = ViewBag.AcessLevel; ViewBag.Month = month; ViewBag.Year = year; ViewBag.Approval = approval; ViewBag.Description = description; ViewBag.Clients = clients; ViewBag.Projects = projects; if (id == null) { return(RedirectToAction(nameof(Error), new { message = "Hora não encontrada, informar o suporte" })); } var hour = await _context.Hour.FindAsync(id); var projetos = await _projectService.FindProjecPerEmployeetAsync(empId); var descriptions = await _context.Description.Where(x => x.Active == 1).ToListAsync(); var localities = await _context.Locality.Where(x => x.Active == 1).ToListAsync(); var viewModel = new HourFormViewModel { Hour = hour, Projects = projetos, Description = descriptions, Locality = localities }; return(View(viewModel)); } catch (Exception e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
// GET: Hours/Edit/5 public async Task <IActionResult> Edit(int?id, int Employee_Id) { GetSessions(); if (ViewBag.Email == null) { return(ExpiredSession()); } try { int empId = Employee_Id; var accessLevel = ViewBag.AcessLevel; if (id == null) { return(NotFound()); } var hour = await _context.Hour.FindAsync(id); var clients = await _clientService.FindAllAsync(id, Employee_Id); var projects = await _projectService.FindProjectAsync(empId, accessLevel); var employees = await _employeeService.FindEmployeesAsync(); var description = await _context.Description.Where(x => x.Active == 1).ToListAsync(); var localities = await _context.Locality.Where(x => x.Active == 1).ToListAsync(); var viewModel = new HourFormViewModel { Hour = hour, Projects = projects, Employees = employees, Clients = clients, Description = description, Locality = localities }; return(View(viewModel)); } catch (Exception e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
public async Task <IActionResult> Create(Hour hour, IFormFile Document, int?Selectbilling, int?approval, int?description, int?clients, int?projects, int?employees, int?month, int?year) { GetSessions(); if (ViewBag.Email == null) { return(ExpiredSession()); } try { int empId = ViewBag.Id; int accessLevel = ViewBag.AcessLevel; if (!ModelState.IsValid || _context.Hour.Count(hours => hours.Id_Project == hour.Id_Project && hours.Date == hour.Date && hours.Arrival_Time == hour.Arrival_Time && hours.Exit_Time == hour.Exit_Time) > 0) { var clientes = await _clientService.FindAllAsync(accessLevel, empId); var projetos = await _projectService.FindProjectAsync(empId, accessLevel); var funcionarios = await _employeeService.FindEmployeesActivesAsync(); var localities = await _context.Locality.Where(x => x.Active == 1).ToListAsync(); var viewModel = new HourFormViewModel { Projects = projetos, Employees = funcionarios, Clients = clientes, Locality = localities }; } hour.File = string.Empty; string nomeArquivo = string.Empty; await _hourService.InsertAsync(hour); await _context.SaveChangesAsync(); if (Document != null) { var lastId = (from result in _context.Hour where result.Employee_Id == empId orderby result.Id descending select result).FirstOrDefault(); if (lastId != null) { int hoursId = lastId.Id; nomeArquivo = string.Concat(hoursId, "-", Document.FileName); hour.File = nomeArquivo; _files.EnviarArquivo(Document, nomeArquivo, storage); } _context.Update(hour); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index), new { Selectbilling, approval, description, clients, projects, employees, month, year })); } catch (Exception e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }