public ActionResult <List <SearchStringActionDto> > GetAllSearchStringActions() { var actionList = _repository.GetAllSearchStringActions().Select(_mapper.Map <SearchStringActionDto>); return(Accepted(actionList)); }
public OverallReport CreateOverallReport() { var report = new OverallReport(); if (_userAccountActionsRepository .GetAllUserAccountActions().Any(accountAction => accountAction.ActionType == UserAccountActionType.AccountCreated) == true) { report.CreatedUserAccounts = _userAccountActionsRepository.GetAllUserAccountActions() .Where(accountAction => accountAction.ActionType == UserAccountActionType.AccountCreated).ToList() .Count; } if (_userAccountActionsRepository .GetAllUserAccountActions() .Any(accountAction => accountAction.ActionType == UserAccountActionType.SuccessfulLogonAttempt) == true) { report.TotalLogonCount = _userAccountActionsRepository.GetAllUserAccountActions() .Where(accountAction => accountAction.ActionType == UserAccountActionType.SuccessfulLogonAttempt) .ToList().Count; } if (_productActionsRepository .GetAllProductActions().Any(productAction => productAction.Action == ActionType.AddedNewProduct) == true) { report.AddedProducts = _productActionsRepository.GetAllProductActions() .Where(productAction => productAction.Action == ActionType.AddedNewProduct).ToList().Count; } if (_productActionsRepository.GetAllProductActions() .Where(productAction => productAction.Action == ActionType.RemovedProduct).ToList().Any() == true) { report.RemovedProducts = _productActionsRepository.GetAllProductActions() .Where(productAction => productAction.Action == ActionType.RemovedProduct).ToList().Count; } if (_planActionsRepository.GetAllDietPlanActions() .ToList().Any() == true) { report.AddedPlans = _planActionsRepository.GetAllDietPlanActions() .ToList().Count; } report.ProductsAddedToFav = _productActionsRepository .GetAllProductActions() .Count(productAction => productAction.Action == ActionType.ProductAddedToFavorites); report.ProductsRemovedFromFav = _productActionsRepository .GetAllProductActions() .Count(productAction => productAction.Action == ActionType.ProductRemovedFromFavorites); report.ProductsAddedToPlans = _planActionsRepository .GetAllProductInPlanActions() .Count(productInPlanAction => productInPlanAction.Action == ActionType.AddedProductToExistingDailyPlan); report.SearchesDone = _productActionsRepository .GetAllSearchValueActions().Count() + _productActionsRepository .GetAllSearchStringActions().Count(); if (_productActionsRepository .GetAllSearchStringActions().Any()) { report.TopStringSearch = _productActionsRepository.GetAllSearchStringActions() .GroupBy(x => x.SearchString) .Select(x => new { SearchString = x.Key, TimesAppeared = x.Count() }).ToList() .OrderByDescending(x => x.TimesAppeared).First().SearchString; } if (_productActionsRepository .GetAllSearchValueActions() .Any(action => action.SearchType == SearchActionType.SearchByCalories) == true) { report.AvgCaloriesSearch = Math.Round(_productActionsRepository.GetAllSearchValueActions() .Where(action => action.SearchType == SearchActionType.SearchByCalories).ToList() .Average(value => value.SearchValue), 2); } if (_productActionsRepository .GetAllSearchValueActions() .Any(action => action.SearchType == SearchActionType.SearchByCarbohydrates) == true) { report.AvgCarbohydratesSearch = Math.Round(_productActionsRepository.GetAllSearchValueActions() .Where(action => action.SearchType == SearchActionType.SearchByCarbohydrates).ToList() .Average(value => value.SearchValue), 2); } if (_productActionsRepository .GetAllSearchValueActions() .Any(action => action.SearchType == SearchActionType.SearchByFat) == true) { report.AvgFatSearch = Math.Round(_productActionsRepository.GetAllSearchValueActions() .Where(action => action.SearchType == SearchActionType.SearchByFat).ToList() .Average(value => value.SearchValue), 2); } if (_productActionsRepository .GetAllSearchValueActions() .Any(action => action.SearchType == SearchActionType.SearchByProtein) == true) { report.AvgProteinsSearch = Math.Round(_productActionsRepository.GetAllSearchValueActions() .Where(action => action.SearchType == SearchActionType.SearchByProtein).ToList() .Average(value => value.SearchValue), 2); } if (_productActionsRepository .GetAllProductActions() .Any(action => action.Action == ActionType.ProductAddedToFavorites) == true) { report.TopFavId = _productActionsRepository.GetAllProductActions() .Where(action => action.Action == ActionType.ProductAddedToFavorites) .GroupBy(action => action.ProductName) .Select(x => new { ProductName = x.Key, TimesAppeared = x.Count() }).ToList() .OrderByDescending(x => x.TimesAppeared).First().ProductName; } if (_planActionsRepository .GetAllBmiActions().Any() == true) { report.AvgUserBmi = Math.Round(_planActionsRepository.GetAllBmiActions() .ToList().Average(bmi => bmi.Bmi), 2); } if (_planActionsRepository .GetAllDietPlanActions() .Any(action => action.Action == ActionType.AddedDietPlan) == true) { report.AvgPlanLength = Math.Round(_planActionsRepository.GetAllDietPlanActions() .Where(action => action.Action == ActionType.AddedDietPlan).ToList() .Average(action => action.Length), 2); } if (_planActionsRepository .GetAllDietPlanActions() .Any(action => action.Action == ActionType.AddedDietPlan) == true) { report.AvgPlanCalories = Math.Round(_planActionsRepository.GetAllDietPlanActions() .Where(action => action.Action == ActionType.AddedDietPlan).ToList() .Average(action => action.CaloriesPerDay), 2); } return(report); }