public async Task <object> Register([FromBody] RegisterEmployeeVM model) { var token = Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); if (!PatManagerVerify.CheckIfManager(token, context)) { //if the user isn't a manager then quit the method. Only managers are able to hire new people return(null); } var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { //add the user to the role of employee straight after being added by the manager UserRoleRepo repo = new UserRoleRepo(service); await repo.AddUserRole(model.Email, "employee"); //now add the user details UserRepo userRepo = new UserRepo(context, service); userRepo.AddUserDetails(user.Id, model.FirstName, model.LastName); //The user is never signed in when they are registered. As they are only ever registered through the manager //creating the new user //await signInManager.SignInAsync(user, false); return(await GenerateJwtToken(model.Email, user)); } throw new ApplicationException("UNKNOWN_ERROR"); }
public void DeleteUser([FromBody] EmployeeIdVM employee) { var token = Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); if (PatManagerVerify.CheckIfManager(token, context)) { UserRepo repo = new UserRepo(context, service); repo.DeleteUser(employee.Email); } }
public void PostSchedule([FromBody] List <EmployeeShiftVM> shifts) { // For more detail and better encapsulation (in a service see day 6 OnAuthorization()) //This is our check to determine whether or not our user is a manager or not var token = Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); if (PatManagerVerify.CheckIfManager(token, context)) { ScheduleRepo sRepo = new ScheduleRepo(context); sRepo.AddScheduleItems(shifts); } }
public void DeleteShift([FromBody] ShiftIdVM shiftId) { var token = Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); if (!PatManagerVerify.CheckIfManager(token, context)) { //if the user isn't a manager then quit the method. Only managers are able to hire new people return; } //var query = context.Schedule.Where(s => s.ShiftId == shiftId.shiftId).FirstOrDefault(); var query = (from s in context.Schedule where s.ShiftId == shiftId.ShiftId select s).First(); context.Schedule.Remove(query); context.SaveChanges(); }
public void DeleteAllShifts() { var token = Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); if (!PatManagerVerify.CheckIfManager(token, context)) { //if the user isn't a manager then quit the method. return; } var query = context.Schedule; foreach (var q in query) { context.Schedule.Remove(q); } context.SaveChanges(); }
public void DeleteShiftDay([FromBody] DayShiftVM day) { var token = Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); if (!PatManagerVerify.CheckIfManager(token, context)) { //if the user isn't a manager then quit the method. return; } var query = (from s in context.Schedule where s.Week == day.Week && s.Day == day.Day select s); foreach (var q in query) { context.Schedule.Remove(q); } context.SaveChanges(); }