Skip to content

Commit ae864aa

Browse files
Abu MaryamAbu Maryam
Abu Maryam
authored and
Abu Maryam
committed
Add project files.
1 parent f38af80 commit ae864aa

File tree

97 files changed

+75746
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+75746
-0
lines changed

ToDoList.DAL/AppDbContext.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using ToDoList.Domain.Entities;
8+
9+
namespace ToDoList.DAL;
10+
11+
public class AppDbContext : DbContext
12+
{
13+
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
14+
{
15+
Database.EnsureCreated();
16+
}
17+
18+
public DbSet<TaskEntity> Tasks { get; set; }
19+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ToDoList.DAL.Interfaces;
8+
9+
public interface IBaseRepository<T>
10+
{
11+
Task Create(T entity);
12+
IQueryable<T> GetAll();
13+
Task Delete(T entity);
14+
Task<T> Update(T entity);
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using ToDoList.DAL.Interfaces;
7+
using ToDoList.Domain.Entities;
8+
using ToDoList.Domain.Response;
9+
10+
namespace ToDoList.DAL.Repositories;
11+
12+
public class TaskRepository : IBaseRepository<TaskEntity>
13+
{
14+
private readonly AppDbContext _appDbContext;
15+
public TaskRepository(AppDbContext appDbContext)
16+
{
17+
_appDbContext = appDbContext;
18+
}
19+
public async Task Create(TaskEntity entity)
20+
{
21+
await _appDbContext.Tasks.AddAsync(entity);
22+
await _appDbContext.SaveChangesAsync();
23+
}
24+
25+
public async Task Delete(TaskEntity entity)
26+
{
27+
_appDbContext.Tasks.Remove(entity);
28+
await _appDbContext.SaveChangesAsync();
29+
}
30+
31+
public IQueryable<TaskEntity> GetAll()
32+
{
33+
return _appDbContext.Tasks;
34+
}
35+
36+
public async Task<TaskEntity> Update(TaskEntity entity)
37+
{
38+
_appDbContext.Tasks.Update(entity);
39+
await _appDbContext.SaveChangesAsync();
40+
41+
return entity;
42+
}
43+
}

ToDoList.DAL/ToDoList.DAL.csproj

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.19" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\ToDoList.Domain\ToDoList.Domain.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using ToDoList.Domain.Enums;
7+
8+
namespace ToDoList.Domain.Entities;
9+
10+
public class TaskEntity
11+
{
12+
public long Id { get; set; }
13+
public string Name { get; set; }
14+
public string Description { get; set; }
15+
public DateTime CreatedAt { get; set; }
16+
public Priority Priority { get; set; }
17+
public bool IsDone { get; set; }
18+
}

ToDoList.Domain/Enums/Priority.cs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace ToDoList.Domain.Enums;
9+
10+
public enum Priority
11+
{
12+
[Display(Name = "Простая")]
13+
Easy = 1,
14+
[Display(Name = "Важная")]
15+
Medium = 2,
16+
[Display(Name = "Критичная")]
17+
Hard = 3
18+
}

ToDoList.Domain/Enums/StatusCode.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ToDoList.Domain.Enums;
8+
9+
public enum StatusCode
10+
{
11+
TaskAlreadyCreated = 1,
12+
TaskNotFound = 2,
13+
OK = 200,
14+
InternalServerError = 500
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Reflection.Metadata.Ecma335;
7+
using System.Runtime.CompilerServices;
8+
using System.Runtime.InteropServices;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
12+
namespace ToDoList.Domain.Extensions
13+
{
14+
public static class EnumExtension
15+
{
16+
public static string GetDisplayName(this System.Enum enumValue)
17+
{
18+
return enumValue.GetType()
19+
.GetMember(enumValue.ToString())
20+
.First()
21+
.GetCustomAttribute<DisplayAttribute>()
22+
?.GetName() ?? "Неопределенный";
23+
}
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Linq.Expressions;
5+
using System.Runtime.CompilerServices;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace ToDoList.Domain.Extensions;
10+
11+
public static class QueryExtension
12+
{
13+
public static IQueryable<T> WhereIf<T>(this IQueryable<T> source, bool condition,
14+
Expression<Func<T, bool>> predicate)
15+
{
16+
if (condition)
17+
return source.Where(predicate);
18+
return source;
19+
}
20+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ToDoList.Domain.Filters;
8+
9+
public class PagingFIlter
10+
{
11+
public int PageSize { get; set; }
12+
public int Skip { get; set; }
13+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using ToDoList.Domain.Enums;
7+
8+
namespace ToDoList.Domain.Filters.Task;
9+
10+
public class TaskFilter : PagingFIlter
11+
{
12+
public string Name { get; set; }
13+
public Priority? Priority { get; set; }
14+
}
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using CsvHelper;
2+
using CsvHelper.Configuration;
3+
using System;
4+
using System.Collections;
5+
using System.Collections.Generic;
6+
using System.Globalization;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace ToDoList.Domain.Helpers;
12+
13+
public class CsvBaseService<T>
14+
{
15+
private readonly CsvConfiguration _configuration;
16+
public CsvBaseService()
17+
{
18+
_configuration = GetConfiguration();
19+
}
20+
21+
22+
public byte[] UploadFile(IEnumerable data)
23+
{
24+
using (var stream = new MemoryStream())
25+
{
26+
using (var streamWriter = new StreamWriter(stream))
27+
{
28+
using (var csvWriter = new CsvWriter(streamWriter, _configuration))
29+
{
30+
csvWriter.WriteRecords(data);
31+
streamWriter.Flush();
32+
return stream.ToArray();
33+
}
34+
}
35+
}
36+
}
37+
38+
public CsvConfiguration GetConfiguration()
39+
{
40+
return new CsvConfiguration(CultureInfo.InvariantCulture)
41+
{
42+
Delimiter = ",",
43+
Encoding = Encoding.UTF8,
44+
NewLine = "\r\n",
45+
};
46+
}
47+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using ToDoList.Domain.Enums;
8+
9+
namespace ToDoList.Domain.Response;
10+
11+
public class BaseResponse<T> : IBaseResponse<T>
12+
{
13+
public string Description { get; set; }
14+
public StatusCode StatusCode { get; set; }
15+
public T Data { get; set; }
16+
}
17+
18+
public interface IBaseResponse<T>
19+
{
20+
string Description { get; set; }
21+
StatusCode StatusCode { get; set; }
22+
T Data { get; set; }
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ToDoList.Domain.Response;
8+
9+
public class DataTableResult
10+
{
11+
public object Data { get; set; }
12+
public int Total { get; set; }
13+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="CsvHelper" Version="32.0.3" />
11+
</ItemGroup>
12+
13+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ToDoList.Domain.ViewModels.Task;
8+
9+
public class CompletedTaskViewModel
10+
{
11+
public long Id { get; set; }
12+
public string Name { get; set; }
13+
public string Description { get; set; }
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using ToDoList.Domain.Enums;
7+
8+
namespace ToDoList.Domain.ViewModels.Task;
9+
10+
public class CreateTaskViewModel
11+
{
12+
public string Name { get; set; }
13+
public string Description { get; set; }
14+
public Priority Priority { get; set; }
15+
16+
public void Validate()
17+
{
18+
if (string.IsNullOrWhiteSpace(Name))
19+
{
20+
throw new ArgumentNullException(Name, "enter name of the task");
21+
}
22+
if (string.IsNullOrWhiteSpace(Description))
23+
{
24+
throw new ArgumentNullException(Name, "enter description of the task");
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.ComponentModel.DataAnnotations;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using ToDoList.Domain.Enums;
9+
10+
namespace ToDoList.Domain.ViewModels.Task
11+
{
12+
public class TaskViewModel
13+
{
14+
public long Id { get; set; }
15+
[Display(Name = "Название")]
16+
public string Name { get; set; }
17+
[Display(Name = "Описание")]
18+
public string Description { get; set; }
19+
[Display(Name = "Дата создания")]
20+
public string CreatedAt { get; set; }
21+
[Display(Name = "Приоритет")]
22+
public string Priority { get; set; }
23+
[Display(Name = "Готовность")]
24+
public string IsDone { get; set; }
25+
}
26+
}

0 commit comments

Comments
 (0)