public async void DeleteOrderItem(int id)
 {
     using (var connection = new SqlConnection(_config.GetConnectionString("RestaurantAPI")))
     {
         await connection.ExecuteAsync(SqlQueriesFactory.DeleteOrderItem(), new { Id = id });
     }
 }
        public async Task <Table> GetFirstOrDefault(int id)
        {
            Table table;

            using (var connection = new SqlConnection(_config.GetConnectionString("RestaurantAPI")))
            {
                table = await connection.QueryFirstOrDefaultAsync <Table>(SqlQueriesFactory.GetTable(), new { Id = id });
            }

            return(table);
        }
        public async Task <IEnumerable <Table> > GetAll()
        {
            IEnumerable <Table> tablesList;

            using (var connection = new SqlConnection(_config.GetConnectionString("RestaurantAPI")))
            {
                tablesList = await connection.QueryAsync <Table>(SqlQueriesFactory.GetAllTables());
            }

            return(tablesList);
        }
コード例 #4
0
        public async Task <Meal> GetFirstOrDefault(int id)
        {
            Meal meal;

            using (var connection = new SqlConnection(_config.GetConnectionString("RestaurantAPI")))
            {
                meal = await connection.QueryFirstOrDefaultAsync <Meal>(SqlQueriesFactory.GetMeal(), new { Id = id });
            }

            return(meal);
        }
コード例 #5
0
        public async Task <IEnumerable <Meal> > GetAll()
        {
            IEnumerable <Meal> mealsList;

            using (var connection = new SqlConnection(_config.GetConnectionString("RestaurantAPI")))
            {
                mealsList = await connection.QueryAsync <Meal>(SqlQueriesFactory.GetAllMeals());
            }

            return(mealsList);
        }
        public async void Register(User user, string password)
        {
            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            using (var connection = new SqlConnection(_config.GetConnectionString("RestaurantAPI")))
            {
                await connection.ExecuteAsync(SqlQueriesFactory.AddUser(), user);
            }
        }
 public async Task <bool> UserExists(string username)
 {
     using (var connection = new SqlConnection(_config.GetConnectionString("RestaurantAPI")))
     {
         if (await connection.QueryFirstOrDefaultAsync <User>(SqlQueriesFactory.GetUser(), new { Username = username }) == null)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
 }
コード例 #8
0
        public async Task <Meal> Add(Meal entity)
        {
            Meal insertedMeal;

            using (var connection = new SqlConnection(_config.GetConnectionString("RestaurantAPI")))
            {
                await connection.OpenAsync();

                using (var transaction = await connection.BeginTransactionAsync())
                {
                    insertedMeal = await connection.QueryFirstOrDefaultAsync <Meal>(SqlQueriesFactory.AddMeal(), entity);

                    await transaction.CommitAsync();
                }
            }

            return(insertedMeal);
        }
        public async Task <User> Login(UserForLoginDto userForLoginDto)
        {
            using (var connection = new SqlConnection(_config.GetConnectionString("RestaurantAPI")))
            {
                var user = await connection.QueryFirstOrDefaultAsync <User>(SqlQueriesFactory.GetUser(), new { Username = userForLoginDto.Username });

                if (user == null)
                {
                    return(null);
                }

                if (!VerifyPasswordHash(userForLoginDto.Password, user.PasswordHash, user.PasswordSalt))
                {
                    return(null);
                }

                return(user);
            }
        }
        public async Task <Table> Add(Table entity)
        {
            Table insertedTable;

            using (var connection = new SqlConnection(_config.GetConnectionString("RestaurantAPI")))
            {
                await connection.OpenAsync();

                using (var transaction = await connection.BeginTransactionAsync())
                {
                    insertedTable = await connection.QueryFirstOrDefaultAsync <Table>(SqlQueriesFactory.AddTable(), entity);

                    await transaction.CommitAsync();
                }
            }

            return(insertedTable);
        }