-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47b3511
commit 2e6a26e
Showing
19 changed files
with
158 additions
and
8 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file renamed
BIN
+2.05 MB
...719c427-945b-4b30-a461-51db5dd41385.vsidx → ...a7a6c3d-e21e-49d0-8b29-79b8ee9cdeb1.vsidx
Binary file not shown.
Binary file added
BIN
+55.3 KB
.vs/FitnessPro/FileContentIndex/85b5aa30-cdb1-47a9-8790-d269c9c34acd.vsidx
Binary file not shown.
Binary file removed
BIN
-47.4 KB
.vs/FitnessPro/FileContentIndex/c4ecd980-83e0-4ab3-9917-0cdfaaacc855.vsidx
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using FitnessProWebApp.Models; | ||
using FitnessProWebApp.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Threading; | ||
|
||
namespace FitnessProWebApp.Controllers | ||
{ | ||
public class ReportController : Controller | ||
{ | ||
private IAPIClientService<CheatMeal> _iAPIClientServiceCheatMeal; | ||
private IAPIClientService<Workout> _iAPIClientServiceWorkout; | ||
|
||
public ReportController(IAPIClientService<CheatMeal> iAPIClientServiceCheatMeal, IAPIClientService<Workout> iAPIClientServiceWorkout) | ||
{ | ||
_iAPIClientServiceCheatMeal = iAPIClientServiceCheatMeal; | ||
_iAPIClientServiceWorkout = iAPIClientServiceWorkout; | ||
} | ||
|
||
public IActionResult Generate() | ||
{ | ||
return View(); | ||
} | ||
|
||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public async Task<IActionResult> Generate(Report report) | ||
{ | ||
try | ||
{ | ||
var cheatMeals = await _iAPIClientServiceCheatMeal.GetAll("CheatMeal"); | ||
var filteredCheatMeals = cheatMeals.Where(i => i.CreatedDate.Date >= report.StartDate && i.CreatedDate.Date <= report.EndDate).ToList(); | ||
|
||
var workouts = await _iAPIClientServiceWorkout.GetAll("Workout"); | ||
var filteredWorkouts = workouts.Where(i => i.CreatedDate.Date >= report.StartDate && i.CreatedDate.Date <= report.EndDate).ToList(); | ||
|
||
int caloriesBurned = 0; | ||
|
||
foreach (Workout e in filteredWorkouts) | ||
{ | ||
caloriesBurned += e.CaloriesBurned; | ||
} | ||
|
||
int caloriesGained = 0; | ||
|
||
foreach (CheatMeal e in filteredCheatMeals) | ||
{ | ||
caloriesGained += e.CaloriesGained; | ||
} | ||
|
||
int netCaloryBurn = caloriesBurned - caloriesGained; | ||
int weightDiff = (int)(netCaloryBurn * 0.45 * 1000 / 3500); | ||
|
||
report.data.Add("Number Of Workouts: ", filteredWorkouts.Count); | ||
report.data.Add("Number Of Cheat Meals: ", filteredCheatMeals.Count); | ||
report.data.Add("Total Calories Burned: ", caloriesBurned); | ||
report.data.Add("Total Calories Gained: ", caloriesGained); | ||
report.data.Add("Net Calories Burned(+)/Gained(-): ", netCaloryBurn); | ||
report.data.Add("Net Weight Loss(+)/Gain(-) in grams (g): ", weightDiff); | ||
|
||
report.generationComplete = true; | ||
|
||
TempData["success"] = "Report generated successfully"; | ||
return View(report); | ||
} | ||
catch (Exception ex) | ||
{ | ||
TempData["error"] = "Error occoured while generating the report"; | ||
return View(); | ||
} | ||
|
||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace FitnessProWebApp.Models | ||
{ | ||
public class Report | ||
{ | ||
[Required] | ||
public DateTime StartDate { get; set; } | ||
[Required] | ||
public DateTime EndDate { get; set; } | ||
public Dictionary<string, int> data { get; set; } = new Dictionary<string, int>(); | ||
public bool generationComplete { get; set; } = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
@using static FitnessProWebApp.Models.Report; | ||
@model Report | ||
|
||
@{ | ||
ViewData["Title"] = "Generate Report"; | ||
} | ||
|
||
<form method="post"> | ||
<fieldset> | ||
<div class="row pb-2"> | ||
<h2 class="text-primary">Generate Report</h2> | ||
<hr /> | ||
</div> | ||
<div asp-validation-summary="All"></div> | ||
<div class="form-group"> | ||
<label asp-for="StartDate"></label> | ||
<input asp-for="StartDate" class="form-control" textmode="DateTime" /> | ||
<span asp-validation-for="StartDate" class="text-danger"></span> | ||
</div> | ||
<br /> | ||
<div class="form-group"> | ||
<label asp-for="EndDate"></label> | ||
<input asp-for="EndDate" class="form-control" textmode="DateTime" /> | ||
<span asp-validation-for="EndDate" class="text-danger"></span> | ||
</div> | ||
<br /> | ||
<button type="submit" class="btn btn-primary">Generate</button> | ||
<a asp-controller="Home" asp-action="Index" class="btn btn-secondary">Back</a> | ||
</fieldset> | ||
</form> | ||
|
||
<br /> | ||
<br /> | ||
<br /> | ||
|
||
@if (Model != null && Model.generationComplete) | ||
{ | ||
<div class="card bg-secondary mb-3"> | ||
<div class="card-header">Report</div> | ||
<div class="card-body"> | ||
<h4 class="card-title">From @Model.StartDate , To @Model.EndDate</h4> | ||
<br /> | ||
@foreach (var item in Model.data) | ||
{ | ||
<p>@item.Key @item.Value</p> | ||
} | ||
</div> | ||
</div> | ||
} | ||
|
||
@section Scripts{ | ||
@{ | ||
<partial name="_ValidationScriptsPartial" /> | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
FitnessProWebApp/obj/Debug/net6.0/FitnessProWebApp.csproj.CoreCompileInputs.cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
5340cba8358a9c88e1d370c91dbeeef55c20db42 | ||
6667b2f2788d4f6e9b490f2198e5d5c308c0d768 |
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file modified
BIN
+3.5 KB
(110%)
FitnessProWebApp/obj/Debug/net6.0/refint/FitnessProWebApp.dll
Binary file not shown.