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
116 changes: 0 additions & 116 deletions Controllers/TodoItemsController.cs

This file was deleted.

14 changes: 0 additions & 14 deletions Models/TodoContext.cs

This file was deleted.

12 changes: 0 additions & 12 deletions Models/TodoItem.cs

This file was deleted.

32 changes: 25 additions & 7 deletions TodoApiDTO.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30002.166
# Visual Studio Version 17
VisualStudioVersion = 17.2.32602.215
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoApiDTO", "TodoApiDTO.csproj", "{623124F9-F5BA-42DD-BC26-A1720774229C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoApiDTO", "VeletechToDoAPI\TodoApiDTO.csproj", "{F920CF77-6BD6-4DCB-A404-175B43E18CB1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TodoCore", "TodoCore\TodoCore.csproj", "{1F48623E-0BE5-4F33-9DA9-F0790EC2CD4A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TodoInfrastructure", "TodoInfrastructure\TodoInfrastructure.csproj", "{6F3C44A1-A612-474D-BDA9-5CD1167D77AA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TodoApplication", "TodoApplication\TodoApplication.csproj", "{45A28653-AC55-4F6D-B0B5-06DD69E6D563}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{623124F9-F5BA-42DD-BC26-A1720774229C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{623124F9-F5BA-42DD-BC26-A1720774229C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{623124F9-F5BA-42DD-BC26-A1720774229C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{623124F9-F5BA-42DD-BC26-A1720774229C}.Release|Any CPU.Build.0 = Release|Any CPU
{F920CF77-6BD6-4DCB-A404-175B43E18CB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F920CF77-6BD6-4DCB-A404-175B43E18CB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F920CF77-6BD6-4DCB-A404-175B43E18CB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F920CF77-6BD6-4DCB-A404-175B43E18CB1}.Release|Any CPU.Build.0 = Release|Any CPU
{1F48623E-0BE5-4F33-9DA9-F0790EC2CD4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F48623E-0BE5-4F33-9DA9-F0790EC2CD4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F48623E-0BE5-4F33-9DA9-F0790EC2CD4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F48623E-0BE5-4F33-9DA9-F0790EC2CD4A}.Release|Any CPU.Build.0 = Release|Any CPU
{6F3C44A1-A612-474D-BDA9-5CD1167D77AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F3C44A1-A612-474D-BDA9-5CD1167D77AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F3C44A1-A612-474D-BDA9-5CD1167D77AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F3C44A1-A612-474D-BDA9-5CD1167D77AA}.Release|Any CPU.Build.0 = Release|Any CPU
{45A28653-AC55-4F6D-B0B5-06DD69E6D563}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45A28653-AC55-4F6D-B0B5-06DD69E6D563}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45A28653-AC55-4F6D-B0B5-06DD69E6D563}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45A28653-AC55-4F6D-B0B5-06DD69E6D563}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
22 changes: 22 additions & 0 deletions TodoApplication/ApplicationCollectionExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.Extensions.DependencyInjection;
using TodoApplication.AutoMapperProfiles;
using TodoApplication.Services;
using TodoCore.Services;

namespace TodoApplication
{
public static class ApplicationCollectionExtension
{
public static IServiceCollection AddApplication(this IServiceCollection services)
{
services.AddTransient<IAddTodoItemService, AddTodoItemService>();
services.AddTransient<IGetTodoItemService, GetTodoItemService>();
services.AddTransient<IGetTodoItemsService, GetTodoItemsService>();
services.AddTransient<IDeleteTodoItemService, DeleteTodoItemService>();
services.AddTransient<IUpdateTodoItemService, UpdateTodoItemService>();

services.AddAutoMapper(typeof(TodoItemProfile));
return services;
}
}
}
16 changes: 16 additions & 0 deletions TodoApplication/AutoMapperProfiles/TodoItemProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using AutoMapper;
using TodoCore.Data.Entities;
using TodoCore.DTOs;

namespace TodoApplication.AutoMapperProfiles
{
public class TodoItemProfile : Profile
{
public TodoItemProfile()
{
CreateMap<TodoItem, TodoItemDTO>();
CreateMap<TodoItemDTO, TodoItem>();
}

}
}
27 changes: 27 additions & 0 deletions TodoApplication/Services/AddTodoItemService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using AutoMapper;
using System.Threading.Tasks;
using TodoCore.Data.Entities;
using TodoCore.Data.Interfaces;
using TodoCore.DTOs;
using TodoCore.Services;

namespace TodoApplication.Services
{
public class AddTodoItemService : IAddTodoItemService
{
private readonly IUnitOfWork _unitOfWork;
private readonly IMapper _mapper;
public AddTodoItemService(IUnitOfWork unitOfWork, IMapper mapper)
{
_unitOfWork = unitOfWork;
_mapper = mapper;
}

public Task AddTodoItemAsync(TodoItemDTO todoItemDTO)
{
var entity = _mapper.Map<TodoItem>(todoItemDTO);
_unitOfWork.TodoItemReposytory.Add(entity);
return _unitOfWork.SaveChangesAsync();
}
}
}
49 changes: 49 additions & 0 deletions TodoApplication/Services/DeleteTodoItemService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using AutoMapper;
using System;
using System.Threading.Tasks;
using TodoCore.Data.Entities;
using TodoCore.Data.Interfaces;
using TodoCore.DTOs;
using TodoCore.Exceptions;
using TodoCore.Services;

namespace TodoApplication.Services
{
public class DeleteTodoItemService : IDeleteTodoItemService
{
private readonly IUnitOfWork _unitOfWork;
private readonly IMapper _mapper;

public DeleteTodoItemService(IUnitOfWork unitOfWork, IMapper mapper)
{
_unitOfWork = unitOfWork;
_mapper = mapper;
}

public async Task<TodoItemDTO> DeleteTodoItemAsync(long id)
{
TodoItem todoItem;
try
{
todoItem = await _unitOfWork.TodoItemReposytory.GetByIdAsync(id);
}
catch(EntityNotFoundException<TodoItem> ex)
{
throw ex;
}
using var transaction = _unitOfWork.StartTransation();
try
{
_unitOfWork.TodoItemReposytory.Delete(todoItem);
await _unitOfWork.SaveChangesAsync();
transaction.Commit();
return _mapper.Map<TodoItemDTO>(todoItem);
}
catch(Exception ex)
{
transaction.Rollback();
throw new SomethingWentWrongException("Something went wrong while deleting todo item");
}
}
}
}
35 changes: 35 additions & 0 deletions TodoApplication/Services/GetTodoItemService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using AutoMapper;
using System.Threading.Tasks;
using TodoCore.Data.Entities;
using TodoCore.Data.Interfaces;
using TodoCore.DTOs;
using TodoCore.Exceptions;
using TodoCore.Services;

namespace TodoApplication.Services
{
internal class GetTodoItemService : IGetTodoItemService
{
private readonly ITodoItemRepository _todoItemReposytory;
private readonly IMapper _mapper;

public GetTodoItemService(ITodoItemRepository todoItemReposytory, IMapper mapper)
{
_todoItemReposytory = todoItemReposytory;
_mapper = mapper;
}

public async Task<TodoItemDTO> GetTodoItemAsync(long id)
{
try
{
var entity = await _todoItemReposytory.GetByIdAsync(id);
return _mapper.Map<TodoItemDTO>(entity);
}
catch(EntityNotFoundException<TodoItem> ex)
{
throw ex;
}
}
}
}
26 changes: 26 additions & 0 deletions TodoApplication/Services/GetTodoItemsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using AutoMapper;
using System.Collections.Generic;
using System.Threading.Tasks;
using TodoCore.Data.Interfaces;
using TodoCore.DTOs;
using TodoCore.Services;

namespace TodoApplication.Services
{
public class GetTodoItemsService : IGetTodoItemsService
{
private readonly ITodoItemRepository _todoItemReposytory;
private readonly IMapper _mapper;

public GetTodoItemsService(ITodoItemRepository todoItemReposytory, IMapper mapper)
{
_todoItemReposytory = todoItemReposytory;
_mapper = mapper;
}
public async Task<List<TodoItemDTO>> GetTodoItemsAsync()
{
var todoItems = await _todoItemReposytory.GetAllAsync();
return _mapper.Map<List<TodoItemDTO>>(todoItems);
}
}
}
Loading