Ejemplo n.º 1
0
        public IActionResult Get(int groupId)
        {
            var user  = User.Identity.Name;
            var group = _repository.GetGroupById(groupId, user);

            if (group != null)
            {
                return(Ok(_mapper.Map <IEnumerable <Meeting>, IEnumerable <MeetingViewModel> >(group.Meetings)));
            }

            return(NotFound());
        }
Ejemplo n.º 2
0
        public IActionResult Post([FromBody] GroupMemberViewModel groupMemberViewModel)
        {
            try
            {
                var group = _repository.GetGroupById(groupMemberViewModel.GroupId);
                if (group == null)
                {
                    return(BadRequest($"Group does not exist. [id={groupMemberViewModel.GroupId}]"));
                }

                var user = _repository.GetUser(groupMemberViewModel.Member.UserName);
                if (user == null)
                {
                    return(BadRequest($"User not found. [user={groupMemberViewModel.Member.UserName}]"));
                }

                foreach (var member in group.Members)
                {
                    if (member.MemberId.Equals(user.Id))
                    {
                        return(BadRequest($"User already in group. [user={user.Id}]"));
                    }
                }

                var groupMember = _mapper.Map <GroupMemberViewModel, GroupMember>(groupMemberViewModel);

                group.Members.Add(groupMember);
                user.Memberships.Add(groupMember);

                if (_repository.SaveAll())
                {
                    return(Ok());
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to save group membership changes. [ex={ex}]");

                throw;
            }

            return(BadRequest("Failed to save group membership changes."));
        }
Ejemplo n.º 3
0
        public IActionResult Get(int id)
        {
            try
            {
                var user  = User.Identity.Name;
                var group = _repository.GetGroupById(id, user);

                if (group != null)
                {
                    return(Ok(_mapper.Map <Group, GroupViewModel>(group)));
                }

                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to get groups. Exception={ex}");
                return(BadRequest($"Failed to get groups. {ex.Message}"));
            }
        }