public void BreathAPI(BreathAPI A)
        {
            G3_Measure_Air B = new G3_Measure_Air();

            B.Userid          = A.Userid;
            B.Air             = A.Air;
            B.MeasurementDate = DateTime.Now;
            if (B.Air <= 0)
            {
                B.Status = "呼吸停止,有立即性危險,應盡速送醫";
                B.Score  = 10;
            }
            else
            {
                B.Status = "呼吸正常";
                B.Score  = 0;
            }
            using (AIPEntities25 db = new AIPEntities25())
            {
                db.G3_Measure_Air.Add(B);
                db.SaveChanges();
            }
        }
        public ActionResult Create(string Name = null)
        {
            SystemNutrition        D       = new SystemNutrition();
            G3_Nutrition_Nutrition B       = new G3_Nutrition_Nutrition();
            HealthyScore           Healthy = new HealthyScore();
            UserHealthyInformation C       = new UserHealthyInformation();

            using (AIPEntities18 db = new AIPEntities18())
            {
                var reuslt = db.G1_User_Account.ToList();
                foreach (var item in reuslt)
                {
                    if (Name == item.email)
                    {
                        B.UserId = item.id;
                    }
                }
            }
            D.UserName  = Name;
            D.Nutrition = B;

            using (AIPEntities7 db = new AIPEntities7())
            {
                int number = 1;
                var reuslt = db.G3_Measure_BloodPressure.ToList();
                G3_Measure_BloodPressure History = new G3_Measure_BloodPressure();
                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.SBP             = item.SBP;
                        History.DBP             = item.DBP;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.SBP             = item.SBP;
                            History.DBP             = item.DBP;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.BloodPressure = History;
                }
            }

            using (AIPEntities9 db = new AIPEntities9())
            {
                int            number  = 1;
                var            reuslt  = db.G3_Measure_ABG.ToList();
                G3_Measure_ABG History = new G3_Measure_ABG();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.SpO2            = item.SpO2;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.SpO2            = item.SpO2;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.ABG = History;
                }
            }

            using (AIPEntities8 db = new AIPEntities8())
            {
                int number = 1;
                var reuslt = db.G3_Measure_BloodGlucose.ToList();
                G3_Measure_BloodGlucose History = new G3_Measure_BloodGlucose();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.GLU_AC          = item.GLU_AC;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.GLU_AC          = item.GLU_AC;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.BloodGlucose = History;
                }
            }

            using (AIPEntities11 db = new AIPEntities11())
            {
                int            number  = 1;
                var            reuslt  = db.G3_Measure_BMI.ToList();
                G3_Measure_BMI History = new G3_Measure_BMI();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.BMI             = item.BMI;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.BMI             = item.BMI;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.BMI = History;
                }
            }
            using (AIPEntities25 db = new AIPEntities25())
            {
                int            number  = 1;
                var            reuslt  = db.G3_Measure_Air.ToList();
                G3_Measure_Air History = new G3_Measure_Air();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.Air             = item.Air;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.Air             = item.Air;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.Air = History;
                }
            }
            using (GSR db = new GSR())
            {
                int            number  = 1;
                var            reuslt  = db.G3_Measure_GSR.ToList();
                G3_Measure_GSR History = new G3_Measure_GSR();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid                 = item.Userid;
                        History.SkinConductance        = item.SkinConductance;
                        History.SkinResistance         = item.SkinResistance;
                        History.SkinConductanceVoltage = item.SkinConductanceVoltage;
                        History.MeasurementDate        = item.MeasurementDate;
                        History.Status                 = item.Status;
                        History.Score = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.SkinConductance        = item.SkinConductance;
                            History.SkinResistance         = item.SkinResistance;
                            History.SkinConductanceVoltage = item.SkinConductanceVoltage;
                            History.MeasurementDate        = item.MeasurementDate;
                            History.Status = item.Status;
                            History.Score  = item.Score;
                        }
                    }
                    C.GSR = History;
                }
            }
            using (GyroValues db = new GyroValues())
            {
                int number = 1;
                var reuslt = db.G3_Measure_GyroValues.ToList();
                G3_Measure_GyroValues History = new G3_Measure_GyroValues();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.RawX            = item.RawX;
                        History.RawY            = item.RawY;
                        History.RawZ            = item.RawZ;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.RawX            = item.RawX;
                            History.RawY            = item.RawY;
                            History.RawZ            = item.RawZ;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.GyroValues = History;
                }
            }
            using (bodyTemperature db = new bodyTemperature())
            {
                int number = 1;
                var reuslt = db.G3_Measure_Temperature.ToList();
                G3_Measure_Temperature History = new G3_Measure_Temperature();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.Temperature     = item.Temperature;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.Temperature     = item.Temperature;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.Temperature = History;
                }
            }
            using (Pulse db = new Pulse())
            {
                int number = 1;
                var reuslt = db.G3_Measure_Pulse.ToList();
                G3_Measure_Pulse History = new G3_Measure_Pulse();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.Pulse           = item.Pulse;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.Pulse           = item.Pulse;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.Pulse = History;
                }
            }

            Healthy.HealthyInformation = C;
            Healthy.Total = C.ABG.Score + C.BloodGlucose.Score + C.BloodPressure.Score + C.BMI.Score +
                            C.Air.Score + C.GSR.Score + C.GyroValues.Score + C.Pulse.Score +
                            C.Temperature.Score;

            D.UserHealthy = Healthy;

            ViewBag.Message = "新增建議";
            return(View(D));
        }