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 Create([FromBody] ProductCustomViewModel dataBody) { try { using (var db = new DB_Context()) { Product product = dataBody.ConvertToProduct(); db.Products.Add(product); db.SaveChanges(); return(Ok("Data Saved Successfully")); } } 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; } } }
public IHttpActionResult CustomCreateProduct([FromBody] ProductCustomViewModel dataBody) { try { using (var db = new DB_Context()) { var temp = db.Products.AsQueryable(); Dictionary <string, object> result = new Dictionary <string, object>(); Product product = dataBody.ConvertToProduct(); db.Products.Add(product); db.SaveChanges(); return(Ok("Data Saved Successfully")); } } catch (Exception) { throw; } }
public IHttpActionResult CalculateProductUnitPrice([FromBody] ProductCustomViewModel dataBody, string condition = null, int?userDemand = null, decimal?Duration = null) { try { using (var db = new DB_Context()) { Dictionary <string, object> result = new Dictionary <string, object>(); List <ProductCustomViewModel> listProduct = new List <ProductCustomViewModel>(); var product = db.Products.AsQueryable(); foreach (var item in product) { } result.Add("Message", "Update data success"); result.Add("data", listProduct); return(Ok(result)); } } catch (Exception) { throw; } }