Exemplo n.º 1
0
        public OkObjectResult NewEnsemble([FromBody] EnsembleDto dto)
        {
            var userId = GetUserId();

            var ensemble = new Ensemble
            {
                Name = dto.Name
            };

            _context.Ensembles.Add(ensemble);

            // Make ensemble creator Mod
            var mod = new EnsembleModerator
            {
                UserIdRecipient = userId,
                UserIdRequester = userId,
                EnsembleId      = ensemble.EnsembleId,
                Status          = RequestStatus.Accepted,
                ConfirmedAt     = DateTime.Now
            };

            _context.EnsembleModerators.Add(mod);
            // Make ensemble creator Member
            var mem = new EnsembleMember
            {
                EnsembleId      = ensemble.EnsembleId,
                UserIdRecipient = userId,
                UserIdRequester = userId,
                Status          = RequestStatus.Accepted,
                ConfirmedAt     = DateTime.Now
            };

            _context.EnsembleMembers.Add(mem);

            _context.SaveChanges();

            return(new OkObjectResult(new { success = true, ensembleId = ensemble.EnsembleId }));
        }
Exemplo n.º 2
0
        public OkObjectResult GetEnsemblePage([FromBody] EnsembleDto dto)
        {
            var userId = GetUserId();

            var ensMems = _context.EnsembleMembers
                          .Where(em => em.EnsembleId == dto.EnsembleId &&
                                 em.Status == RequestStatus.Accepted)
                          .Select(em => em.UserIdRecipient).ToArray();

            var ensMods = _context.EnsembleModerators
                          .Where(em => em.EnsembleId == dto.EnsembleId &&
                                 em.Status == RequestStatus.Accepted)
                          .Select(em => em.UserIdRecipient).ToArray();

            var validMem = ensMems.Contains(userId);
            var validMod = ensMods.Contains(userId);

            if (!(validMem || validMod))
            {
                return(new OkObjectResult(new { success = false, error = "Not valid member or mod" }));
            }

            var events = _context.Bookings
                         .Include(b => b.Event)
                         .Where(b => b.EnsembleId == dto.EnsembleId && b.Status == RequestStatus.Accepted)
                         .Select(b => new EnsembleBookingDto
            {
                EventName     = b.Event.Name,
                EventLocation = b.Event.Location,
                DateAndTime   = b.Event.DateAndTime,
                BookingId     = b.BookingId,
                Setlist       = b.Setlist,
                UserIsMod     = validMod
            }).ToList() as ICollection <EnsembleBookingDto>;

            var userConnectionIds = GetUserConnections(userId);

            var comments = _context.EnsembleComments
                           .Where(ec => ec.EnsembleId == dto.EnsembleId)
                           .OrderByDescending(ec => ec.Timestamp)
                           .Select(ec => new EnsembleCommentDto
            {
                EnsembleId = ec.EnsembleCommentId,
                Text       = ec.Text,
                Timestamp  = ec.Timestamp,
                User       = new MemberDto
                {
                    FullName        = ec.User.FullName,
                    PhotoUrl        = ec.User.PhotoUrl,
                    UserId          = ec.UserId,
                    ConnectedToUser = userConnectionIds.Contains(ec.User.UserId)
                }
            })
                           .ToList() as ICollection <EnsembleCommentDto>;

            var members = _context.EnsembleMembers
                          .Where(e => e.EnsembleId == dto.EnsembleId && e.Status == RequestStatus.Accepted)
                          .Select(e => new MemberDto
            {
                FullName        = e.UserRecipient.FullName,
                PhotoUrl        = e.UserRecipient.PhotoUrl,
                UserId          = e.UserRecipient.UserId,
                ConnectedToUser = userConnectionIds.Contains(e.UserIdRecipient),
                MemberSince     = e.ConfirmedAt
            }).ToList() as ICollection <MemberDto>;

            var ensemble = _context.Ensembles
                           .Select(e => new EnsembleDto
            {
                EnsembleId   = e.EnsembleId,
                Name         = e.Name,
                Members      = members,
                Comments     = comments,
                Performances = events,
                UserIsMod    = validMod
            })
                           .FirstOrDefault(e => e.EnsembleId == dto.EnsembleId);

            return(new OkObjectResult(new
            {
                success = true,
                ensemble
            }));
        }