// JObject here is very very important... public ActionResult <string> Post([FromBody] JObject entityObj) { ORDER_DETAIL_MST postedEntity = entityObj.ToObject <ORDER_DETAIL_MST>(); var orderListEntity = myContext.ORDER_LIST_MST.Where(d => d.ORDER_NO != null); if (!String.IsNullOrEmpty(postedEntity.ORDER_NO)) { orderListEntity = orderListEntity.Where(d => d.ORDER_NO.Equals(postedEntity.ORDER_NO)); } if (orderListEntity.Count() == 0) { // INSERT myContext.ORDER_LIST_MST.Add(postedEntity); myContext.SaveChanges(); return(""); } else { orderListEntity.First().CONTRACT_NO = postedEntity.CONTRACT_NO; orderListEntity.First().PROJECT_NM = postedEntity.PROJECT_NM; orderListEntity.First().ORDER_UNIT = postedEntity.ORDER_UNIT; orderListEntity.First().SALES_PERSON = postedEntity.SALES_PERSON; orderListEntity.First().DEPARTURE_DATE = postedEntity.DEPARTURE_DATE.ToLocalTime(); orderListEntity.First().DELIVERY_DATE = postedEntity.DELIVERY_DATE.ToLocalTime(); orderListEntity.First().REMARK = postedEntity.REMARK; orderListEntity.First().APPLICATION_ENGINEER = postedEntity.APPLICATION_ENGINEER; myContext.SaveChanges(); return(""); } }
public ActionResult <string> Delete(string ORDER_NO) { Boolean isSuccess = true; string data = "Delete success"; if (!String.IsNullOrEmpty(ORDER_NO)) { String[] ORDER_NO_LIST = ORDER_NO.Split(","); foreach (string ORDER_ITEM in ORDER_NO_LIST) { ORDER_DETAIL_MST delMstEntity = new ORDER_DETAIL_MST() { ORDER_NO = ORDER_ITEM }; if (delMstEntity.Equals(null)) { isSuccess = false; data = "No such data."; break; } else { // FIND ORDER DETAIL /* * int deteilNum = myContext.ORDER_LIST_DETAIL.Count(d => d.ORDER_NO == ORDER_ITEM); * if (deteilNum > 0) * { * isSuccess = false; * data = ORDER_ITEM + " has detail info."; * break; * } */ // FIND DB ITEM myContext.ORDER_LIST_MST.Attach(delMstEntity); // DELETE DB ITEM myContext.ORDER_LIST_MST.Remove(delMstEntity); // DELETE DETAIL ITEM int deteilNum = myContext.ORDER_LIST_DETAIL.Count(d => d.ORDER_NO == ORDER_ITEM); if (deteilNum > 0) { foreach (ORDER_LIST_DETAIL DetailEntity in myContext.ORDER_LIST_DETAIL.Where(d => d.ORDER_NO == ORDER_ITEM).ToList()) { myContext.ORDER_LIST_DETAIL.Remove(DetailEntity); } } // NEED TO CHECK DELETE RESULT HERE if (true) { // SAVE CHANGES AND DO NOT RETURN myContext.SaveChanges(); } else { isSuccess = false; data = "No such data."; break; } } } } else { isSuccess = false; data = "No such data."; } JsonRes res = new JsonRes(); res.isSuccess = isSuccess; res.data = data; return(JsonConvert.SerializeObject(res)); }