Esempio n. 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);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 新增資料
 /// </summary>
 /// <param name="measure"></param>
 /// <returns></returns>
 public static long InsertMeasureInfo(Models.Entity.MeasureInfo measure)
 {
     try
     {
         using (var db = new HealthPaltformContext())
         {
             db.MeasureInfo.Add(measure);
             db.SaveChanges();
             return(measure.UID);
         }
     }
     catch (DbEntityValidationException ex)
     {
         new Log().Error($"產生與資料庫相關的錯誤\n" +
                         $"Data:{ex.ToString()}");
         return(-999);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 新增會員資料
        /// </summary>
        /// <param name="memberInfo"></param>
        /// <returns></returns>
        public static int InsertMemberInfo(Models.Entity.MemberInfo memberInfo)
        {
            Log log = new Log();

            try
            {
                using (var db = new HealthPaltformContext())
                {
                    db.MemberInfo.Add(memberInfo);

                    //log
                    return(db.SaveChanges());
                }
            }
            catch (DbEntityValidationException ex)
            {
                log.Error($"產生與資料庫相關的錯誤\n" +
                          $"Data:{ex.ToString()}");
                return(-999);
            }
        }