public JsonResult SaveBondRating(string actionType, BondRatingViewModel dataModel) { MSGReturnModel result = new MSGReturnModel(); result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.parameter_Error.GetDescription(); try { MSGReturnModel resultSave = TickerRatingRepository.saveBondRating(actionType, dataModel); result.RETURN_FLAG = resultSave.RETURN_FLAG; result.DESCRIPTION = Message_Type.save_Success.GetDescription(); if (!result.RETURN_FLAG) { result.DESCRIPTION = Message_Type.save_Fail.GetDescription() + " " + resultSave.DESCRIPTION; } } catch (Exception ex) { result.RETURN_FLAG = false; result.DESCRIPTION = ex.Message; } return(Json(result)); }
public JsonResult GetBondRatingData(string queryType, BondRatingViewModel dataModel) { MSGReturnModel result = new MSGReturnModel(); result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.not_Find_Any.GetDescription(); try { var queryData = TickerRatingRepository.getBondRating(queryType, dataModel); result.RETURN_FLAG = queryData.Item1; result.Datas = Json(queryData.Item2); } catch (Exception ex) { result.RETURN_FLAG = false; result.DESCRIPTION = ex.Message; } return(Json(result)); }
public MSGReturnModel saveBondRating(string actionType, BondRatingViewModel dataModel) { MSGReturnModel result = new MSGReturnModel(); using (IFRS9DBEntities db = new IFRS9DBEntities()) { try { if (actionType == "Add") { if (db.Bond_Rating.AsNoTracking() .Where(x => x.Bond_Number == dataModel.Bond_Number) .Count() > 0) { result.RETURN_FLAG = false; result.DESCRIPTION = string.Format("資料重複:{0} 已存在", dataModel.Bond_Number); return(result); } Bond_Rating addData = new Bond_Rating(); addData.Bond_Number = dataModel.Bond_Number; addData.S_And_P = dataModel.S_And_P; addData.Moodys = dataModel.Moodys; addData.Fitch = dataModel.Fitch; addData.Fitch_TW = dataModel.Fitch_TW; addData.TRC = dataModel.TRC; addData.Create_User = _UserInfo._user; addData.Create_Time = _UserInfo._time; addData.Create_Date = _UserInfo._date; db.Bond_Rating.Add(addData); } else if (actionType == "Modify") { Bond_Rating oldData = db.Bond_Rating .Where(x => x.Bond_Number == dataModel.Bond_Number) .FirstOrDefault(); oldData.S_And_P = dataModel.S_And_P; oldData.Moodys = dataModel.Moodys; oldData.Fitch = dataModel.Fitch; oldData.Fitch_TW = dataModel.Fitch_TW; oldData.TRC = dataModel.TRC; oldData.LastUpdate_User = _UserInfo._user; oldData.LastUpdate_Date = _UserInfo._date; oldData.LastUpdate_Time = _UserInfo._time; } db.SaveChanges(); result.RETURN_FLAG = true; } catch (DbUpdateException ex) { result.RETURN_FLAG = false; result.DESCRIPTION = ex.Message; } } return(result); }
public Tuple <bool, List <BondRatingViewModel> > getBondRating(string queryType, BondRatingViewModel dataModel) { using (IFRS9DBEntities db = new IFRS9DBEntities()) { var query = from q in db.Bond_Rating.AsNoTracking() select q; if (dataModel.Bond_Rating_ID.IsNullOrWhiteSpace() == false) { query = query.Where(x => x.Bond_Rating_ID.ToString() == dataModel.Bond_Rating_ID); } if (dataModel.Bond_Number.IsNullOrWhiteSpace() == false) { query = query.Where(x => x.Bond_Number == dataModel.Bond_Number); } if (dataModel.S_And_P.IsNullOrWhiteSpace() == false) { query = query.Where(x => x.S_And_P == dataModel.S_And_P); } if (dataModel.Moodys.IsNullOrWhiteSpace() == false) { query = query.Where(x => x.Moodys == dataModel.Moodys); } if (dataModel.Fitch.IsNullOrWhiteSpace() == false) { query = query.Where(x => x.Fitch == dataModel.Fitch); } if (dataModel.Fitch_TW.IsNullOrWhiteSpace() == false) { query = query.Where(x => x.Fitch_TW == dataModel.Fitch_TW); } if (dataModel.TRC.IsNullOrWhiteSpace() == false) { query = query.Where(x => x.TRC == dataModel.TRC); } bool item1 = true; if (queryType != "ALL") { item1 = query.Any(); } return(new Tuple <bool, List <BondRatingViewModel> >( item1, query.AsEnumerable() .Select(x => { return DbToBondRatingModel(x); }).ToList())); } }