Ejemplo n.º 1
0
        public async Task <IActionResult> CompleteWorkItem(CompleteWorkItemDto dto)
        {
            var workItem = (await _workItemRepository.GetWorkItems(_clock.UtcNow.UtcDateTime, User.UserId(), workItemId: dto.Id)).Single();

            if (workItem.CompletedAt.HasValue || workItem.CanceledAt.HasValue)
            {
                return(Problem("Work item is already complete"));
            }
            else if (User.IsInPatrol(workItem.PatrolId))
            {
                if (workItem.CanComplete || workItem.CanAdmin || User.RoleInPatrol(workItem.PatrolId).CanMaintainWorkItems())
                {
                    //normal user completion
                    if (workItem.CanComplete && !dto.ForUserId.HasValue)
                    {
                        await _workItemService.CompleteWorkItem(dto.Id, User.UserId(), dto.WorkNotes);
                    }
                    //admin force completion
                    else if ((workItem.CanAdmin || User.RoleInPatrol(workItem.PatrolId).CanMaintainWorkItems()) &&
                             !dto.ForUserId.HasValue)
                    {
                        await _workItemService.CompleteWorkItem(dto.Id, User.UserId(), dto.WorkNotes, force : true);
                    }
                    //admin proxy completion
                    else if ((workItem.CanAdmin || User.RoleInPatrol(workItem.PatrolId).CanMaintainWorkItems()) &&
                             dto.ForUserId.HasValue && (workItem.CompletionMode == CompletionMode.Any || workItem.Assignments.Any(y => y.UserId == dto.ForUserId.Value)))
                    {
                        await _workItemService.CompleteWorkItem(dto.Id, User.UserId(), dto.WorkNotes, dto.ForUserId.Value);
                    }
                    //admin force proxy completion
                    else if ((workItem.CanAdmin || User.RoleInPatrol(workItem.PatrolId).CanMaintainWorkItems()) &&
                             dto.ForUserId.HasValue && workItem.Assignments.Any(y => y.UserId == dto.ForUserId.Value))
                    {
                        await _workItemService.CompleteWorkItem(dto.Id, User.UserId(), dto.WorkNotes, dto.ForUserId.Value, true);
                    }
                    else
                    {
                        throw new InvalidOperationException("Invalid completion paramaters");
                    }
                    return(Ok());
                }
                else
                {
                    return(Forbid());
                }
            }
            else
            {
                return(Forbid());
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <IEnumerable <WorkItemDto> > > GetWorkItems(Guid iterationId)
        {
            var workitems = await _workItemRepository.GetWorkItems(iterationId);

            var result = _mapper.Map <IEnumerable <WorkItemDto> >(workitems);

            return(Ok(result));
        }
Ejemplo n.º 3
0
        public async Task <object> GetAllWorkItems()
        {
            var workitems = await _workItemRepository.GetWorkItems();

            var iterations = await _iterationRepository.GetIterationsAsync();

            var result = from i in iterations
                         join wi in workitems on i.Id equals wi.IterationId
                         select new
            {
                Id           = wi.Id,
                Title        = wi.Title,
                Description  = wi.Description,
                Iteration    = i.Title,
                IterationId  = i.Id,
                Created      = wi.Created,
                Priority     = wi.Priority,
                State        = wi.State,
                LastModified = wi.LastModified.Value,
            };

            return(result.ToList());
        }
Ejemplo n.º 4
0
        public async Task PopulateShiftWorkItemOccurences(RecurringWorkItemDto recurringWorkItem, DateTime now, int userId, Models.Patrol patrol, bool populateWorkitemAssignments = true)
        {
            var shifts = await _workItemRepository.GetShiftRecurringWorkItems(recurringWorkItem.Id);

            var workItems = await _workItemRepository.GetWorkItems(recurringWorkItem.Id, now);

            var allScheduledShiftAssignments = new List <ScheduledShiftAssignmentDto>();

            foreach (var shift in shifts)
            {
                var scheduledShiftAssignments = await _shiftRepository.GetScheduledShiftAssignments(recurringWorkItem.PatrolId, from : now, shiftId : shift.ShiftId);

                allScheduledShiftAssignments.AddRange(scheduledShiftAssignments);

                var scheduledShifts = scheduledShiftAssignments.GroupBy(x => x.ScheduledShiftId);

                foreach (var scheduledShift in scheduledShifts)
                {
                    var shiftWorkItems  = workItems.Where(x => x.ScheduledShiftId == scheduledShift.Key);
                    var shiftStartLocal = scheduledShift.First().StartsAt.UtcToPatrolLocal(patrol);

                    if (!shiftWorkItems.Any())
                    {
                        //create the work item
                        var workItem = new WorkItem()
                        {
                            AdminGroupId      = recurringWorkItem.AdminGroupId,
                            CreatedAt         = now,
                            CreatedByUserId   = userId,
                            CompletionMode    = recurringWorkItem.CompletionMode,
                            DescriptionMarkup = recurringWorkItem.DescriptionMarkup,
                            Location          = recurringWorkItem.Location,
                            Name                = recurringWorkItem.Name,
                            PatrolId            = recurringWorkItem.PatrolId,
                            RecurringWorkItemId = recurringWorkItem.Id,
                            ScheduledShiftId    = scheduledShift.Key,
                            ScheduledAt         = new DateTime(shiftStartLocal.Year, shiftStartLocal.Month, shiftStartLocal.Day, shift.ScheduledAtHour, shift.ScheduledAtMinute, 0).UtcFromPatrolLocal(patrol)
                        };
                        await _workItemRepository.InsertWorkItem(workItem);
                    }
                    else
                    {
                        //realistically should only ever be 1
                        foreach (var workItem in shiftWorkItems)
                        {
                            if (!workItem.CompletedAt.HasValue && !workItem.CanceledAt.HasValue)
                            {
                                workItem.CompletionMode    = recurringWorkItem.CompletionMode;
                                workItem.DescriptionMarkup = recurringWorkItem.DescriptionMarkup;
                                workItem.Location          = recurringWorkItem.Location;
                                workItem.Name         = recurringWorkItem.Name;
                                workItem.ScheduledAt  = new DateTime(shiftStartLocal.Year, shiftStartLocal.Month, shiftStartLocal.Day, shift.ScheduledAtHour, shift.ScheduledAtMinute, 0).UtcFromPatrolLocal(patrol);
                                workItem.AdminGroupId = recurringWorkItem.AdminGroupId;
                                await _workItemRepository.UpdateWorkItem(workItem);
                            }
                        }
                    }
                }
            }

            if (populateWorkitemAssignments)
            {
                await RecalculateShiftWorkItemAssignments(allScheduledShiftAssignments);
            }
        }
 public IEnumerable <WorkItem> GetWorkItems(string path)
 {
     return(_workItemRepsitory.GetWorkItems(path));
 }
Ejemplo n.º 6
0
        public async Task <IActionResult> Index()
        {
            var items = await repo.GetWorkItems();

            return(View(Mappers.Map(items)));
        }