Exemple #1
0
        public async Task <Message> CreateAsync(Message dto, Action <string, string> AddErrorMessage)
        {
            ApplicationUser user = await _userManager.GetUserAsync(_httpContextAccessor.HttpContext.User);

            if (user == null)
            {
                AddErrorMessage?.Invoke("General", "Only Logged-in user can perform this operation");
                return(null);
            }

            MessageEntity entity   = _mappingService.DtoToEntity(dto);
            Chatroom      chatroom = await _chatroomService.GetAsync(entity.ChatroomID);

            if (user.Id != chatroom.OwnerID)
            {
                AddErrorMessage?.Invoke("General", "Only Owner of a Chatroom can add participants!");
                return(null);
            }

            MessageEntity createdEntity = await _repository.CreateAsync(entity);

            if (createdEntity != null)
            {
                await _context.SaveChangesAsync();
            }

            createdEntity = await _repository.GetCompleteAsync(createdEntity.ID);

            return(_mappingService.EntityToDto(createdEntity));
        }
Exemple #2
0
        public async Task <Participant> CreateAsync(Participant dto, ApplicationUser user, Action <string, string> AddErrorMessage)
        {
            if (user == null)
            {
                AddErrorMessage?.Invoke("General", "Only Logged-in user can perform this operation");
                return(null);
            }

            ParticipantEntity entity   = _mappingService.DtoToEntity(dto);
            Chatroom          chatroom = await _chatroomService.GetAsync(entity.ChatroomID);

            if (user.Id != chatroom.OwnerID)
            {
                AddErrorMessage?.Invoke("General", "Only Owner of a Chatroom can add participants!");
                return(null);
            }

            ParticipantEntity createdEntity = await _repository.CreateAsync(entity);

            if (createdEntity != null)
            {
                await _context.SaveChangesAsync();
            }

            createdEntity = await _repository.GetCompleteAsync(createdEntity.ID);

            Participant created = _mappingService.EntityToDto(createdEntity);

            created.Deletable = true;
            return(created);
        }
Exemple #3
0
 public async Task <Chatroom> Get(int id)
 {
     // 200(OK) if found an id
     // 204(No Content) if there is no such id
     return(await _chatroomService.GetAsync(id));
 }