// GET: Shift // Shift/Index public ActionResult Index() { ShiftService service = CreateShiftService(); var model = service.GetShifts(); return(View(model)); }
public async Task <IActionResult> View(int?locationId, DateTime selectedDate, int?shiftId) { string userId = _userManager.GetUserId(User); Member member = null; List <Shift> shifts = new List <Shift>(); // Load shifts in requested location if there is access if (locationId.HasValue) { if (await _userService.HasLocationAccess(userId, locationId.Value)) { Location location = await _locationService.GetLocation(locationId.Value); member = await _memberService.GetMember(location.GroupId, userId); shifts = await _shiftService.GetShifts(location.Id, selectedDate, member.CanManageShifts); } else { return(BadRequest()); } } // Load requested shift if there is access Shift singleShift; if (shiftId.HasValue) { if (await _userService.HasShiftAccess(userId, shiftId.Value)) { singleShift = await _shiftService.GetShift(shiftId.Value); member = await _memberService.GetMember(singleShift.Location.GroupId, userId); if (!singleShift.Enabled && !member.CanManageShifts) { return(BadRequest()); } else { shifts.Add(singleShift); } } else { return(BadRequest()); } } // Sort participants foreach (Shift shift in shifts) { shift.Participants = shift.Participants.OrderBy(p => p.Member.User.FullName).ToList(); } ViewBag.ShowManageButton = member.CanManageShifts; return(PartialView("_ShiftsPartial", shifts)); }
protected override void OnInitialized() { try { var shiftResult = ShiftService.GetShifts(); if (shiftResult.Successful) { shifts = shiftResult.Data; shifts.RemoveAll(s => s == null); var positionResult = _positionService.GetPositions(); if (positionResult.Successful) { positions = positionResult.Data; var membersResult = _minimalService.GetMinimalMembers(); if (membersResult.Successful) { members = membersResult.Data; } else { error = positionResult.Error; } } else { error = positionResult.Error; } } else { error = shiftResult.Error; } } catch (Exception ex) { Console.WriteLine(ex.Message + "\n\n" + ex.StackTrace); } }