Ejemplo n.º 1
0
        public IActionResult Get()
        {
            try
            {
                var invitations      = _repo.GetAllInvitations();
                var invitationModels = new List <InvitationModel>();

                for (int i = 0; i < invitations.Count(); i++)
                {
                    var inv = invitations.ElementAt(i);

                    var id         = inv.Id;
                    var invitee    = GetUserModel(inv.InviteeId);
                    var inviter    = GetUserModel(inv.InviterId);
                    var eventModel = GetEventModel(inv.EventId);
                    var message    = inv.Message;

                    InvitationModel model = new InvitationModel
                    {
                        Id      = id,
                        Invitee = invitee,
                        Inviter = inviter,
                        Event   = eventModel,
                        Message = message
                    };

                    invitationModels.Add(model);
                }

                return(Ok(invitationModels));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Threw exception while fetching users: {ex}");
            }

            return(BadRequest("Could not fetch users"));
        }