public JsonResult Insert([FromBody] AppVendor obj) { var msg = new JMessage() { Error = false, Title = "" }; try { var checkExist = _context.AppVendors.FirstOrDefault(x => x.VendorCode.ToLower() == obj.VendorCode.ToLower()); if (checkExist != null) { msg.Error = true; msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_EXITS"), CommonUtil.ResourceValue("AVD_CURD_LBL_CODE")); } else { _context.AppVendors.Add(obj); _context.SaveChanges(); msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_SUCCESS"), CommonUtil.ResourceValue("AVD_MSG_PARTNER")); } } catch (Exception ex) { msg.Error = true; msg.Title = String.Format(CommonUtil.ResourceValue("COM_ERR_FAIL_ADD"), CommonUtil.ResourceValue("AVD_MSG_PARTNER")); } return(Json(msg)); }
public JsonResult Update([FromBody] AppVendor obj) { var msg = new JMessage() { Error = false, Title = "" }; try { var data = _context.AppVendors.FirstOrDefault(x => x.Id == obj.Id); if (data != null) { data.Name = obj.Name; data.Email = obj.Email; data.Status = obj.Status; data.Address = obj.Address; data.Note = obj.Note; _context.SaveChanges(); msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_UPDATE_SUCCESS"), CommonUtil.ResourceValue("AVD_MSG_PARTNER")); } else { msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_NOT_EXITS"), CommonUtil.ResourceValue("AVD_MSG_PARTNER_AVD")); } } catch (Exception ex) { msg.Error = true; msg.Title = String.Format(CommonUtil.ResourceValue("COM_UPDATE_FAIL")); } return(Json(msg)); }