Skip to content

Commit

Permalink
Merge pull request #1 from GuttiDK/develop
Browse files Browse the repository at this point in the history
Version 0.0.3 (28/09/2023)
  • Loading branch information
GuttiDK authored Sep 28, 2023
2 parents b818544 + 156e113 commit 4ddcc22
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 60 deletions.
40 changes: 40 additions & 0 deletions Pages/DeleteToDoList.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@page
@using TheTodoService.DataTransferObjects;
@model TheTodoWeb.Pages.DeleteToDoListModel
@{
ViewData["Title"] = "ToDoList";
}

<h3>Delete Completed Tasks</h3>

<hr />

<table class="table table-hover">
<thead>
<tr>
<th>Id</th>
<th>Description</th>
<th>Created Time</th>
<th>IsCompleted</th>
<th>Priory</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (ToDoItemDto item in Model.ToDoItems)
{
<tr>
<td>@item.Id</td>
<td>@item.TaskDescription</td>
<td>@item.CreatedTime</td>
<td>@item.IsCompleted</td>
<td>@item.Priority</td>
<td>
<form asp-page-handler="Delete" asp-route-id="@item.Id" method="post">
<button class="btn btn-default">Delete</button>
</form>
</td>
</tr>
}
</tbody>
</table>
44 changes: 44 additions & 0 deletions Pages/DeleteToDoList.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Collections.ObjectModel;
using TheTodoRepository.Models;
using TheTodoService.DataTransferObjects;
using TheTodoService.Interfaces;

namespace TheTodoWeb.Pages
{
public class DeleteToDoListModel : PageModel
{

private readonly IToDoItemService _toDoItemService;

public ObservableCollection<ToDoItemDto> ToDoItems = new();

public DeleteToDoListModel(IToDoItemService toDoItemService)
{
_toDoItemService = toDoItemService;
}

public async Task<IActionResult> OnGet()
{
ToDoItems = await _toDoItemService.GetAllCompletedAsync();

return Page();
}

public async Task<IActionResult> OnPostDelete(Guid id)
{
if (ModelState.IsValid)
{
ToDoItemDto toDoItemDto = await _toDoItemService.GetByIDAsync(id);

if (toDoItemDto != null)
{
await _toDoItemService.DeleteAsync(toDoItemDto);
}
}

return RedirectToPage("DeleteToDoList");
}
}
}
4 changes: 4 additions & 0 deletions Pages/EditToDoList.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@page
@model TheTodoWeb.Pages.EditToDoListModel
@{
}
35 changes: 35 additions & 0 deletions Pages/EditToDoList.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using TheTodoService.DataTransferObjects;
using TheTodoService.Interfaces;

namespace TheTodoWeb.Pages
{
public class EditToDoListModel : PageModel
{
private readonly LinkGenerator linkGenerator;
private readonly IToDoItemService _toDoItemService;

public EditToDoListModel(LinkGenerator linkGenerator, IToDoItemService toDoItemService)
{
this.linkGenerator = linkGenerator;
_toDoItemService = toDoItemService;
}

public async Task OnGetAsync(Guid guid)
{
string guid1 = linkGenerator.GetPathByRouteValues(HttpContext, "EditToDoList", new { guid });

if (guid != null)
{
ToDoItemDto toDoItemDto = await _toDoItemService.GetByIDAsync(guid);
if (toDoItemDto != null)
{
}
}

}


}
}
5 changes: 5 additions & 0 deletions Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@ public void OnGet()
{

}

public IActionResult OnPost()
{
return RedirectToPage("ToDoList");
}
}
}
35 changes: 6 additions & 29 deletions Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<!DOCTYPE html>
@using TheTodoService.Enums;
@using TheTodoService.Interfaces;


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - Todo List</title>
<title>@ViewData["Title"] - TheTodoRazerApp</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/TheTodoRazerApp.styles.css" asp-append-version="true" />
Expand All @@ -22,12 +26,6 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" data-bs-toggle="offcanvas" href="#offcanvasExample" role="button" aria-controls="offcanvasExample">Create</a>
</li>
</ul>
</div>
</div>
Expand All @@ -36,27 +34,6 @@
<div class="container">
<main role="main" class="pb-3">
@RenderBody()

<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasExampleLabel">Offcanvas</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div>
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
</div>
<div class="dropdown mt-3">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
Dropdown button
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
</ul>
</div>
</div>
</div>

</main>
</div>

Expand Down
70 changes: 55 additions & 15 deletions Pages/ToDoList.cshtml
Original file line number Diff line number Diff line change
@@ -1,32 +1,72 @@
@page
@page
@using TheTodoService.DataTransferObjects;
@using TheTodoService.Enums;
@model TheTodoWeb.Pages.ToDoListModel
@{
ViewData["Title"] = "ToDoList";
}

<h3>ToDoList</h3>

<a class="btn btn-primary" data-bs-toggle="offcanvas" href="#offcanvasExample" role="button" aria-controls="offcanvasExample">Create</a>
<hr />

<table class="table">
<thread>
<table class="table table-hover">
<thead>
<tr>
<th>Id</th>
<th>Description</th>
<th>Created Time</th>
<th>IsCompleted</th>
<th>Created</th>
<th>Completed</th>
<th>Priory</th>
<th>Actions</th>
</tr>
</thread>
</thead>
<tbody>
@foreach (var item in Model.ToDoItems)
@foreach (ToDoItemDto item in Model.ToDoItems)
{
<tr>
<td>@item.Id</td>
<td>@item.TaskDescription</td>
<td>@item.CreatedTime</td>
<td>@item.IsCompleted</td>
<td>@item.Priority</td>
</tr>
<tr>
<td>@item.Id</td>
<td>@item.TaskDescription</td>
<td>@item.CreatedTime</td>
<td>@item.IsCompleted</td>
<td>@item.Priority</td>
<td>
<a class="btn btn-primary" asp-page="EditToDoList" asp-route-id="@item.Id">Edit</a>
<form method="post" asp-page-handler="Completed" asp-route-id="@item.Id"><a class="btn btn-danger" asp-route-id="@item.Id">Complete</a></form>
<button ></button>
</td>
</tr>
}
</tbody>
</table>


<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasExampleLabel">Offcanvas</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div>
Here can you create a new todo item.
<hr />
</div>
<form method="post" asp-page-handler="CreateTask">
<div class="input-group mb-3">
<span class="input-group-text" id="inputGroup-sizing-default">Description</span>
<input type="text" class="form-control" asp-for="Description" id="description" name="description">
</div>

<div class="input-group mb-3">
<label class="input-group-text" for="inputGroupSelect01">Priority</label>
<select class="form-select" asp-for="PriorityForm" name="priorityForm">
@foreach (PrioryEnumDto priorityEnum in Enum.GetValues(typeof(PrioryEnumDto)))
{
<option value="@priorityEnum">@priorityEnum</option>
}
</select>
</div>
<button class="btn btn-primary" type="submit">Button</button>
</form>
</div>
</div>
56 changes: 54 additions & 2 deletions Pages/ToDoList.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
using TheTodoRepository.Enums;
using TheTodoService.DataTransferObjects;
using TheTodoService.Enums;
using TheTodoService.Interfaces;

namespace TheTodoWeb.Pages
Expand All @@ -9,16 +14,63 @@ public class ToDoListModel : PageModel
{
private readonly IToDoItemService _toDoItemService;

public List<ToDoItemDto> ToDoItems = new();
public ObservableCollection<ToDoItemDto> ToDoItems = new();

[BindProperty]
public string Description { get; set; }
[BindProperty]
public PrioryEnum PriorityForm { get; set; }


public ToDoListModel(IToDoItemService toDoItemService)
{
_toDoItemService = toDoItemService;
}

public async Task OnGet()
public async Task<IActionResult> OnGet()
{
ToDoItems = await _toDoItemService.GetAllAsync();

return Page();
}

public async Task<IActionResult> OnPostCompleted(Guid id)
{
if (ModelState.IsValid)
{
ToDoItemDto toDoItemDto = await _toDoItemService.GetByIDAsync(id);

if (toDoItemDto != null)
{
toDoItemDto.IsCompleted = true;

await _toDoItemService.UpdateAsync(toDoItemDto);
}
}

return RedirectToPage("ToDoList");
}

public async Task<IActionResult> OnPostCreateTask()
{
if (ModelState.IsValid)
{
if (Description != null)
{
ToDoItemDto toDoItemDto = new ToDoItemDto
{
Id = Guid.NewGuid(),
TaskDescription = Description,
CreatedTime = DateTime.Now,
IsCompleted = false,
Priority = PriorityForm
};

await _toDoItemService.CreateAsync(toDoItemDto);
}
}

return RedirectToPage("ToDoList");
}
}
}
Loading

0 comments on commit 4ddcc22

Please sign in to comment.