Commit ce19c171 authored by Mihkel Tiganik's avatar Mihkel Tiganik

Add project files.

parent 3931eb6c

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2020
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApp", "WebApp\WebApp.csproj", "{F09BFABA-1618-4E2D-BF1A-E87865EC415E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "Domain\Domain.csproj", "{C35026CC-0459-438B-903D-BD8CED09AA00}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DAL.App.EF", "DAL.App.EF\DAL.App.EF.csproj", "{219E9AF1-9630-4257-B783-3275761D9631}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DAL.App.Interfaces", "DAL.App.Interfaces\DAL.App.Interfaces.csproj", "{178BF3DA-A1FB-436E-A084-B7AB1FD6741D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DAL.EF", "DAL.EF\DAL.EF.csproj", "{485F7EE3-5FD9-4908-BF0D-1543BA9940AF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DAL.Interfaces", "DAL.Interfaces\DAL.Interfaces.csproj", "{3392DCCF-C3B3-4216-BF61-CBDF7BB98426}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F09BFABA-1618-4E2D-BF1A-E87865EC415E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F09BFABA-1618-4E2D-BF1A-E87865EC415E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F09BFABA-1618-4E2D-BF1A-E87865EC415E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F09BFABA-1618-4E2D-BF1A-E87865EC415E}.Release|Any CPU.Build.0 = Release|Any CPU
{C35026CC-0459-438B-903D-BD8CED09AA00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C35026CC-0459-438B-903D-BD8CED09AA00}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C35026CC-0459-438B-903D-BD8CED09AA00}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C35026CC-0459-438B-903D-BD8CED09AA00}.Release|Any CPU.Build.0 = Release|Any CPU
{219E9AF1-9630-4257-B783-3275761D9631}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{219E9AF1-9630-4257-B783-3275761D9631}.Debug|Any CPU.Build.0 = Debug|Any CPU
{219E9AF1-9630-4257-B783-3275761D9631}.Release|Any CPU.ActiveCfg = Release|Any CPU
{219E9AF1-9630-4257-B783-3275761D9631}.Release|Any CPU.Build.0 = Release|Any CPU
{178BF3DA-A1FB-436E-A084-B7AB1FD6741D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{178BF3DA-A1FB-436E-A084-B7AB1FD6741D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{178BF3DA-A1FB-436E-A084-B7AB1FD6741D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{178BF3DA-A1FB-436E-A084-B7AB1FD6741D}.Release|Any CPU.Build.0 = Release|Any CPU
{485F7EE3-5FD9-4908-BF0D-1543BA9940AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{485F7EE3-5FD9-4908-BF0D-1543BA9940AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{485F7EE3-5FD9-4908-BF0D-1543BA9940AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{485F7EE3-5FD9-4908-BF0D-1543BA9940AF}.Release|Any CPU.Build.0 = Release|Any CPU
{3392DCCF-C3B3-4216-BF61-CBDF7BB98426}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3392DCCF-C3B3-4216-BF61-CBDF7BB98426}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3392DCCF-C3B3-4216-BF61-CBDF7BB98426}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3392DCCF-C3B3-4216-BF61-CBDF7BB98426}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2B0B2AF9-2F42-4A04-AC05-287B706585A0}
EndGlobalSection
EndGlobal
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DAL.App.Interfaces\DAL.App.Interfaces.csproj" />
<ProjectReference Include="..\DAL.EF\DAL.EF.csproj" />
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL.App.Interfaces.Repositories;
using DAL.EF.Repositories;
using Domain;
using Microsoft.EntityFrameworkCore;
namespace DAL.App.EF.Repositories
{
public class AnimalTypeRepository : EFRepository<AnimalType>, IAnimalTypeRepository
{
// TODO: write constructor
public AnimalTypeRepository(DbContext dbContext) : base(dbContext)
{
}
public bool ExistsByPrimaryKey(int keyValue)
{
return RepositoryDbSet.Any(e => e.AnimalTypeId == keyValue);
}
public async Task<bool> ExistsByPrimaryKeyAsync(int keyValue)
{
return await RepositoryDbSet.AnyAsync(e => e.AnimalTypeId == keyValue);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL.App.Interfaces.Repositories;
using DAL.EF.Repositories;
using Domain;
using Microsoft.EntityFrameworkCore;
namespace DAL.App.EF.Repositories
{
public class CatRepository : EFRepository<Cat>, ICatRepository
{
public CatRepository(DbContext dbContext) : base(dbContext)
{
}
public override IEnumerable<Cat> All()
{
return RepositoryDbSet
.Include(c => c.AnimalType)
.Include(c => c.Customer)
.Include(c => c.PreviousLocation).ToList();
}
public override async Task<IEnumerable<Cat>> AllAsync()
{
return await RepositoryDbSet
.Include(c => c.AnimalType)
.Include(c => c.Customer)
.Include(c => c.PreviousLocation)
.ToListAsync();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL.App.Interfaces.Repositories;
using DAL.EF.Repositories;
using Domain;
using Microsoft.EntityFrameworkCore;
namespace DAL.App.EF.Repositories
{
public class CustomerRepository : EFRepository<Customer>, ICustomerRepository
{
public CustomerRepository(DbContext dbContext) : base(dbContext)
{
}
public bool ExistsByPrimaryKey(int keyValue)
{
return RepositoryDbSet.Any(e => e.CustomerId == keyValue);
}
public async Task<bool> ExistsByPrimaryKeyAsync(int keyValue)
{
return await RepositoryDbSet.AnyAsync(e => e.CustomerId == keyValue);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using DAL.App.Interfaces.Repositories;
using DAL.EF.Repositories;
using Domain;
using Microsoft.EntityFrameworkCore;
namespace DAL.App.EF.Repositories
{
public class PreviousLocationRepository : EFRepository<PreviousLocation>, IPreviousLocationRepository
{
public PreviousLocationRepository(DbContext dbContext) : base(dbContext)
{
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DAL.Interfaces\DAL.Interfaces.csproj" />
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Text;
namespace Domain
{
class IAppUnitOfWork
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using DAL.Interfaces.Repositories;
using Domain;
namespace DAL.App.Interfaces.Repositories
{
public interface IAnimalTypeRepository : IRepository<AnimalType>
{
bool ExistsByPrimaryKey(int keyValue);
Task<bool> ExistsByPrimaryKeyAsync(int keyValue);
}
}
using System;
using System.Collections.Generic;
using System.Text;
using DAL.Interfaces.Repositories;
using Domain;
namespace DAL.App.Interfaces.Repositories
{
public interface ICatRepository : IRepository<Cat>
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using DAL.Interfaces.Repositories;
using Domain;
namespace DAL.App.Interfaces.Repositories
{
public interface ICustomerRepository : IRepository<Customer>
{
bool ExistsByPrimaryKey(int keyValue);
Task<bool> ExistsByPrimaryKeyAsync(int keyValue);
}
}
using System;
using System.Collections.Generic;
using System.Text;
using DAL.Interfaces.Repositories;
using Domain;
namespace DAL.App.Interfaces.Repositories
{
public interface IPreviousLocationRepository : IRepository<PreviousLocation>
{
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DAL.Interfaces\DAL.Interfaces.csproj" />
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL.Interfaces.Repositories;
using Microsoft.EntityFrameworkCore;
namespace DAL.EF.Repositories
{
public class EFRepository<TEntity> : IRepository<TEntity> where TEntity : class
{
protected DbContext RepositoryDbContext;
protected DbSet<TEntity> RepositoryDbSet;
public EFRepository(DbContext dbContext)
{
RepositoryDbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
RepositoryDbSet = RepositoryDbContext.Set<TEntity>();
}
// virtual lets you override method
public virtual void Add(TEntity entity)
{
RepositoryDbSet.Add(entity);
}
public virtual async Task AddAsync(TEntity entity)
{
await RepositoryDbSet.AddAsync(entity);
}
public virtual IEnumerable<TEntity> All()
{
return RepositoryDbSet.ToList();
}
public virtual async Task<IEnumerable<TEntity>> AllAsync()
{
return await RepositoryDbSet.ToListAsync();
}
public virtual TEntity Find(params object[] id)
{
return RepositoryDbSet.Find(id);
}
public virtual async Task<TEntity> FindAsync(params object[] id)
{
return await RepositoryDbSet.FindAsync(id);
}
public virtual void Remove(TEntity entity)
{
RepositoryDbSet.Remove(entity);
}
public virtual void Remove(params object[] id)
{
Remove(Find(id));
}
public virtual TEntity Update(TEntity entity)
{
return RepositoryDbSet.Update(entity).Entity;
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace DAL.Interfaces.Repositories
{
public interface IRepository<TEntity> where TEntity : class
{
// provide basic crud functionality
IEnumerable<TEntity> All();
Task<IEnumerable<TEntity>> AllAsync();
TEntity Find(params object[] id); // Find(1) or Find(1,2,3,...)
Task<TEntity> FindAsync(params object[] id);
void Add(TEntity entity);
Task AddAsync(TEntity entity);
TEntity Update(TEntity entity);
void Remove(TEntity entity);
void Remove(params object[] id);
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Domain
{
public class AnimalType
{
public int AnimalTypeId { get; set; }
public string AnimalTypeName { get; set; }
public virtual List<Cat> Cats { get; set; } = new List<Cat>();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
namespace WebApp.Models
{
// Add profile data for application users by adding properties to the ApplicationUser class
public class ApplicationUser : IdentityUser
{
}
}
using System;
using System.ComponentModel.DataAnnotations;
namespace Domain
{
public class Cat
{
public int CatId { get; set; }
[MaxLength(100)]
public string CatName { get; set; }
[MaxLength(500)]
public string Description { get; set; }
[Display(Name = "Year")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy}", ApplyFormatInEditMode = true)]
public DateTime DateOfBirth { get; set; }
public int CustomerId { get; set; }
public Customer Customer { get; set; }
public int PreviousLocationId { get; set; }
public PreviousLocation PreviousLocation { get; set; }
public int AnimalTypeId { get; set; }
public AnimalType AnimalType { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Domain
{
public class Customer
{
public int CustomerId { get; set; }
[MaxLength(100)]
public string FirstName { get; set; }
[MaxLength(100)]
public string LastName { get; set; }
public virtual List<Cat> Cats { get; set; } = new List<Cat>();
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.0.1" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.4.1" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.ComponentModel.Annotations">
<HintPath>..\..\..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\System.ComponentModel.Annotations.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Helpers\" />
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Domain
{
public class PreviousLocation
{
public int PreviousLocationId { get; set; }
[MaxLength(100)]
public string PreviousLocationName { get; set; }
public virtual List<Cat> Cats { get; set; } = new List<Cat>();
}
}
This diff is collapsed.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Domain;
using WebApp.Data;
using DAL.App.EF.Repositories;
using DAL.App.Interfaces.Repositories;
namespace WebApp.Controllers
{
public class AnimalTypesController : Controller
{
private readonly ApplicationDbContext _context;
private readonly IAnimalTypeRepository _animalTypeRepository;
public AnimalTypesController(ApplicationDbContext context)
{
_animalTypeRepository = new AnimalTypeRepository(context);
_context = context;
}
// GET: AnimalTypes
public async Task<IActionResult> Index()
{
return View(await _animalTypeRepository.AllAsync());
}
// GET: AnimalTypes/Details/5
public async Task<IActionResult> Details(int? id)
{
if (id == null)
{
return NotFound();
}
// We don't need SingleOrDefaultAsync, because every element have unique ID
//var animalType = await _context.AnimalTypes
// .SingleOrDefaultAsync(m => m.AnimalTypeId == id);
var animalType = await _animalTypeRepository.FindAsync();
if (animalType == null)
{
return NotFound();
}
return View(animalType);
}
// GET: AnimalTypes/Create