Reputation: 7866
I develop REST api plugin method in nopcommerce for getting all product list from product table, but any how my method call two times ! that i want to call only ones.
public IList<ProductAllResponse> GetAllProducts(string apiSecretKey, int storeId, int languageId)
{
var _productRepository = EngineContext.Current.Resolve<IRepository<Product>>();
var GetAllProducts = new List<ProductAllResponse>();
try
{
if (!CheckAPIKey(apiSecretKey, storeId))
{
GetAllProducts.Add(new ProductAllResponse { Message = _localizationService.GetResource("Plugins.XcellenceIT.RestApi.Message.CheckApi") });
return GetAllProducts;
}
var query = (from p in _productRepository.Table
where p.Published && !p.Deleted
select new
{
Id = p.Id,
Name = p.Name
}).ToList();
foreach (var item in query)
{
GetAllProducts.Add(new ProductAllResponse { Id = item.Id, Name = item.Name });
}
return GetAllProducts;
}
catch (Exception exc)
{
_logger.Error(exc.Message);
GetAllProducts.Add(new ProductAllResponse { Message = exc.Message });
return GetAllProducts;
}
}
Upvotes: 2
Views: 526
Reputation: 7866
Here issue is in ProductAllResponse
, this response class inherited from other class contextClass
, and this both of class has same property called Id
.
When I removed Id
from ProductAllResponse
and it's now call one time.
Upvotes: 1