Exemple #1
0
        public async Task <ActionResult <Book> > UpdateAsync(string id, BookBase model)
        {
            using (await _locker.EnterAsync(id))
            {
                var book = await _books.GetAsync(id);

                if (book == null)
                {
                    return(ResultUtilities.NotFound <Book>(id));
                }

                _mapper.Map(model, book);

                await _books.UpdateAsync(book);

                await _snapshots.ModifiedAsync(book);

                return(book);
            }
        }
        public async Task <ActionResult <RegistrationResponse> > RegisterAsync(RegistrationRequest request)
        {
            using (await _locker.EnterAsync(request.Username))
            {
                // ensure username is unique
                if (await _users.GetByNameAsync(request.Username) != null)
                {
                    return(BadRequest($"Cannot use the username '{request.Username}'."));
                }

                var user = new User
                {
                    Username    = request.Username,
                    Secret      = _hash.Hash(request.Password),
                    Permissions = _options.DefaultUserPermissions
                };

                await _users.UpdateAsync(user);

                await _snapshot.CreatedAsync(user, default, SnapshotType.System, user.Id);