public IActionResult ProductSupplierByProductId(int productId, [FromBody] ProductSupplierSearchModel model) { var result = _yachtMerchantProductSupplier.GetSupplierByProductId(productId, model); if (result.IsSuccessStatusCode) { return(Ok(result)); } return(BadRequest()); }
public BaseResponse <PagedList <ProductSupplierViewModel> > GetSupplierByProductId(int productId, ProductSupplierSearchModel model) { try { var pageSize = model.PageSize > 0 ? model.PageSize : 10; var pageIndex = model.PageIndex > 0 ? model.PageIndex : 1; var query = (from v in _context.YachtMerchantProductInventories join s in _context.YachtMerchantProductSuppliers on v.Id equals s.ProductFid where s.Deleted == false && v.Deleted == false && s.ProductFid == productId select new ProductSupplierViewModel() { ProductFid = s.ProductFid, VendorFid = s.VendorFid, VendorName = _context.YachtMerchantProductVendors.FirstOrDefault(x => x.Id == s.VendorFid) != null ? _context.YachtMerchantProductVendors.FirstOrDefault(x => x.Id == s.VendorFid).Name : string.Empty, EffectiveDate = s.EffectiveDate, EffectiveEndDate = s.EffectiveEndDate, Remark = s.Remark }).OrderBy(m => m.EffectiveDate).ThenBy(m => m.EffectiveDate); var result = new PagedList <ProductSupplierViewModel>(query, pageIndex, pageSize); return(BaseResponse <PagedList <ProductSupplierViewModel> > .Success(result)); } catch (Exception ex) { return(BaseResponse <PagedList <ProductSupplierViewModel> > .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace)); } }