/// <summary> /// 新增,刪除,修改 A96 最後交易日 /// </summary> /// <param name="data"></param> /// <param name="type"></param> /// <returns></returns> public MSGReturnModel saveA96Trade(A96TradeViewModel data, Action_Type type) { MSGReturnModel result = new MSGReturnModel(); result.RETURN_FLAG = false; using (IFRS9DBEntities db = new IFRS9DBEntities()) { var reportDate = TypeTransfer.stringToDateTime(data.Report_Date); if (type == Action_Type.Add) { db.Bond_Spread_Trade_Info.Add( new Bond_Spread_Trade_Info() { Report_Date = reportDate, Last_Date = TypeTransfer.stringToDateTime(data.Last_Date), Create_User = _UserInfo._user, Create_Date = _UserInfo._date, Create_Time = _UserInfo._time, LastUpdate_User = _UserInfo._user, LastUpdate_Date = _UserInfo._date, LastUpdate_Time = _UserInfo._time }); result.DESCRIPTION = Message_Type.save_Success.GetDescription(); } else if (type == Action_Type.Dele) { db.Bond_Spread_Trade_Info.Remove(db.Bond_Spread_Trade_Info.First(x => x.Report_Date == reportDate)); result.DESCRIPTION = Message_Type.delete_Success.GetDescription(); } else if (type == Action_Type.Edit) { var _trade = db.Bond_Spread_Trade_Info.FirstOrDefault(x => x.Report_Date == reportDate); if (_trade != null) { _trade.Last_Date = TypeTransfer.stringToDateTime(data.Last_Date); _trade.LastUpdate_User = _UserInfo._user; _trade.LastUpdate_Date = _UserInfo._date; _trade.LastUpdate_Time = _UserInfo._time; } result.DESCRIPTION = Message_Type.save_Success.GetDescription(); } try { db.SaveChanges(); result.RETURN_FLAG = true; } catch (Exception ex) { result.DESCRIPTION = ex.exceptionMessage(); } } return(result); }
public JsonResult saveA96Trade(A96TradeViewModel data, string action, string reportDate) { MSGReturnModel result = new MSGReturnModel(); Action_Type _action = EnumUtil.GetValues <Action_Type>() .FirstOrDefault(x => x.ToString() == action); DateTime?dt = null; DateTime _dt = DateTime.MinValue; if (DateTime.TryParse(reportDate, out _dt)) { dt = _dt; } result = A9Repository.saveA96Trade(data, _action); if (result.RETURN_FLAG) { var datas = A9Repository.getA96Trade(dt); Cache.Invalidate(CacheList.A96TradeDbfileData); //清除 Cache.Set(CacheList.A96TradeDbfileData, datas); //把資料存到 Cache } return(Json(result)); }