public async Task <IActionResult> Edit(ShiftVM shiftModel) { // Check that the data is present if (!ModelState.IsValid || shiftModel.ShiftId == 0) { return(BadRequest()); } // Check that the shift exists Shift shift = await _shiftService.GetShift(shiftModel.ShiftId); if (shift == null) { return(BadRequest()); } // Check that the user has management access string userId = _userManager.GetUserId(User); Member member = await _memberService.GetMember(shift.Location.GroupId, userId); if (member == null || !member.Approved || !member.CanManageShifts) { return(BadRequest()); } shift.Start = shiftModel.Start; shift.End = shiftModel.End; shift.MinParticipants = shiftModel.MinParticipants; shift.MaxParticipants = shiftModel.MaxParticipants; shift.Instructions = shiftModel.Instructions; await _shiftService.EditShift(shift); return(Ok()); }
/// <summary> /// CREATOR: Kaleb Bachert /// CREATED: 2020/4/1 /// APPROVER: Lane Sandburg /// /// This method retrieves all scheduled Shifts with ShiftTimes from the Database by user. /// /// </summary> /// <remarks> /// UPDATER: NA /// UPDATED: NA /// UPDATE: NA /// /// </remarks> public List <ShiftVM> SelectShiftsByUser(int userID) { List <ShiftVM> shiftVMs = new List <ShiftVM>(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_shifts_by_user", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("UserID", userID); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { ShiftVM shiftVM = new ShiftVM(); shiftVM.ShiftID = reader.GetInt32(0); shiftVM.ShiftTimeID = reader.GetInt32(1); shiftVM.Date = reader.GetDateTime(3).ToShortDateString(); shiftVM.EmployeeWorking = reader.GetInt32(4); shiftVM.Department = reader.GetString(6); shiftVM.StartTime = reader.GetString(7); shiftVM.EndTime = reader.GetString(8); shiftVMs.Add(shiftVM); } reader.Close(); } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(shiftVMs); }
/// <summary> /// CREATOR: Kaleb Bachert /// CREATED: 2020/4/15 /// APPROVER: Lane Sandburg /// /// This method retrieves all scheduled Shifts with ShiftTimes from the Database on the specified day. /// </summary> /// <remarks> /// UPDATER: NA /// UPDATED: NA /// UPDATE: NA /// /// </remarks> /// <param name="date"></param> public List <ShiftVM> SelectShiftsByDay(DateTime date) { List <ShiftVM> shiftVMs = new List <ShiftVM>(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_shifts_by_day", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("Date", date.ToShortDateString()); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { ShiftVM shiftVM = new ShiftVM(); shiftVM.EmployeeWorking = reader.GetInt32(0); shiftVM.Date = reader.GetDateTime(1).ToShortDateString(); shiftVM.StartTime = reader.GetString(2); shiftVM.EndTime = reader.GetString(3); shiftVMs.Add(shiftVM); } reader.Close(); } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(shiftVMs); }
public async Task <IActionResult> Create(ShiftVM shiftModel) { // Check that the data is present if (!ModelState.IsValid || shiftModel.LocationId == 0) { return(BadRequest()); } // Check that the location exists Location location = await _locationService.GetLocation(shiftModel.LocationId); if (location == null) { return(BadRequest()); } // Check that the user has management access string userId = _userManager.GetUserId(User); Member member = await _memberService.GetMember(location.GroupId, userId); if (member == null || !member.Approved || !member.CanManageShifts) { return(BadRequest()); } // Make sure the system is not overloaded with shifts if (shiftModel.CreateCopies && shiftModel.CopyUntil.Date >= shiftModel.Start.Date.AddYears(1)) { return(BadRequest()); } var newShifts = new List <Shift>(); newShifts.Add(new Shift() { LocationId = shiftModel.LocationId, Start = shiftModel.Start, End = shiftModel.End, MinParticipants = shiftModel.MinParticipants, MaxParticipants = shiftModel.MaxParticipants, Instructions = shiftModel.Instructions, Enabled = shiftModel.Enabled }); if (shiftModel.CreateCopies) { var totalDays = shiftModel.CopyUntil.Date - shiftModel.Start.Date; for (int day = 1; day <= totalDays.Days; day++) { DayOfWeek newDayOfWeek = shiftModel.Start.AddDays(day).DayOfWeek; if ((newDayOfWeek == DayOfWeek.Monday && shiftModel.CopyMonday) || (newDayOfWeek == DayOfWeek.Tuesday && shiftModel.CopyTuesday) || (newDayOfWeek == DayOfWeek.Wednesday && shiftModel.CopyWednesday) || (newDayOfWeek == DayOfWeek.Thursday && shiftModel.CopyThursday) || (newDayOfWeek == DayOfWeek.Friday && shiftModel.CopyFriday) || (newDayOfWeek == DayOfWeek.Saturday && shiftModel.CopySaturday) || (newDayOfWeek == DayOfWeek.Sunday && shiftModel.CopySunday)) { var newStartDate = shiftModel.Start.AddDays(day); var newEndDate = shiftModel.End.AddDays(day); newShifts.Add(new Shift() { LocationId = shiftModel.LocationId, Start = newStartDate, End = newEndDate, MinParticipants = shiftModel.MinParticipants, MaxParticipants = shiftModel.MaxParticipants, Instructions = shiftModel.Instructions, Enabled = shiftModel.Enabled }); } } } await _shiftService.CreateShifts(newShifts); return(Ok()); }