Ejemplo n.º 1
0
        public IActionResult Details([FromRoute] string eventId)
        {
            if (eventId == null)
            {
                throw new ArgumentNullException(nameof(eventId));
            }
            var parsedId = TryParseObjectId(eventId);

            if (!parsedId.HasValue)
            {
                return(RedirectToAction("Index"));
            }
            var e     = eventRepository.GetEvent(parsedId.Value);
            var users = eventRepository.GetUsersForEvent(e.Id);

            return(View(new EventViewModel
            {
                Id = e.Id.ToString(),
                Name = e.Name,
                Description = e.Description,
                Private = e.Private,
                Finished = e.Finished,
                StartTime = e.StartTime.ToUserTime(User),
                EndTime = e.EndTime?.ToUserTime(User),
                Accepted = invitationRepository.CountAccepted(parsedId.Value),
                Invited = invitationRepository.CountInvited(parsedId.Value),
                OwnerId = e.OwnerId.ToString(),
                UserIds = users,
                UserEventData = e.UserEventData
            }));
        }
Ejemplo n.º 2
0
        public IActionResult GetUserEvents([FromQuery] int skip = 0, [FromQuery] int take = 10)
        {
            var events = eventRepository.GetEventsForUser(User.Identity.GetUserId(), skip, take);
            var users  = userRepository.GetUsersByIds(events.SelectMany(e => e.UserEventData).Select(e => e.UserId)
                                                      .ToList());
            var result = events.Select(e =>
            {
                var owner = userRepository.GetById(e.OwnerId);
                return(new MobileEventViewModel
                {
                    OwnerName = owner.FirstName + " " + owner.LastName,
                    Id = e.Id.ToString(),
                    Name = e.Name,
                    Description = e.Description,
                    Private = e.Private,
                    Finished = e.Finished,
                    StartTime = e.StartTime.ToUserTime(User).ToString("f"),
                    EndTime = e.EndTime?.ToUserTime(User).ToString("f"),
                    Accepted = invitationRepository.CountAccepted(e.Id),
                    Invited = invitationRepository.CountInvited(e.Id),
                    OwnerId = e.OwnerId.ToString(),
                    UserEventData = e.UserEventData.Select(f =>
                                                           new MobileUserEventData
                    {
                        UserId = f.UserId.ToString(),
                        Meters = f.Meters,
                        DurationSeconds = (long)f.Duration.TotalSeconds,
                        UserName = users.First(e => e.Id == f.UserId).FirstName + " " +
                                   users.First(e => e.Id == f.UserId).LastName
                    }
                                                           ).ToList()
                });
            }).ToList();

            return(Ok(result));
        }