using Fuel.Core.Nozzle.Dto;
using FuelServer.Core.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Fuel.Application.Repositories
{
    public class NozzleRepository : INozzleRepository
    {
        private readonly IFreeSql _fsql;
        public NozzleRepository(IFreeSql fsql)
        {
            _fsql = fsql;
        }
        public async Task<bool> uploadNozzle(UploadNozzle uploadNozzle)
        {
            bool result = false;
            if (uploadNozzle.type == 1)
            {

            }
            else if (uploadNozzle.type == 2)
            {

            }
            else if (uploadNozzle.type == 3)
            {

            }
            var sds = _fsql.Select<nozzle>().ToList();
            return result;
        }
        public async Task<List<nozzle>> AddNozzle(nozzle _nozzle)
        {
            return _fsql.Insert(_nozzle).ExecuteInserted();
        }
        public async Task<tanks> AddTanks(tanks _tanks)
        {
            try
            {
                _fsql.Insert(_tanks).ExecuteAffrows();

                object insertedIdObj = _fsql.Ado.ExecuteScalar("SELECT LAST_INSERT_ID();");
                int insertedId = Convert.ToInt32(insertedIdObj);

                // 查询插入后的数据
                return _fsql.Select<tanks>().Where(n => n.Id == insertedId).First();
            }
            catch (Exception ex)
            {

            }
            return null;
        }
        public async Task<product> AddProduct(product _product)
        {
            try
            {
                _fsql.Insert(_product).ExecuteAffrows();

                object insertedIdObj = _fsql.Ado.ExecuteScalar("SELECT LAST_INSERT_ID();");
                int insertedId = Convert.ToInt32(insertedIdObj);

                // 查询插入后的数据
                return _fsql.Select<product>().Where(n => n.Id == insertedId).First();
            }
            catch (Exception ex)
            {

            }
            return null;
        }
    }
}
