ASP.NET / ASP.NET E-commerce Website Using Vue / DAL / DAO / BranchDAO.cs
BranchDAO.cs
Raw
using Casestudy.DAL.DomainClasses;
using Casestudy.Migrations;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
namespace Casestudy.DAL.DAO
{
    public class BranchDAO
    {
        private readonly AppDbContext _db;
        public BranchDAO(AppDbContext ctx)
        {
            _db = ctx;
        }
        public async Task<List<Branch>?> GetThreeClosestStores(float? lat, float? lon)
        {
            List<Branch>? storeDetails = null;
            try
            {
                var latParam = new SqlParameter("@lat", lat);
                var lonParam = new SqlParameter("@lon", lon);
                var query = _db.Branch?.FromSqlRaw("dbo.pGetThreeClosestStores @lat, @lon", latParam,
                lonParam);
                storeDetails = await query!.ToListAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return storeDetails;
        }
    }
}