コード例 #1
0
        public async Task <IActionResult> Add([FromBody] AddInvitationRequest request, [FromRoute] int accountId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var response = await _invitationService.AddAsync(request, accountId);

            if (!response.IsValid)
            {
                return(BadRequest(response.Message));
            }
            return(Ok(response));
        }
コード例 #2
0
        public async Task <BaseResponse> AddAsync(AddInvitationRequest request, int accountId)
        {
            var loggedUser = await _authenticationService.GetLoggedUserAsync();

            var accountUser = await _accountUserRepository.GetAsync(accountUser => accountUser.UserId == loggedUser.User.Id && accountUser.AccountId == accountId);

            var invitation = _mapper.Map <AddInvitationRequest, Invitation>(request);

            invitation.AccountId = accountId;
            invitation.CreatedBy = accountUser;

            await _invitationRepository.AddAsync(invitation);

            await _unitOfWork.SaveChangesAsync();

            return(new BaseResponse());
        }