public HttpResponseMessage RequestFriend(NotificationDto postData)
        {
            var success = false;

            try
            {
                var notify = NotificationsController.Instance.GetNotification(postData.NotificationId);
                ParseInviteNotificationKey(notify.Context);

                _inviteRepo = new InviteRepository();
                var oInvitation = _inviteRepo.GetInvite(_inviteid);

                if (oInvitation != null)
                {
                    // Add friend of new user to invite user
                    UserInfo inviteUser = UserController.GetUserById(oInvitation.PortalId, oInvitation.InvitedByUserId);
                    if (inviteUser != null)
                    {
                        UserInfo recipientUser = UserController.GetUserById(oInvitation.PortalId, oInvitation.RecipientUserId);
                        FriendsController.Instance.AddFriend(inviteUser, recipientUser);
                    }
                    success = true;
                    NotificationsController.Instance.DeleteNotification(postData.NotificationId);
                }
            }
            catch (Exception exc)
            {
                DotNetNuke.Services.Exceptions.Exceptions.LogException(exc);
            }

            return(success ? Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }) : Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification"));
        }
Exemple #2
0
        public async Task <IActionResult> AgreeInvite(int id)
        {
            var userId = int.Parse(User.GetName());
            var invite = await _inviteRepository.GetInvite(id);

            if (invite == null)
            {
                return(BadRequest(new { message = "Попытка согласиться на задачу, для которой нет приглашения." }));
            }

            if (invite.IdPerformer != userId)
            {
                return(BadRequest(new { message = "Попытка согласиться на задачу для другого исполнителя." }));
            }

            var task = await _taskRepository.GetTask(id);

            task.IdPerformer = userId;
            await _taskRepository.UpdateTask(task);

            await _inviteRepository.DeleteInvite(invite);

            return(Ok());
        }