Ejemplo n.º 1
0
 private IssuerRatingViewModel DbToIssuerRatingModel(Issuer_Rating data)
 {
     return(new IssuerRatingViewModel()
     {
         Table_Name = "Issuer_Rating",
         Issuer_Rating_ID = data.Issuer_Rating_ID.ToString(),
         Issuer = data.Issuer,
         S_And_P = data.S_And_P,
         Moodys = data.Moodys,
         Fitch = data.Fitch,
         Fitch_TW = data.Fitch_TW,
         TRC = data.TRC
     });
 }
Ejemplo n.º 2
0
        public MSGReturnModel saveIssuerRating(string actionType, IssuerRatingViewModel dataModel)
        {
            MSGReturnModel result = new MSGReturnModel();

            using (IFRS9DBEntities db = new IFRS9DBEntities())
            {
                try
                {
                    if (actionType == "Add")
                    {
                        if (db.Issuer_Rating.AsNoTracking()
                            .Where(x => x.Issuer == dataModel.Issuer)
                            .Count() > 0)
                        {
                            result.RETURN_FLAG = false;
                            result.DESCRIPTION = string.Format("資料重複:{0} 已存在", dataModel.Issuer);
                            return(result);
                        }

                        Issuer_Rating addData = new Issuer_Rating();

                        addData.Issuer      = dataModel.Issuer;
                        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_Date = _UserInfo._date;
                        addData.Create_Time = _UserInfo._time;
                        db.Issuer_Rating.Add(addData);
                    }
                    else if (actionType == "Modify")
                    {
                        Issuer_Rating oldData = db.Issuer_Rating
                                                .Where(x => x.Issuer == dataModel.Issuer)
                                                .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);
        }