public ActionResult <UserDto> CreateUser(UserForCreationDto user)
        {
            var userEntity = _mapper.Map <User>(user);

            _articleLibraryRepository.AddUser(userEntity);
            _articleLibraryRepository.Save();

            var userToReturn = _mapper.Map <UserDto>(userEntity);

            return(CreatedAtRoute("GetUser",
                                  new { userId = userToReturn.Id },
                                  userToReturn));
        }
Example #2
0
        public ActionResult <IEnumerable <UserDto> > CreateUserCollection(IEnumerable <UserForCreationDto> userCollection)
        {
            var userEntities = _mapper.Map <IEnumerable <Entities.User> >(userCollection);

            foreach (var user in userEntities)
            {
                _articleLibraryRepository.AddUser(user);
            }

            _articleLibraryRepository.Save();

            var userCollectionToReturn = _mapper.Map <IEnumerable <UserDto> >(userEntities);
            var idsAsString            = string.Join(",", userCollectionToReturn.Select(u => u.Id));

            return(CreatedAtRoute("GetAuthorCollection",
                                  new { ids = idsAsString },
                                  userCollectionToReturn));
        }