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.

26 changes: 0 additions & 26 deletions Program.cs

This file was deleted.

55 changes: 0 additions & 55 deletions Startup.cs

This file was deleted.

18 changes: 18 additions & 0 deletions TodoApi.BLL/Extensions/MappingProfiles/TodoItemMappingProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using AutoMapper;
using TodoApi.BLL.Models;
using TodoApi.DAL.Models;

namespace TodoApi.BLL.Extensions.MappingProfiles;

public class TodoItemMappingProfile : Profile
{
public TodoItemMappingProfile()
{
CreateMap<TodoItemDto, TodoItemEntity>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.IsComplete, opt => opt.MapFrom(src => src.IsComplete))
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
.ForMember(dest => dest.Secret, opt => opt.Ignore())
.ReverseMap();
}
}
17 changes: 17 additions & 0 deletions TodoApi.BLL/Extensions/StartupExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TodoApi.BLL.Extensions.MappingProfiles;
using TodoApi.BLL.Services;
using TodoApi.BLL.Services.Contracts;

namespace TodoApi.BLL.Extensions;

public static class StartupExtension
{
public static void AddBLLServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddScoped<IServiceTodoItem, ServiceTodoItem>();

services.AddAutoMapper(typeof(TodoItemMappingProfile));
}
}
9 changes: 5 additions & 4 deletions Models/TodoItemDTO.cs → TodoApi.BLL/Models/TodoItemDTO.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
namespace TodoApi.Models
namespace TodoApi.BLL.Models
{
#region snippet
public class TodoItemDTO
public class TodoItemDto
{

public long Id { get; set; }

public string Name { get; set; }

public bool IsComplete { get; set; }
}
#endregion
}
16 changes: 16 additions & 0 deletions TodoApi.BLL/Services/Contracts/IServiceTodoItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using TodoApi.BLL.Models;

namespace TodoApi.BLL.Services.Contracts;

public interface IServiceTodoItem
{
public Task<IEnumerable<TodoItemDto>> GetTodoItems();

public Task<TodoItemDto?> GetTodoItemById(long id);

public Task<bool> UpdateTodoItem(TodoItemDto todoItemDto);

public Task<TodoItemDto> CreateTodoItem(TodoItemDto todoItemDto);

public Task<bool> DeleteTodoItem(long id);
}
50 changes: 50 additions & 0 deletions TodoApi.BLL/Services/ServiceTodoItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using AutoMapper;
using TodoApi.BLL.Models;
using TodoApi.BLL.Services.Contracts;
using TodoApi.DAL.Models;
using TodoApi.DAL.Repositories.Contracts;

namespace TodoApi.BLL.Services;

public class ServiceTodoItem : IServiceTodoItem
{
private readonly IRepository<TodoItemEntity> _repository;
private readonly IMapper _mapper;

public ServiceTodoItem(IRepository<TodoItemEntity> repository, IMapper mapper)
{
_repository = repository;
_mapper = mapper;
}

public async Task<IEnumerable<TodoItemDto>> GetTodoItems()
{
var todoItems = await _repository.GetAll();

return todoItems.Select(i => _mapper.Map<TodoItemDto>(i)).ToList();
}

public async Task<TodoItemDto?> GetTodoItemById(long id)
{
var todoItem = await _repository.GetById(id);

return _mapper.Map<TodoItemDto>(todoItem);
}

public async Task<bool> UpdateTodoItem(TodoItemDto todoItemDto)
{
return await _repository.Update(_mapper.Map<TodoItemEntity>(todoItemDto));
}

public async Task<TodoItemDto> CreateTodoItem(TodoItemDto todoItemDto)
{
var createdItem = await _repository.Create(_mapper.Map<TodoItemEntity>(todoItemDto));

return _mapper.Map<TodoItemDto>(createdItem);
}

public async Task<bool> DeleteTodoItem(long id)
{
return await _repository.Delete(id);
}
}
19 changes: 19 additions & 0 deletions TodoApi.BLL/TodoApi.BLL.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\TodoApi.DAL\TodoApi.DAL.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
</ItemGroup>

</Project>
Loading