public IDataResult <List <ProductWithImageDto> > GetAll() { using (ECommercialContext context = new ECommercialContext()) { var list = context.Database.SqlQuery <ProductWithImageDto>("select * from Products p inner join(select * from ProductImages where Id in(select t.id from(select ProductId, max(Id) as id from ProductImages group by ProductId) as t)) as pı on p.Id = pı.ProductId inner join UserFavorites uf on uf.ProductId = p.Id where uf.Status = 'True'").ToListAsync().Result; return(new SuccessDataResult <List <ProductWithImageDto> >(list)); } }
public IDataResult <List <ProductWithImageDto> > GetProductWithImages(Expression <Func <Task, bool> > filter = null) { using (ECommercialContext context = new ECommercialContext()) { var list = context.Database.SqlQuery <ProductWithImageDto>("select * from Products p inner join(select * from ProductImages where Id in (select t.id from(select ProductId, max(Id) as id from ProductImages group by ProductId) as t)) as pı on p.Id = pı.ProductId inner join Categories c on c.CategoryId = p.CategoryId").ToListAsync().Result; return(new SuccessDataResult <List <ProductWithImageDto> >(list)); } }
public IDataResult <ProductWithImageDto> GetProductWithImagesByProductId(int id) { using (ECommercialContext context = new ECommercialContext()) { var product = context.Database.SqlQuery <ProductWithImageDto>($"select * from Products p inner join(select * from ProductImages where Id in (select t.id from(select ProductId, max(Id) as id from ProductImages group by ProductId) as t)) as pı on p.Id = pı.ProductId inner join Categories c on c.CategoryId = p.CategoryId where p.Id = {id}").FirstOrDefault(); return(new SuccessDataResult <ProductWithImageDto>(product)); } }
public List <SelectListItem> GetCategoriesList() { using (ECommercialContext context = new ECommercialContext()) { var result = from c in context.Categories.Where(x => x.Status == true) select new SelectListItem { Text = c.CategoryName, Value = c.CategoryId.ToString() }; return(result.ToList()); } }