Beispiel #1
0
        public CommandResult Handle(CreatePieceCommand command)
        {
            var piece = mapper.Map <Model.Entity.Piece>(command);

            using (var ctx = new BookshelfDbContext(_connectionString))
            {
                ctx.Pieces.Add(piece);
                ctx.SaveChanges();
                return(CommandResult.Ok(piece.Id));
            }
        }
        public CommandResult Handle(CreateAuthorCommand command)
        {
            var author        = mapper.Map <Model.Entity.Author>(command);
            var nationalityId = getNationalityIdByNameQueryHandler.Handle(new GetNationalityIdByNameQuery {
                Name = command.Nationality
            });

            author.NationalityId = nationalityId.Value;
            using (var ctx = new BookshelfDbContext(_connectionString))
            {
                ctx.Authors.Add(author);
                ctx.SaveChanges();
                return(CommandResult.Ok(author.Id));
            }
        }
 public CommandResult Handle(CreateAccountCommand command)
 {
     using (var ctx = new BookshelfDbContext(connectionString))
     {
         var user = new Model.Entity.User
         {
             AspNetGuid = command.AspNetGuid,
             FirstName  = command.FirstName,
             LastName   = command.LastName,
             CardId     = new Random().Next(1, 99999999), // TODO: In the future check if number is not used yet.
         };
         ctx.Users.Add(user);
         ctx.SaveChanges();
         return(CommandResult.Ok(user.Id));
     }
 }
        public CommandResult Handle(CreateBookCommand command)
        {
            var book = mapper.Map <Model.Entity.Book>(command);

            book.BookTags = new List <Model.Entity.BookTag>();
            foreach (var tag in command.BookTags)
            {
                book.BookTags.Add(new Model.Entity.BookTag
                {
                    Tag = tag
                });
            }

            using (var ctx = new BookshelfDbContext(_connectionString))
            {
                ctx.Books.Add(book);
                ctx.SaveChanges();
                return(CommandResult.Ok(book.Id));
            }
        }