Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Access layer created #24

Merged
merged 2 commits into from
Feb 3, 2021
Merged
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
13 changes: 13 additions & 0 deletions OutOfSchool/.idea/.idea.OutOfSchool/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions OutOfSchool/.idea/.idea.OutOfSchool/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions OutOfSchool/.idea/.idea.OutOfSchool/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions OutOfSchool/.idea/.idea.OutOfSchool/.idea/riderModule.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions OutOfSchool/.idea/.idea.OutOfSchool/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions OutOfSchool/OutOfSchool.DataAccess/Enums/Gender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OutOfSchool.Services.Enums
{
public enum Gender
{
Male,
Female
}
}
11 changes: 11 additions & 0 deletions OutOfSchool/OutOfSchool.DataAccess/Enums/OrganisationType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace OutOfSchool.Services.Enums
{
public enum OrganisationType
{
FOP,
Social,
TOV,
Private,
EducationalInstitution
}
}
50 changes: 50 additions & 0 deletions OutOfSchool/OutOfSchool.DataAccess/Models/Organisation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#nullable enable
using System.ComponentModel.DataAnnotations;
using OutOfSchool.Services.Enums;

namespace OutOfSchool.Services.Models
{
public class Organisation : User
{
public long OrganisationId { get; set; }

[Required(ErrorMessage = "Title is required")]
[DataType(DataType.Text)]
public string Title { get; set; }

[DataType(DataType.Url)]
public string? Website { get; set; }

[DataType(DataType.Url)]
public string? Facebook { get; set; }

[DataType(DataType.Url)]
public string? Istagram { get; set; }

[MaxLength(750)]
[Required(ErrorMessage = "Description is required")]
public string Description { get; set; }

[Required(ErrorMessage = "MFO code is required")]
[MinLength(6, ErrorMessage = "MFO code should contain 6 digits")]
public string MFO { get; set; }

[Required(ErrorMessage = "EDRPOU code is required")]
[RegularExpression(@"^(\d{8}|\d{10})$",
ErrorMessage = "EDRPOU code should contain 8 or 10 digits")]
public string EDRPOU { get; set; }

[Required(ErrorMessage = "INPP code is required")]
[RegularExpression(@"^(\d{9}|\d{10}|\d{12})$",
ErrorMessage = "INPP code should contain 12, 10 or 9 digits")]
public string INPP { get; set; }

[DataType(DataType.ImageUrl)]
public byte[]? Image { get; set; }

[Required]
public OrganisationType Type { get; set; }


}
}
17 changes: 17 additions & 0 deletions OutOfSchool/OutOfSchool.DataAccess/Models/Parent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.ComponentModel.DataAnnotations;

namespace OutOfSchool.Services.Models
{
public class Parent : User
{
public long ParentId { get; set; }

[DataType(DataType.Text)]
[Required(ErrorMessage = "First name is required")]
public string FirstName { get; set; }

[DataType(DataType.Text)]
[Required(ErrorMessage = "Last name is required")]
public string LastName { get; set; }
}
}
38 changes: 38 additions & 0 deletions OutOfSchool/OutOfSchool.DataAccess/Models/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace OutOfSchool.Services.Models
{
public class User
{
public long UserId { get; set; }

[DataType(DataType.EmailAddress)]
[Required(ErrorMessage = "Email is required")]
public string Email { get; set; }

[DataType(DataType.PhoneNumber)]
[Required(ErrorMessage = "Phone number is required")]
[RegularExpression(@"([0-9]{3})([-]?)([0-9]{3})([-]?)([0-9]{2})([-]?)([0-9]{2})",
ErrorMessage = "Phone number format is incorrect. Example: XXX-XXX-XX-XX")]
public string Phone { get; set; }

[Required(ErrorMessage = "Password is required")]
[RegularExpression(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$",
ErrorMessage = "Password must contain at least one capital, number and symbol.")]
[DataType(DataType.Password)]
public string Password { get; set; }

[Required(ErrorMessage = "Password confirmation is required")]
[DataType(DataType.Password)]
[Compare("Password", ErrorMessage = "Passwords doesn't match")]
public string ConfirmPassword { get; set; }

[DataType(DataType.DateTime)]
public DateTime CreatingTime { get; set; }

[DataType(DataType.DateTime)]
public DateTime? LastLogin { get; set; }
}
}
17 changes: 17 additions & 0 deletions OutOfSchool/OutOfSchool.DataAccess/OutOfSchool.DataAccess.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>OutOfSchool.Services</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OutOfSchool.ApplicationCore\OutOfSchool.ApplicationCore.csproj" />
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore;
using OutOfSchool.Services.Models;

namespace OutOfSchool.Services
{
public class OutOfSchoolDbContext : DbContext
{
public OutOfSchoolDbContext(DbContextOptions<OutOfSchoolDbContext> options) : base(options)
{

}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(b => b.MigrationsAssembly("OutOfSchool.WebApi"));
}

public DbSet<Parent> Parents { get; set; }
public DbSet<Organisation> Organisations { get; set; }
}
}
3 changes: 2 additions & 1 deletion OutOfSchool/OutOfSchool.Tests/OrganizationControllerTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using OutOfSchool.Controllers;
using OutOfSchool.WebApi.Controllers;

namespace OutOfSchool.Tests
{
[TestFixture]
public class Tests
{
private readonly ILogger<OrganizationController> _logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace OutOfSchool.Controllers
namespace OutOfSchool.WebApi.Controllers
{
[ApiController]
[Route("[controller]")]
Expand Down
Loading