public async Task <IActionResult> Create([Bind("Id,Email,Pass,ConfirmPass,EmployeeId")] Login login)
        {
            Login foundLogin = _context.Login.FirstOrDefault(l => l.Email == login.Email);

            if (foundLogin == null)
            {
                _context.Add(login);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetInt32("UserLoggedIn", 1);

                var employeeWithEmail = await _context.Employee.FirstOrDefaultAsync(e => e.Email == login.Email);

                if (employeeWithEmail == null)
                {
                    return(RedirectToAction("RegistrationUnfinished", "Home"));
                }
                else
                {
                    login.EmployeeId = employeeWithEmail.Id;
                    _context.Update(login);
                    await _context.SaveChangesAsync();
                }

                HttpContext.Session.SetInt32("LoggedInEmployeeID", employeeWithEmail.Id);

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                TempData["ErrorMessage"] = "Email has already been registered.";
            }
            return(View(login));
        }
        public async Task <IActionResult> ChangeStatus(string submit, [Bind("Id,EmployeeId,Created,Day,Message,Approved")] Timeoffrequest timeoffrequest)
        {
            try
            {
                switch (submit)
                {
                case "Approve":
                    timeoffrequest.Approved = true;
                    break;

                case "Deny":
                    timeoffrequest.Approved = false;
                    break;
                }
                _context.Update(timeoffrequest);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TimeoffrequestExists(timeoffrequest.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("Id,PrivelegesId,CompanyId,FirstName,LastName,EmployeeNumber,Email,Wages")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                var employeeFound = await _context.Employee.Include(e => e.Priveleges)
                                    .FirstOrDefaultAsync(e => e.Id == HttpContext.Session.GetInt32("LoggedInEmployeeID"));

                employee.CompanyId = employeeFound.CompanyId;
                _context.Add(employee);
                await _context.SaveChangesAsync();

                var loginFound = await _context.Login.FirstOrDefaultAsync(l => l.Email == employee.Email);

                if (loginFound != null)
                {
                    loginFound.EmployeeId = employee.Id;
                    _context.Update(loginFound);
                    await _context.SaveChangesAsync();
                }


                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PrivelegesId"] = new SelectList(_context.Priveleges, "Id", "Name", employee.Priveleges);
            return(View(employee));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,CompanyNumber")] Company company)
        {
            if (ModelState.IsValid)
            {
                _context.Add(company);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(company));
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Department department)
        {
            if (ModelState.IsValid)
            {
                _context.Add(department);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(department));
        }
        public async Task <IActionResult> Create([Bind("Id,PrivelegesId,CompanyId,FirstName,LastName,EmployeeNumber,Email,Wages")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CompanyId"]    = new SelectList(_context.Company, "Id", "Id", employee.CompanyId);
            ViewData["PrivelegesId"] = new SelectList(_context.Priveleges, "Id", "Id", employee.PrivelegesId);
            return(View(employee));
        }
示例#7
0
        public async Task <IActionResult> Create([Bind("ScheduleId,EmployeeId,Start,End")] EmployeeSchedule employeeSchedule)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employeeSchedule);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EmployeeId"] = new SelectList(_context.Employee, "Id", "EmployeeNumber", employeeSchedule.EmployeeId);
            ViewData["ScheduleId"] = new SelectList(_context.Schedule, "Id", "Id", employeeSchedule.ScheduleId);
            return(View(employeeSchedule));
        }
示例#8
0
        public async Task <IActionResult> Create([Bind("Id,Week,DepartmentId")] Schedule schedule)
        {
            var scheduleExists = _context.Schedule.Any(s => s.Week == schedule.Week && s.DepartmentId == schedule.DepartmentId);

            if (!scheduleExists)
            {
                if (ModelState.IsValid)
                {
                    _context.Add(schedule);
                    await _context.SaveChangesAsync();
                }
            }
            else
            {
                schedule = _context.Schedule.FirstOrDefault(s => s.Week == schedule.Week && s.DepartmentId == schedule.DepartmentId);
            }
            HttpContext.Session.SetString("scheduleId", schedule.Id.ToString());
            return(RedirectToAction("index", "EmployeeSchedule"));
        }
        public async Task <IActionResult> Create([Bind("Id,EmployeeId,ScheduleId,Day,Start,End")] Shift shift)
        {
            if (ModelState.IsValid)
            {
                TimeSpan starttime = shift.Start.Value.TimeOfDay;
                TimeSpan endtime   = shift.End.Value.TimeOfDay;
                shift.Start = shift.Day.Value;
                shift.Start = shift.Start.Value + starttime;
                shift.End   = shift.Day.Value;
                shift.End   = shift.End.Value + endtime;
                _context.Add(shift);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            var employeeLoggedIn = _context.Employee.FirstOrDefault(e => e.Id == HttpContext.Session.GetInt32("LoggedInEmployeeID"));

            ViewData["EmployeeId"] = new SelectList(_context.Employee.Where(s => s.CompanyId == employeeLoggedIn.CompanyId), "Id", "FullName", shift.EmployeeId);
            ViewData["ScheduleId"] = new SelectList(_context.Schedule.Include(s => s.Department).Where(s => s.CompanyId == employeeLoggedIn.CompanyId), "Id", "StartEnd", shift.ScheduleId);
            return(View(shift));
        }
示例#10
0
        public async Task <IActionResult> Create([Bind("Start,End,DepartmentId")] Schedule schedule)
        {
            var scheduleExists = _context.Schedule.Include(s => s.Department).Any(s => s.Start == schedule.Start && s.End == schedule.End && s.DepartmentId == schedule.DepartmentId);

            if (!scheduleExists)
            {
                if (ModelState.IsValid)
                {
                    var employeeLoggedIn = _context.Employee.FirstOrDefault(e => e.Id == HttpContext.Session.GetInt32("LoggedInEmployeeID"));
                    schedule.CompanyId = employeeLoggedIn.CompanyId;
                    _context.Add(schedule);
                    await _context.SaveChangesAsync();
                }
            }
            else
            {
                TempData["ErrorMessage"] = "A schedule for that department during that week has already been created.";
                var employeeLoggedIn = _context.Employee.FirstOrDefault(e => e.Id == HttpContext.Session.GetInt32("LoggedInEmployeeID"));
                ViewData["DepartmentId"] = new SelectList(_context.Department.Where(d => d.CompanyId == employeeLoggedIn.CompanyId), "Id", "Name");
                return(View(schedule));
            }
            HttpContext.Session.SetInt32("scheduleId", schedule.Id);
            return(RedirectToAction("Create", "Shifts"));
        }