コード例 #1
0
        public async Task <bool> SendFriendRequestResponse(FriendRequestResponseModel model)
        {
            var toaster = new ToasterSettings("Friend request answering");

            var settings = new HttpSettings($"{this._url}/request", null, null, toaster);

            var body = new HttpBody <FriendRequestResponseModel>(model);

            return(await this._httpService.Update <FriendRequestResponseModel>(settings, body));
        }
コード例 #2
0
        /// <summary>
        /// Send friend request response
        /// Add notification rows
        /// </summary>
        /// <param name="model">Model of response</param>
        public void SendFriendRequestResponse(FriendRequestResponseModel model)
        {
            var user = this._utilsService.GetCurrentUser();

            var request = this._context.FriendRequests.Find(model.RequestId);

            if (request == null)
            {
                throw this._loggerService.LogInvalidThings(user, nameof(FriendService), RequestIdThing,
                                                           RequestDoesNotExistMessage);
            }

            request.Response     = model.Response;
            request.ResponseDate = DateTime.Now;
            this._context.FriendRequests.Update(request);
            this._context.SaveChanges();
            this._loggerService.LogInformation(user, nameof(FriendService), SendFriendRequestResponseAction, request.Id);
            this._notificationService.AddSystemNotificationByType(
                model.Response
                    ? SystemNotificationType.FriendRequestAccepted
                    : SystemNotificationType.FriendRequestDeclined, request.Sender, user.UserName);

            if (model.Response)
            {
                var friend1 = new Friends {
                    RequestId = model.RequestId, UserId = user.Id, FriendId = request.Sender.Id
                };
                this._context.Friends.Add(friend1);

                var friend2 = new Friends {
                    RequestId = model.RequestId, UserId = request.Sender.Id, FriendId = user.Id
                };
                this._context.Friends.Add(friend2);

                this._context.SaveChanges();

                this._notificationService.AddSystemNotificationByType(SystemNotificationType.YouHasANewFriend, user,
                                                                      request.Sender.UserName);
                this._notificationService.AddSystemNotificationByType(SystemNotificationType.YouHasANewFriend,
                                                                      request.Sender, user.UserName);
            }
        }
コード例 #3
0
 public IActionResult SendFriendRequestResponse(FriendRequestResponseModel model)
 {
     this._friendService.SendFriendRequestResponse(model);
     return(this.Ok());
 }