Esempio n. 1
0
        public void SendRequests_GivenSelfInvitation_ReturnsFalse()
        {
            // Arrange
            var model = new RelationModel
            {
                InvitingUser = new UserModel {
                    Id = _john.Id, UserName = _john.UserName
                },
                InvitedUser = new UserModel {
                    Id = _john.Id, UserName = _john.UserName
                }
            };

            // Act
            var result = _relationService.SendRequest(model);

            // Assert
            Assert.IsFalse(result);
        }
        public IActionResult Send([FromBody] RelationWebModel webModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var invitingUser = _userService.GetByUserName(webModel.InvitingUserName);

            if (invitingUser == null)
            {
                return(BadRequest());
            }

            var invitedUser = _userService.GetByUserName(webModel.InvitedUserName);

            if (invitedUser == null)
            {
                return(BadRequest());
            }

            var model = new RelationModel
            {
                RelationStatus = RelationStatus.Pending,
                InvitingUser   = invitingUser,
                InvitedUser    = invitedUser
            };

            var isSuccess = _relationService.SendRequest(model);

            if (!isSuccess)
            {
                return(BadRequest());
            }

            return(new OkObjectResult(JsonConvert.SerializeObject("Relation request sent.")));
        }