Пример #1
0
        /// <summary>
        /// 建立評語的資料
        /// </summary>
        /// <param name="measure"></param>
        /// <returns></returns>
        public static bool InitialResultRemark()
        {
            var result = false;

            try
            {
                using (var db = new HealthPaltformContext())
                {
                    if (!db.ResultRemark.Any())
                    {
                        var tmpData = ToolLibs.GetResultRemarkData();
                        var obj     = ToolLibs.ResultRemarkConvert(tmpData);

                        if (obj.Result.Any())
                        {
                            foreach (var unit in obj.Result)
                            {
                                //建立新物件
                                var tmpResult = new Models.Entity.ResultRemark();

                                //型態
                                tmpResult.Type = ToolLibs.GetEnum <ResultRemarkType>(unit.Type);

                                //低標
                                tmpResult.LowRange = Convert.ToDouble(unit.LowRange);

                                //頂標
                                tmpResult.HightRange = Convert.ToDouble(unit.HightRange);

                                //等級
                                tmpResult.Level = unit.Level;

                                //評語
                                tmpResult.Message = unit.Message;

                                //建立日期
                                tmpResult.CreateDate = DateTime.Now;

                                //新增資料
                                db.ResultRemark.Add(tmpResult);
                            }
                            //儲存新增
                            if (db.SaveChanges() > 0)
                            {
                                result = true;
                            }
                        }
                    }
                }
                return(result);
            }
            catch (DbEntityValidationException ex)
            {
                new Log().Error($"產生與資料庫相關的錯誤\n" +
                                $"Data:{ex.ToString()}");
                return(result);
            }
        }