public IHttpActionResult Read(int?prodID = null) { using (var db = new DB_Context()) { try { ProductCustomViewModel listResult = new ProductCustomViewModel(); var listProductEntity = db.Products.AsQueryable(); List <ProductCustomViewModel> listProduct = new List <ProductCustomViewModel>(); if (prodID != null) { listProductEntity = listProductEntity.Where(data => data.ProductID == prodID); } foreach (var item in listProductEntity.AsEnumerable().ToList()) { ProductCustomViewModel product = new ProductCustomViewModel(item); listProduct.Add(product); } Dictionary <string, object> finalReturn = listResult.FinalResult(listProduct, "Read Data Success"); return(Ok(finalReturn)); } catch (Exception) { throw; } } }
public IHttpActionResult Delete(int prodID) { using (var db = new DB_Context()) { try { ProductCustomViewModel obj = new ProductCustomViewModel(); Product product = db.Products.Where(data => data.ProductID == prodID).FirstOrDefault(); db.Products.Remove(product); db.SaveChanges(); return(Ok(obj.FinalResult(null, "Delete data Success"))); } catch (Exception) { throw; } } }