DB object for carbohydrates calculation algorithm
Inheritance: IEntity
        public void GetLastUserMealProfileByUserIdTest_ShouldReturnLastUserMealProfileSortedByDate()
        {
            string userName = Guid.NewGuid().ToString();
            UserMealProfile mealProfile1 = new UserMealProfile()
            {
                MealId = Guid.NewGuid(),
                UserName = userName,
                UserInsulinProfile = new RapidInsulinProfile() { InsulinCarbohydrateRatio = 40 },
                CalculatedCarbsDeviation = 30,
                CreatedAt = DateTime.Parse("01/02/2013")
            };

            UserMealProfile mealProfile2 = new UserMealProfile()
            {
                MealId = Guid.NewGuid(),
                UserName = userName,
                UserInsulinProfile = new RapidInsulinProfile() { InsulinCarbohydrateRatio = 40 },
                CalculatedCarbsDeviation = 30,
                CreatedAt = DateTime.Parse("02/03/2012")
            };

            //act
            string id1 = UserMealProfileUtilities.AddUserMealProfileToDB(mealProfile1);
            string id2 = UserMealProfileUtilities.AddUserMealProfileToDB(mealProfile2);
            UserMealProfile foundMealProfile = UserMealProfileUtilities.GetLastUserMealProfileByUserId(userName);

            //revome temp MealProfile from db
            UserMealProfileUtilities.RemoveUserMealProfile(id1);
            UserMealProfileUtilities.RemoveUserMealProfile(id2);

            //assert
            Assert.AreEqual(mealProfile1.MealId, foundMealProfile.MealId);
        }
        public void AddUserMealProfileToDBTest_ShouldSaveUserMealProfileInDBAndReturnId()
        {
            UserMealProfile mealProfile = new UserMealProfile()
            {
                MealId = Guid.NewGuid(),
                UserName = "******",
                UserInsulinProfile = new RapidInsulinProfile() { InsulinCarbohydrateRatio = 40 },
                CalculatedCarbsDeviation = 30
            };

            //act
            string id = UserMealProfileUtilities.AddUserMealProfileToDB(mealProfile);
            UserMealProfile savedMealProfile = UserMealProfileUtilities.GetUserMealProfileById(id);

            //revome temp MealProfile from db
            UserMealProfileUtilities.RemoveUserMealProfile(id);

            //assert
            Assert.IsNotNull(id);
            Assert.IsTrue(!string.IsNullOrEmpty(id));

            Assert.AreEqual(mealProfile.MealId, savedMealProfile.MealId);
            Assert.AreEqual(mealProfile.UserName, savedMealProfile.UserName);
            Assert.AreEqual(mealProfile.UserInsulinProfile.InsulinCarbohydrateRatio, savedMealProfile.UserInsulinProfile.InsulinCarbohydrateRatio);
            Assert.AreEqual(mealProfile.CalculatedCarbsDeviation, savedMealProfile.CalculatedCarbsDeviation);
        }
        public static string AddUserMealProfileToDB(UserMealProfile userMealProfile)
        {
            log.DebugFormat("[AddUserMealProfileToDB] restaurant={0}.", userMealProfile.ToString());
            using (Restaurants restaurantsDb = new Restaurants())
            {
                MongoEntityRepositoryBase<UserMealProfile> basicData =
                              new MongoEntityRepositoryBase<UserMealProfile>(restaurantsDb.DB);

                userMealProfile.CreatedAt = DateTime.UtcNow;
                basicData.Add(userMealProfile);
                return userMealProfile.Id.ToString();
            }
        }
        public UserMealProfile CreaeteFromMealAndUserData(Meal userMeal, string userName, SpontaneousUserModel userData)
        {
            log.InfoFormat("[CreaeteFromMealAndUserData] userMeal.Id={0}, userName={1}.", userMeal.Id.ToString(), userName);
            UserMealProfile mealProfile = new UserMealProfile()
            {
                MealId = userMeal.Id,
                UserName = userName,
                ExpectedCarbsAmount = userMeal.CarbAmount
            };

            if (userData.BaseInsulinCalcProfile != null)
            {
                mealProfile.UserInsulinProfile = userData.BaseInsulinCalcProfile;
                AlgorithmCalculations.AlgorithmResult algResult =  AlgorithmCalculations.CalcMealCarbsDeviation(userMeal, mealProfile.UserInsulinProfile);
                if (algResult.Status == "Success")
                {
                    mealProfile.CalculatedCarbsDeviation = algResult.Result;
                    mealProfile.MealCarbsAmount = mealProfile.ExpectedCarbsAmount + mealProfile.CalculatedCarbsDeviation;
                }
            }
            return mealProfile;
        }
 public static void UpdateUserMealProfile(UserMealProfile userMealProfile)
 {
     using (Restaurants restaurantsDb = new Restaurants())
     {
         MongoEntityRepositoryBase<UserMealProfile> basicData =
                       new MongoEntityRepositoryBase<UserMealProfile>(restaurantsDb.DB);
         basicData.Update(userMealProfile);
     }
 }