Spontaneous.WebApp.Services.UserProfileFacade.UpdateCarbsInLastMeal C# (CSharp) Метод

UpdateCarbsInLastMeal() приватный Метод

private UpdateCarbsInLastMeal ( string restaurnatId, int menuPartId, int dishId, double totalCarbohydrate ) : bool
restaurnatId string
menuPartId int
dishId int
totalCarbohydrate double
Результат bool
        internal bool UpdateCarbsInLastMeal(string restaurnatId, int menuPartId, int dishId, double totalCarbohydrate)
        {
            var userProfile = GetUserProfile();
            var userData = userProfile.GetUserData();
            if (userData.UserMeals == null)
            {
                log.WarnFormat("[UpdateCarbsInLastMeal] User={0} tried to update postmeal sugar, but meal doesn't exists.", userProfile.UserName);
                return false;
            }

            var userMeal = userData.UserMeals.OrderByDescending(c => c.CreatedAt).ToList().FirstOrDefault();
            bool updateFlag = false;
            if(restaurnatId == userMeal.RestaurantId)
            {
                foreach (var portion in userMeal.Portions)
                {
                    if (portion.MenuPartId == menuPartId && portion.PrtionFrom.Id == dishId)
                    {
                        portion.CarbAmount = totalCarbohydrate;
                        updateFlag = true;
                    }
                }
            }

            if (updateFlag)
            {
                userProfile.SetUserData(userData);
                userProfile.Save();
                log.InfoFormat("[UpdateCarbsInLastMeal] user={0}, restaurnatId={1}, menuPartId={2}, dishId={3}, totalCarbohydrate={4}.", userProfile.UserName, restaurnatId, menuPartId, dishId, totalCarbohydrate);
                return true;
            }
            else
            {
                log.WarnFormat("[UpdateCarbsInLastMeal] Was unsuccessful. Incorrect meal. user={0}, restaurnatId={1}, menuPartId={2}, dishId={3}, totalCarbohydrate={4}.", userProfile.UserName, restaurnatId, menuPartId, dishId, totalCarbohydrate);
                return false;
            }
        }