Exemple #1
0
            //Dapper allows ou to write out SQL Queries
            private async Task <int> InsertUser(Command command)
            {
                var sql = @"
DECLARE @InsertedRows TABLE ( ID int )
INSERT INTO sec.AppUser OUTPUT inserted.ID INTO @InsertedRows 
VALUES 
( 
    @UserID,
    @FirstName,
    @LastName,
    @Role,
    @IsActive,
    @Title,
    @EmailAddress,
   ...[some proeprties hidden]
)
SELECT ID FROM @InsertedRows";

                var result = await _context.Execute( //parameterized queries
                    sql,
                    new
                {
                    UserID       = command.UserID,
                    FirstName    = command.FirstName,
                    LastName     = command.LastName,
                    Role         = command.Role,
                    IsActive     = true,
                    Title        = command.Title,
                    EmailAddress = command.EmailAddress,
                    //...[some properties hidden]
                    UpdatedUserID = _user.UserName,
                    UpdateDT      = DateTime.Now
                });

                return(result);
            }