Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Exercisetracker.javedkhan2k2/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Exercisetracker.javedkhan2k2/bin/Debug/net8.0/Exercisetracker.javedkhan2k2.dll",
"args": [],
"cwd": "${workspaceFolder}/Exercisetracker.javedkhan2k2",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "externalTerminal",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
1 change: 1 addition & 0 deletions Exercisetracker.javedkhan2k2/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
41 changes: 41 additions & 0 deletions Exercisetracker.javedkhan2k2/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Exercisetracker.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/Exercisetracker.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/Exercisetracker.sln"
],
"problemMatcher": "$msCompile"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Exercisetacker.Controllers;
using System;
using System.Threading;
using System.Threading.Tasks;
using Exercisetacker.UI;

public class ConsoleAppService : IHostedService
{
private readonly IServiceProvider _serviceProvider;
private readonly IHostApplicationLifetime _appLifetime;

public ConsoleAppService(IServiceProvider serviceProvider, IHostApplicationLifetime appLifetime)
{
_serviceProvider = serviceProvider;
_appLifetime = appLifetime;
}

public async Task StartAsync(CancellationToken cancellationToken)
{
using (var scope = _serviceProvider.CreateScope())
{
var joggingController = scope.ServiceProvider.GetRequiredService<JoggingController>();

var menu = new Menu();
var runApplication = true;
while (runApplication)
{
Console.Clear();
var choice = menu.GetMainMenu();
switch (choice)
{
case "View All Sessions":
await joggingController.DisplayAllJoggingSessions();
break;
case "Add Jogging Session":
await joggingController.AddJogging();
break;
case "Update Jogging Session":
await joggingController.UpdateJogging();
break;
case "Delete Jogging Session":
await joggingController.DeleteJogging();
break;
case "Exit":
runApplication = false;
_appLifetime.StopApplication();
break;
default:
break;
}
}
}
await Task.CompletedTask;
}

public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


namespace Shiftlogger.UI.Constants;

public static class Messages
{
public static readonly string StartDateUpdate = "Do you want to Update Start Date and Time";
public static readonly string StartTime = "Enter Start date and time in [bold green](yyyy-MM-dd HH:mm:ss)[/] format.";
public static readonly string EndDateUpdate = "Do you want to Update End Date and Time";
public static readonly string EndTime = "Enter End date and time in [bold green](yyyy-MM-dd HH:mm:ss)[/] format.";
public static readonly string CommentsUpdate = "Do you want to Update Comments";
public static readonly string Comments = "Enter Comments for the Jogging Session";
public static readonly string TimeFormat = "yyyy-MM-dd HH:mm:ss";

internal static string GetCommentsUpdate(string comments) => $"{CommentsUpdate} [maroon]{comments}[/]?";

internal static object GetEndDateUpdate(DateTime dateEnd) => $"{EndDateUpdate} [maroon]{dateEnd}[/]?";

internal static object GetStartDateUpdate(DateTime dateStart) => $"{StartDateUpdate} [maroon]{dateStart}[/]?";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using Exercisetacker.Services.Interfaces;
using Exercisetacker.UI;

namespace Exercisetacker.Controllers;

public class JoggingController
{
private readonly IJoggingService _joggingService;

public JoggingController(IJoggingService joggingService)
{
_joggingService = joggingService;
}

public async Task DisplayAllJoggingSessions()
{
var joggings = await _joggingService.GetAllJoggings();
VisualizationEngine.DisplayAllJoggings(joggings, "Showing All Jogging Sessions");
VisualizationEngine.DisplayContinueMessage();
}

internal async Task AddJogging()
{
var jogging = UserInput.GetNewJogging();

if (jogging == null)
{
VisualizationEngine.DisplayCancelOperation();
return;
}

var addedjogging = await _joggingService.AddJogging(jogging);
if (addedjogging == null)
{
VisualizationEngine.DisplayFailureMessage("Jogging Session is not added to database.");
}
else
{
VisualizationEngine.DisplaySuccessMessage("Jogging Session is added to database successfully.");
}
}

internal async Task UpdateJogging()
{
var joggings = await _joggingService.GetAllJoggings();
VisualizationEngine.DisplayAllJoggings(joggings, "All Joggings Table");
int joggingId = UserInput.GetIntInput();
if(joggingId == 0)
{
VisualizationEngine.DisplayCancelOperation();
return;
}

var jogging = await _joggingService.GetJoggingById(joggingId);

if(jogging == null)
{
VisualizationEngine.DisplayFailureMessage($"Jogging with id: [green]{joggingId}[/] not found.");
return;
}

if(!UserInput.GetUpdateJogging(jogging))
{
VisualizationEngine.DisplayCancelOperation();
return;
}
if(await _joggingService.UpdateJogging(jogging) == 0)
{
VisualizationEngine.DisplayFailureMessage("Jogging is not updated.");
}
else
{
VisualizationEngine.DisplaySuccessMessage("Jogging is updated.");
}
}

internal async Task DeleteJogging()
{
var joggings = await _joggingService.GetAllJoggings();
VisualizationEngine.DisplayAllJoggings(joggings, "All Joggings Table");
int joggingId = UserInput.GetIntInput();
if(joggingId == 0)
{
VisualizationEngine.DisplayCancelOperation();
return;
}

var jogging = await _joggingService.GetJoggingById(joggingId);

if(jogging == null)
{
VisualizationEngine.DisplayFailureMessage($"Jogging with id: [green]{joggingId}[/] not found.");
return;
}

if(await _joggingService.DeleteJogging(jogging) == 0)
{
VisualizationEngine.DisplayFailureMessage("Jogging is not deleted.");
}
else
{
VisualizationEngine.DisplaySuccessMessage("Jogging is deleted.");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.ComponentModel.DataAnnotations;
using Exercisetacker.Entities;

namespace Exercisetacker.DTOs;

public class JoggingAddDto
{
public DateTime DateStart { get; set; }
public DateTime DateEnd {get;set;}
public TimeSpan Duration {get;set;}
public string Comments {get;set;}

public Jogging ToJogging()
{
return new Jogging
{
DateStart = this.DateStart,
DateEnd = this.DateEnd,
Duration = this.Duration,
Comments = this.Comments
};
}

}
Loading