using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace marketconnectionNET
{
    public class dataaccess
    {

        public List<cities> GetLocations(string LocationName)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(helper.CnnVal("marketdb")))
            {

                var output = connection.Query<cities> ($"select * from cities where city_name = '{ LocationName }'").ToList();
                return output;

            }
        }

        public void InsertPerson(string Firstname, string Lastname, string Date_of_birth, string Streetname, string Streetnumber)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(helper.CnnVal("marketdb")))
            {
                //person newPerson = new person { firstname = Firstname, lastname = Lastname, date_of_birth = Date_of_birth, streetname = Streetname, streetnumber = Streetnumber };
                List<person> people = new List<person>();

                people.Add(new person { firstname = Firstname, lastname = Lastname, date_of_birth = Date_of_birth, streetname = Streetname, streetnumber = Streetnumber, });

                connection.Execute("insert into dbo.persons (firstname, lastname, date_of_birth, streetname, streetnumber)" +
                    " values (@firstname, @lastname, @date_of_birth, @streetname, @streetnumber) ", people);

            }
        }
    }
}
