Пример #1
0
        public async Task <ActionResult <MessageDTO> > AddMessage(CreateMessageDTO message)
        {
            var sendUserName = User.GetUserName();

            if (sendUserName == message.RecipientUserName)
            {
                return(BadRequest("Not allowed to send message to yourself"));
            }
            var sender = await _mainRespositories.AppUserRespository.GetUserByUserNameAsync(sendUserName);

            var recipient = await _mainRespositories.AppUserRespository.GetUserByUserNameAsync(message.RecipientUserName);

            if (recipient == null)
            {
                return(NotFound());
            }
            var newMsg = new Message
            {
                SenderId          = sender.Id,
                SenderUserName    = sender.UserName,
                RecipientId       = recipient.Id,
                RecipientUserName = recipient.UserName,
                Content           = message.Content
            };
            await _mainRespositories.MessageRepository.AddMessage(newMsg);

            if (await _mainRespositories.Complete())
            {
                return(Ok(_mapper.Map <MessageDTO>(newMsg)));
            }
            return(BadRequest("Fail to send message"));
        }
Пример #2
0
        public async Task <ActionResult> UpdateUser(UpdateMemberDTO member)
        {
            var user = await _mainRespositories.AppUserRespository.GetUserByUserNameAsync(User.GetUserName());

            _mapper.Map(member, user);
            _mainRespositories.AppUserRespository.Update(user);

            if (await _mainRespositories.Complete())
            {
                return(NoContent());
            }

            return(BadRequest("Fail to update"));
        }
Пример #3
0
        public async Task <ActionResult> AddLike(string username)
        {
            var userId = User.GetUserId();
            var user   = await _mainRepositories.UserLikesRespository.GetUserWithLikes(userId);

            var likedUser = await _mainRepositories.AppUserRespository.GetUserByUserNameAsync(username);

            if (likedUser == null)
            {
                return(NotFound());
            }
            if (likedUser.Id == userId)
            {
                return(BadRequest("You cannot like yourself."));
            }
            if (user.LikedUsers.Any(x => x.likedUserId == likedUser.Id))
            {
                return(BadRequest("Person was liked."));
            }

            var userlikes = new UserLikes
            {
                likedByUserId = userId,
                likedUserId   = likedUser.Id
            };

            user.LikedUsers.Add(userlikes);
            if (!await _mainRepositories.Complete())
            {
                return(BadRequest("Fail to add likes"));
            }
            return(Ok());
        }
Пример #4
0
        public async Task <ActionResult> ApproveMembersPhotos(string[] photoIds)
        {
            var users = await _mainRespository.AppUserRespository.GetUsersAsync();

            var photos = users.SelectMany(x => x.Photos.Where(p => photoIds.Contains(p.Id.ToString())));

            foreach (var photo in photos)
            {
                photo.isApproved = true;
            }
            if (await _mainRespository.Complete())
            {
                return(Ok());
            }

            return(BadRequest("Fail to approve photos."));
        }
Пример #5
0
        public override async Task OnConnectedAsync()
        {
            var username      = Context.User.GetUserName();
            var otherusername = Context.GetHttpContext().Request.Query["user"];
            var groupname     = this.GetGroupName(username, otherusername);
            await Groups.AddToGroupAsync(Context.ConnectionId, groupname);

            var msgGroup = await RecordMsgGroup(groupname);

            var msgThread = await _mainRespositores.MessageRepository.GetMessageThread(username, otherusername);

            await Clients.Caller.SendAsync("AllMessageThread", msgThread);

            if (_mainRespositores.HasChanges())
            {
                await _mainRespositores.Complete();
            }

            await Clients.OthersInGroup(groupname).SendAsync("UpdatedGroup", msgGroup);
        }