Пример #1
0
        public ActionResult <UserDto> CreateUser(UserForCreationDto user)
        {
            //Map user from entites to a user for creation
            var userEntity = _mapper.Map <Entities.User>(user);

            //Add a user to repository
            _userLibraryRepository.AddUser(ref userEntity);
            //Save changes
            _userLibraryRepository.Save();
            //Map user from repo to UserDto
            var userToReturn = _mapper.Map <UserDto>(userEntity);

            return(CreatedAtRoute("GetUser",
                                  new { Id = userToReturn.Id },
                                  userToReturn));
        }
Пример #2
0
        public ActionResult <AgreementDto> CreateAgreementForUser(ulong userId, AgreementForCreationDto agreement)
        {
            if (!_userLibraryRepository.UserExists(userId))
            {
                return(NotFound());
            }

            var agreementEntity = _mapper.Map <Entities.Agreement>(agreement);

            _userLibraryRepository.AddAgreement(userId, agreementEntity);
            _userLibraryRepository.Save();

            var agreementToReturn = _mapper.Map <AgreementDto>(agreementEntity);

            return(CreatedAtRoute("GetAgreementForUser",
                                  new { userId = userId, agreementId = agreementToReturn.Id }, agreementToReturn));
        }