internal HealthProfileModel RetrieveHealthProfile(string userId)
        {
            HealthProfileModel healthProfile = new HealthProfileModel();

            try
            {
                HealthProfile healthProfileDb = checkUpContext.HealthProfiles.Where(w => w.userId == userId).FirstOrDefault();
                healthProfile.Id = healthProfileDb.Id;
                healthProfile.dieaseNamesArray  = healthProfileDb.DieaseNames.Select(s => s.Name).ToList();
                healthProfile.isSTakeantiBiotic = healthProfileDb.isSTakeantiBiotic;
                healthProfile.isSuffreDiabetes  = healthProfileDb.isSuffreDiabetes;
                healthProfile.isSuffrePressure  = healthProfileDb.isSuffrePressure;
                healthProfile.isTakehaemophilia = healthProfileDb.isTakehaemophilia;
                healthProfile.userId            = userId;
            }
            catch (Exception ex)
            {
                healthProfile = null;
            }
            return(healthProfile);
        }
 public Response SaveAndUpdateHealthProfile([FromBody] HealthProfileModel healthProfile)
 {
     return(analysisManager.SaveAndUpdateHealthProfile(healthProfile));
 }
        internal Response SaveAndUpdateHealthProfile(HealthProfileModel healthProfile)
        {
            Response response = Response.Success;

            try
            {
                if (healthProfile.Id == 0)
                {
                    HealthProfile HealthProfileDB = new HealthProfile();
                    HealthProfileDB.isSTakeantiBiotic = healthProfile.isSTakeantiBiotic;
                    HealthProfileDB.isSuffreDiabetes  = healthProfile.isSuffreDiabetes;
                    HealthProfileDB.isSuffrePressure  = healthProfile.isSuffrePressure;
                    HealthProfileDB.isTakehaemophilia = healthProfile.isTakehaemophilia;
                    HealthProfileDB.userId            = healthProfile.userId;
                    HealthProfileDB.DieaseNames       = new List <DieaseName>();

                    for (int i = 0; i < healthProfile.dieaseNamesArray.Count; i++)
                    {
                        HealthProfileDB.DieaseNames.Add(new DieaseName()
                        {
                            Name = healthProfile.dieaseNamesArray[i]
                        });
                    }

                    checkUpContext.HealthProfiles.Add(HealthProfileDB);
                }
                else
                {
                    HealthProfile HealthProfileDB = checkUpContext.HealthProfiles.Where(w => w.Id == healthProfile.Id).FirstOrDefault();

                    if (HealthProfileDB != null)
                    {
                        HealthProfileDB.isSTakeantiBiotic = healthProfile.isSTakeantiBiotic;
                        HealthProfileDB.isSuffreDiabetes  = healthProfile.isSuffreDiabetes;
                        HealthProfileDB.isSuffrePressure  = healthProfile.isSuffrePressure;
                        HealthProfileDB.isTakehaemophilia = healthProfile.isTakehaemophilia;
                        HealthProfileDB.userId            = healthProfile.userId;

                        if (HealthProfileDB.DieaseNames == null)
                        {
                            HealthProfileDB.DieaseNames = new List <DieaseName>();
                        }
                        else
                        {
                            HealthProfileDB.DieaseNames.Clear();
                        }

                        for (int i = 0; i < healthProfile.dieaseNamesArray.Count; i++)
                        {
                            HealthProfileDB.DieaseNames.Add(new DieaseName()
                            {
                                Name = healthProfile.dieaseNamesArray[i]
                            });
                        }
                    }
                }
                checkUpContext.SaveChanges();
            }
            catch (Exception ex)
            {
                response = Response.Fail;
            }
            return(response);
        }