using Ropin.Inspection.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ropin.Inspection.Repository
{
    public class TmtnSpotDevOpsContentRepository : RepositoryBase<TMTN_SpotDevOpsContent, Guid>, ITmtnSpotDevOpsContentRepository
    {
        public TmtnSpotDevOpsContentRepository(InspectionDbContext DbContext) : base(DbContext)
        {

        }
        public Task<int> DeleteBySpotIdAsync(string spotId)
        {
            MySqlConnector.MySqlParameter[] parameters = new[] { new MySqlConnector.MySqlParameter("Id", spotId) };
            int result = EntityFrameworkCoreExtensions.ExecuteSqlNoQuery(DbContext.Database, "DELETE from TMTN_SpotDevOpsContent WHERE C_SpotCode = @Id", parameters);
            return Task.FromResult(result);

        }
        public IEnumerable<TMTN_DevOpsContent> GetBySpotCodeAsync(string id)
        {
            MySqlConnector.MySqlParameter[] parameters = new[] { new MySqlConnector.MySqlParameter("Id", id)};
            var contentlist = EntityFrameworkCoreExtensions.SqlQuery<TMTN_DevOpsContent>(DbContext.Database, "select A.* from TMTN_DevOpsContent A, TISP_Spot B ,TMTN_SpotDevOpsContent C WHERE A.C_ID = C.C_DevOpsContentCode AND B.C_Code = C.C_SpotCode AND C.C_SpotCode = @Id", parameters);
            return contentlist;
        }
    }
}