Exemplo n.º 1
0
        public override async Task <Response> Handle(Request message, CancellationToken cancellationToken)
        {
            var year  = message.Year ?? DateTime.Today.Year;
            var month = message.Month?.Value != null ? (int)message.Month.Value.Value : DateTime.Today.Month;

            var users = this.dbContext.Users.AsNoTracking();

            if (message.UserIds?.Items?.Count > 0)
            {
                users = users.Where(u => message.UserIds.Items.Contains(u.Id));
            }

            var minDate = DateTimeUtils.StartOfMonth(year, month);
            var maxDate = DateTimeUtils.EndOfMonth(year, month);

            var leaves = await this.dbContext.Leaves
                         .Where(u => u.ScheduledOn >= minDate && u.ScheduledOn <= maxDate)
                         .GroupBy(t => t.CreatedByUserId, u => new CalendarEntry
            {
                Date     = u.ScheduledOn,
                Activity = u.LeaveType.Name,
                Tag      = u.LeaveType.Tag,
                IsLeave  = true
            })
                         .ToListAsync(cancellationToken: cancellationToken);

            var activities = await this.dbContext.Activities
                             .Where(u => u.ScheduledOn >= minDate && u.ScheduledOn <= maxDate)
                             .GroupBy(t => t.CreatedByUserId, u => new CalendarEntry
            {
                Date     = u.ScheduledOn,
                Activity = u.ActivityType.Name,
                Tag      = u.ActivityType.Tag
            })
                             .ToListAsync(cancellationToken: cancellationToken);

            var schedules = users
                            .Select(t => new UserCalendar
            {
                UserId   = t.Id,
                UserName = t.Name,
                Log      = leaves
                           .Where(x => x.Key == t.Id)
                           .Union(activities.Where(u => u.Key == t.Id))
                           .SelectMany(x => x.ToList())
            })
                            .Where(w => w.Log.Any())
                            .ToList();

            return(new Response
            {
                TeamSchedule = new TeamCalendar(year, month, schedules),
                Actions = new ActionList(
                    AddLeave.Button(),
                    AddCompletedActivity.Button(),
                    AddPlannedActivity.Button())
            });
        }
Exemplo n.º 2
0
        protected override Response Handle(Request message)
        {
            var query = this.dbContext.Activities
                        .Include(a => a.ActivityType)
                        .Where(a => a.CreatedByUserId == this.userContext.User.UserId)
                        .AsNoTracking();

            var result = query
                         .OrderBy(t => t.Id)
                         .Paginate(t => new Item(t, this.activityPermissionManager.CanDo(ActivityAction.Edit, this.userContext, t)), message.Paginator);

            return(new Response
            {
                Users = result,
                Actions = this.permissionManager.CanDo(CoreActions.ViewActivities, this.userContext)
                                        ? new ActionList(AddCompletedActivity.Button(), AddPlannedActivity.Button())
                                        : null
            });
        }