Skip to content

Commit

Permalink
Include Report generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Binara-Sachin committed Jul 27, 2023
1 parent 47b3511 commit 2e6a26e
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 8 deletions.
Binary file modified .vs/FitnessPro/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/FitnessPro/v17/.suo
Binary file not shown.
74 changes: 74 additions & 0 deletions FitnessProWebApp/Controllers/ReportController.cs
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();
}


}
}
}
15 changes: 15 additions & 0 deletions FitnessProWebApp/Models/Report.cs
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;
}
}
4 changes: 4 additions & 0 deletions FitnessProWebApp/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
<a asp-controller="Workout" asp-action="Create" class="btn btn-primary btn-lg">Add Workout</a>
<a asp-controller="CheatMeal" asp-action="Create" class="btn btn-primary btn-lg">Add Cheat Meal</a>
</div>
<br />
<div class="col text-center">
<a asp-controller="Report" asp-action="Generate" class="btn btn-primary btn-lg">Generate Report</a>
</div>
</div>
56 changes: 56 additions & 0 deletions FitnessProWebApp/Views/Report/Generate.cshtml
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" />
}
}

9 changes: 3 additions & 6 deletions FitnessProWebApp/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@
</button>
<div class="collapse navbar-collapse" id="navbarColor01">
<ul class="navbar-nav me-auto">
@* <li class="nav-item">
<a class="nav-link active" href="#">
Home
<span class="visually-hidden">(current)</span>
</a>
</li>*@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
Expand All @@ -36,6 +30,9 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="CheatMeal" asp-action="Index">Cheat Meals</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Report" asp-action="Generate">Report</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="About">About</a>
</li>
Expand Down
Binary file modified FitnessProWebApp/bin/Debug/net6.0/FitnessProWebApp.dll
Binary file not shown.
Binary file modified FitnessProWebApp/bin/Debug/net6.0/FitnessProWebApp.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ build_metadata.AdditionalFiles.CssScope =
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcSG9tZVxJbmRleC5jc2h0bWw=
build_metadata.AdditionalFiles.CssScope =

[D:/Projects/DotNetDev/Projects/FitnessPro/FitnessProWebApp/Views/Report/Generate.cshtml]
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcUmVwb3J0XEdlbmVyYXRlLmNzaHRtbA==
build_metadata.AdditionalFiles.CssScope =

[D:/Projects/DotNetDev/Projects/FitnessPro/FitnessProWebApp/Views/Shared/Error.cshtml]
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcU2hhcmVkXEVycm9yLmNzaHRtbA==
build_metadata.AdditionalFiles.CssScope =
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5340cba8358a9c88e1d370c91dbeeef55c20db42
6667b2f2788d4f6e9b490f2198e5d5c308c0d768
Binary file modified FitnessProWebApp/obj/Debug/net6.0/FitnessProWebApp.dll
Binary file not shown.
Binary file modified FitnessProWebApp/obj/Debug/net6.0/FitnessProWebApp.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion FitnessProWebApp/obj/Debug/net6.0/project.razor.vs.json

Large diffs are not rendered by default.

Binary file modified FitnessProWebApp/obj/Debug/net6.0/ref/FitnessProWebApp.dll
Binary file not shown.
Binary file modified FitnessProWebApp/obj/Debug/net6.0/refint/FitnessProWebApp.dll
Binary file not shown.

0 comments on commit 2e6a26e

Please sign in to comment.