public bool ExistsById(PositiveInt id) { using (var connection = _dbConnectionProvider.GetOpenDbConnection()) { return(connection.QuerySingle <bool>("SELECT CAST(CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END AS BIT) FROM DBO.CUSTOMERS WHERE ID = @ID", new { id = id.Value })); } }
public void Delete(PositiveInt id) { using (var connection = _dbConnectionProvider.GetOpenDbConnection()) { connection.Execute("DELETE FROM DBO.CUSTOMERS WHERE ID = @ID", new { id = id.Value }); } }
public PositiveInt Insert(Command command) { using (var connection = _dbConnectionProvider.GetOpenDbConnection()) { return((PositiveInt)connection.QuerySingle <int>(@"INSERT INTO DBO.CUSTOMERS (SURNAME, NAME, PHONENUMBER, ADDRESS) VALUES (@surname, @name, @phoneNumber, @address) SELECT SCOPE_IDENTITY()", new { surname = command.Surname.Value, name = command.Name.Value, phoneNumber = command.PhoneNumber.Value, address = command.Address.Value })); } }
public void Update(Command command) { using (var connection = _dbConnectionProvider.GetOpenDbConnection()) { connection.Execute("UPDATE DBO.CUSTOMERS SET NAME = @name, SURNAME = @surname, PHONENUMBER = @phoneNumber, ADDRESS = @address WHERE ID = @ID", new { id = command.IdVersion.Id.Value, name = command.Name.Value, surname = command.Surname.Value, phoneNumber = command.PhoneNumber.Value, address = command.Address.Value }); } }
public Maybe <Customer> Get(PositiveInt id) { using (var connection = _dbConnectionProvider.GetOpenDbConnection()) { return(connection.QuerySingleOrDefault <Customer>(SelectQuery, new { id = id.Value })); } }
public Paged <Customer> Handle(Query query) { var pagedFragment = CommandHelper.GetPagedFragment(query.OrderByTopSkip.TopSkip, GetSortColumns(query.OrderByTopSkip.OrderByCollection)); var countQuery = string.Format(CountQuery); var selectQuery = string.Format(SelectQuery, pagedFragment.Data); using (var connection = _dbConnectionProvider.GetOpenDbConnection()) { var count = (NonNegativeInt)connection.QuerySingle <int>(countQuery); var select = connection.Query <Customer>(selectQuery, pagedFragment.Parameters).ToImmutableList(); return(Paged <Customer> .Create(count, select)); } }