public async void Add(List <Item> entity) { using (IDbConnection cnn = _connection.Connect(_configuration)) { var sql = "addItems"; //var getDataset = SqlCustomerUtility.GetPreferences(entity.Preferences, entity.EatingHabits); //var p = new //{ // customerHabbits = getDataset.AsTableValuedParameter("BasicCDT"), // Customer=entity.FullName //}; var queryParameters = new DynamicParameters(); foreach (var item in entity) { var getDataset = SqlItemUtility.GetPreferences(item.Ingredients); queryParameters.Add("@Title", item.Title); queryParameters.Add("@Price", item.Price); queryParameters.Add("@Ingredients", getDataset.AsTableValuedParameter("ItemsType")); queryParameters.Add("@IDCateringFacility", item.ID); await cnn.ExecuteAsync(sql, queryParameters, commandType : CommandType.StoredProcedure); } } }
public async Task <int> Add(CustomerDTO entity) { using (IDbConnection cnn = _connection.Connect(_configuration)) { var sql = "AddCustomertest"; var getDataset = SqlCustomerUtility.GetPreferences(entity.Preferences, entity.EatingHabits); //var p = new //{ // customerHabbits = getDataset.AsTableValuedParameter("BasicCDT"), // Customer=entity.FullName //}; var queryParameters = new DynamicParameters(); queryParameters.Add("@customerHabbits", getDataset.AsTableValuedParameter("BasicCDT")); queryParameters.Add("@CustomerID", entity.UserID); queryParameters.Add("@Customer", entity.FullName); queryParameters.Add("@Gender", entity.Gender); return(await cnn.ExecuteAsync(sql, queryParameters, commandType : CommandType.StoredProcedure)); } //using var connection = ////using var connection = new SqlConnection(_configuration.GetConnectionString("LocalDB")); //connection.Open(); //var queryParameters = new DynamicParameters(); //queryParameters.Add("@ID", 6); //queryParameters.Add("@FullName", entity.FullName); }
//public Task<int> Add(Caterer entity) //{ // //var sql = "AddCaterer"; // //using (var connection = _connection.Connect(_configuration)) // //{ // // connection.Open(); // // var queryParameters = new DynamicParameters(); // // queryParameters.Add("@IDCaterer", entity.IDCaterer); // // queryParameters.Add("@Name", entity.Name); // // queryParameters.Add("@OIB", entity.OIB); // // return await connection.ExecuteAsync(sql, queryParameters, commandType: CommandType.StoredProcedure); // //} // var sql = "AddCaterer"; // using (var connection = _connection.Connect(_configuration)) // { // connection.Open(); // var queryParameters = new DynamicParameters(); // queryParameters.Add("@IDCaterer", entity.IDCaterer); // queryParameters.Add("@Name", entity.Name); // queryParameters.Add("@OIB", entity.OIB); // return connection.Query<int>(sql, queryParameters, commandType: CommandType.StoredProcedure) // .SingleOrDefault(); // } //} public int Adding(Caterer entity) { var sql = "AddCaterer"; using (var connection = _connection.Connect(_configuration)) { connection.Open(); var queryParameters = new DynamicParameters(); queryParameters.Add("@catererName", entity.CatererName); queryParameters.Add("@CatererId", entity.CatererID); queryParameters.Add("@FacilityName", entity.CateringFacilitiName); queryParameters.Add("@Adress", entity.Address); queryParameters.Add("@lat", entity.Lat); queryParameters.Add("@long", entity.Long); return(connection.Query <int>(sql, queryParameters, commandType: CommandType.StoredProcedure) .SingleOrDefault()); } //Testing //var sql = "testTWO"; //using (var connection = _connection.Connect(_configuration)) //{ // connection.Open(); // //var queryParameters = new DynamicParameters(); // //queryParameters.Add("@catererName", 1); // //var grid = connection.QueryMultiple("testTWO", queryParameters, // // commandType: CommandType.StoredProcedure); // //var result1 = grid.Read<dynamic, dynamic, Tuple<dynamic, dynamic>>( // // (a, b) => Tuple.Create((object)a, (object)b)).ToList(); // //var result2 = grid.Read<dynamic, dynamic, Tuple<dynamic, dynamic>>( // // (a, b) => Tuple.Create((object)a, (object)b)).ToList(); // var reader = connection.QueryMultiple("testTWO", param: new { CategoryID = 1, SubCategoryID = "", PageNumber = 1 }, commandType: CommandType.StoredProcedure); // var CategoryOneList = reader.Read<string>().ToList(); // var CategoryTwoList = reader.Read<string>().ToList(); // return 1; //} }