Beispiel #1
0
        public async Task <ActionResult <MemberDTO> > Create(Guid channelId, [FromBody] CreateMemberDTO model)
        {
            //1)Channel laden via de channelrepository op basis van de channelId
            var channel = channelRepository.GetById(channelId);
            //2) valideren dat de currentUser de juiste rechten / rol heeft om een member toetevoegen via getCurrentUserAsync zit hij er niet in stuur Acces Denied terug
            //3) De rollen nakijken, zijn rol opvragen. Huidige rol van de user moet kleiner of groter zijn anders Acces Denied terug.
            //4)Indien true, member.FromCreateMemberDTO(channel,model);


            var member = uMessageAPI.Models.Member.FromCreateMemberDTO(channel, model);

            // Check whether the current channel was resolved.
            if (member.ChannelId == channelId)
            {
                // Create message and assign a name.
                memberRepository.Add(member);
                memberRepository.SaveChanges();
            }
            // Check whether the channel was successfully created.
            if (member != null)
            {
                // Generate the channel response for given channel.
                return(Ok(MemberDTO.FromMember(member)));
            }

            return(NotFound());
        }
Beispiel #2
0
 public static Member FromCreateMemberDTO(Channel channel, CreateMemberDTO model)
 {
     return(new Member {
         Channel = channel, UserId = model.UserId, Role = model.Role, ChannelId = model.ChannelId
     });
 }