Example #1
0
        public async Task <IActionResult> GetList([FromQuery] PaginationFilterDto paginationDto)
        {
            var pagination = _mapper.Map <Pagination>(paginationDto);

            var(municipalities, totalCount) = await _municipalityService.GetMunicipalities(pagination);

            var vws = _mapper.Map <List <MunicipalityApiVw> >(municipalities);

            var route    = Request.Path.Value;
            var responce = PaginationHelper.CreatePagedReponse <MunicipalityApiVw>(vws, pagination, totalCount, _uriService, route);

            return(Ok(responce));
        }
Example #2
0
        public async Task <ICollection <GetMessageDto> > GetAllMessagesForChat(int chatId, string userId, PaginationFilterDto pagination)
        {
            var chat = await _unitOfWork.ChatRepository.GetChatByIdWithAllIncludes(chatId);

            if (chat == null)
            {
                throw new ArgumentException("This chat doesn't exist");
            }

            if (ChatContainUser(userId, chat).Value)
            {
                var chatMessageList = chat.ChatMessages.OrderBy(chm => chm.DateSend).ToList();
                List <GetMessageDto> getMessagesDto = new List <GetMessageDto>();
                foreach (var chatMessage in chatMessageList)
                {
                    if (chatMessage.Message.DeletedForAll || (chatMessage.Message.DeletedForSender && chatMessage.Message.SenderId == userId))
                    {
                        continue;
                    }
                    var messageDTO = _mapper.Map <GetMessageDto>(chatMessage.Message);
                    messageDTO.SendDate = chatMessage.DateSend;
                    getMessagesDto.Add(messageDTO);
                }
                getMessagesDto = getMessagesDto.OrderBy(m => m.SendDate)
                                 .Skip((pagination.PageNo - 1) * pagination.Limit)
                                 .Take(pagination.Limit)
                                 .ToList();
                return(getMessagesDto);
            }
            else
            {
                throw new ArgumentException("You can't do this action");
            }
        }
Example #3
0
        public async Task <ActionResult <ICollection <GetMessageDto> > > GetMessagesForChat(int ChatId, [FromQuery] PaginationFilterDto pagination)
        {
            try
            {
                var userId = this.User.Claims.First(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").Value;

                return(Ok(await _messagesService.GetAllMessagesForChat(ChatId, userId, pagination)));
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }