diff --git a/BL/BL.csproj b/BL/BL.csproj new file mode 100644 index 0000000..04bce3d --- /dev/null +++ b/BL/BL.csproj @@ -0,0 +1,57 @@ + + + + + Debug + AnyCPU + {E9E385E4-C36A-42B0-8424-BC2D075916F2} + Library + Properties + BL + BL + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + {b783887a-e5bb-4066-9b9b-abd7b4c1e269} + DAL + + + + \ No newline at end of file diff --git a/BL/Class1.cs b/BL/Class1.cs new file mode 100644 index 0000000..2b9e1f9 --- /dev/null +++ b/BL/Class1.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BL +{ + public class Class1 + { + } +} diff --git a/BL/DTOs/FoorumDTO.cs b/BL/DTOs/FoorumDTO.cs new file mode 100644 index 0000000..19307df --- /dev/null +++ b/BL/DTOs/FoorumDTO.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BL.DTOs +{ + public class FoorumDTO + { + public int FoorumId { get; set; } + public string Title { get; set; } + + } +} diff --git a/BL/DTOs/PostDTO.cs b/BL/DTOs/PostDTO.cs new file mode 100644 index 0000000..60ef9ec --- /dev/null +++ b/BL/DTOs/PostDTO.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BL.DTOs +{ + public class PostDTO + { + public int PostId { get; set; } + public string Title { get; set; } + + } +} diff --git a/BL/Interfaces/IFoorumService.cs b/BL/Interfaces/IFoorumService.cs new file mode 100644 index 0000000..d13dbc1 --- /dev/null +++ b/BL/Interfaces/IFoorumService.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BL.DTOs; + +namespace BL.Interfaces +{ + public interface IFoorumService + { + IEnumerable GetAll(); + FoorumDTO Get(int id); + void Add(FoorumDTO foorum); + void Update(FoorumDTO foorum); + void Hide(int id); + void Delete(int id); + void AddPost(int id, PostDTO post); + + IEnumerable SearchFoorumTitle(string query); + IEnumerable SearchFoorumAuthor(string query); + IEnumerable SearchPostAuthor(string query); + + } +} diff --git a/BL/Properties/AssemblyInfo.cs b/BL/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4a3a34d --- /dev/null +++ b/BL/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("BL")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("BL")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e9e385e4-c36a-42b0-8424-bc2d075916f2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/BL/Services/FoorumService.cs b/BL/Services/FoorumService.cs new file mode 100644 index 0000000..b62a85b --- /dev/null +++ b/BL/Services/FoorumService.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BL.DTOs; +using BL.Interfaces; +using DAL.Interfaces; + +namespace BL.Services +{ + public class FoorumService : IFoorumService + { + private IFoorumRepository _foorumRepository; + public FoorumService(IFoorumRepository foorumRepository) + { + _foorumRepository = foorumRepository; + } + public void Add(FoorumDTO foorum) + { + throw new NotImplementedException(); + } + + public void AddPost(int id, PostDTO post) + { + throw new NotImplementedException(); + } + + public void Delete(int id) + { + throw new NotImplementedException(); + } + + public FoorumDTO Get(int id) + { + throw new NotImplementedException(); + } + + public IEnumerable GetAll() + { + foreach (var f in _foorumRepository.GetAll()) + { + yield return new FoorumDTO() + { + FoorumId = f.FoorumId, + Title = f.Title + }; + } + + } + + public void Hide(int id) + { + throw new NotImplementedException(); + } + + public IEnumerable SearchFoorumAuthor(string query) + { + throw new NotImplementedException(); + } + + public IEnumerable SearchFoorumTitle(string query) + { + throw new NotImplementedException(); + } + + public IEnumerable SearchPostAuthor(string query) + { + throw new NotImplementedException(); + } + + public void Update(FoorumDTO foorum) + { + throw new NotImplementedException(); + } + } +} diff --git a/DAL/DAL.csproj b/DAL/DAL.csproj index 125f5c9..f3d1e71 100644 --- a/DAL/DAL.csproj +++ b/DAL/DAL.csproj @@ -52,11 +52,15 @@ + + + + + + - - - + diff --git a/DAL/Interfaces/IFoorumDbContext.cs b/DAL/Interfaces/IFoorumDbContext.cs index 362c8ec..6a02d02 100644 --- a/DAL/Interfaces/IFoorumDbContext.cs +++ b/DAL/Interfaces/IFoorumDbContext.cs @@ -1,6 +1,6 @@ namespace DAL.Interfaces { - interface IFoorumDbContext + public interface IFoorumDbContext { } diff --git a/DAL/Interfaces/IFoorumRepository.cs b/DAL/Interfaces/IFoorumRepository.cs new file mode 100644 index 0000000..37c0304 --- /dev/null +++ b/DAL/Interfaces/IFoorumRepository.cs @@ -0,0 +1,6 @@ +using DAL.Domain; + +namespace DAL.Interfaces +{ + public interface IFoorumRepository: IRepository { } +} diff --git a/DAL/Interfaces/IPostRepository.cs b/DAL/Interfaces/IPostRepository.cs new file mode 100644 index 0000000..907d93e --- /dev/null +++ b/DAL/Interfaces/IPostRepository.cs @@ -0,0 +1,6 @@ +using DAL.Domain; + +namespace DAL.Interfaces +{ + public interface IPostRepository: IRepository { } +} diff --git a/DAL/Interfaces/IRepository.cs b/DAL/Interfaces/IRepository.cs new file mode 100644 index 0000000..854fe0e --- /dev/null +++ b/DAL/Interfaces/IRepository.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; + + +namespace DAL.Interfaces +{ + public interface IRepository where T : class + { + T Add(T entity); + T Update(T entity); + void Delete(T entity); + void Delete(Expression> where); + T GetById(int id); + T Get(Expression> where); + IEnumerable GetAll(); + IEnumerable GetMany(Expression> where); + int SaveChanges(); + } +} diff --git a/DAL/Repositories/FoorumRepository.cs b/DAL/Repositories/FoorumRepository.cs new file mode 100644 index 0000000..4665fa2 --- /dev/null +++ b/DAL/Repositories/FoorumRepository.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DAL.Domain; +using DAL.Interfaces; + +namespace DAL.Repositories +{ + public class FoorumRepository: RepositoryBase, IFoorumRepository + { + public FoorumRepository(IFoorumDbContext ctx): base(ctx) { } + } +} diff --git a/DAL/Repositories/PostRepository.cs b/DAL/Repositories/PostRepository.cs new file mode 100644 index 0000000..915378b --- /dev/null +++ b/DAL/Repositories/PostRepository.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DAL.Domain; +using DAL.Interfaces; + +namespace DAL.Repositories +{ + public class PostRepository: RepositoryBase, IPostRepository + { + public PostRepository(IFoorumDbContext ctx) : base(ctx) { } + } +} diff --git a/DAL/Repositories/RepositoryBase.cs b/DAL/Repositories/RepositoryBase.cs new file mode 100644 index 0000000..4e248b4 --- /dev/null +++ b/DAL/Repositories/RepositoryBase.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using System.Linq.Expressions; +using DAL.Interfaces; + +namespace DAL.Repositories +{ + public class RepositoryBase where T : class + { + protected DbContext RepositoryDataContext; + protected DbSet RepositoryDbSet; + + + public RepositoryBase(IFoorumDbContext dbContext) + { + RepositoryDataContext = dbContext as DbContext; + if (RepositoryDataContext == null) + { + throw new ArgumentNullException(paramName: nameof(dbContext)); + } + RepositoryDbSet = RepositoryDataContext.Set(); + if (RepositoryDbSet == null) + { + throw new NullReferenceException(message: nameof(RepositoryDbSet)); + } + } + + public T Add(T entity) + { + var ret = RepositoryDbSet.Add(entity); + SaveChanges(); + return ret; + } + + public T Update(T entity) + { + RepositoryDbSet.Attach(entity); + RepositoryDataContext.Entry(entity).State = EntityState.Modified; + return entity; + } + + public void Delete(T entity) + { + RepositoryDbSet.Remove(entity); + } + + public void Delete(Expression> where) + { + IEnumerable objects = RepositoryDbSet.Where(where).AsEnumerable(); + foreach (T obj in objects) + RepositoryDbSet.Remove(obj); + } + + public T GetById(int id) + { + return RepositoryDbSet.Find(id); + } + + public virtual IEnumerable GetAll() + { + return RepositoryDbSet.ToList(); + } + + public virtual IEnumerable GetMany(Expression> where) + { + return RepositoryDbSet.Where(where).ToList(); + } + + public T Get(Expression> where) + { + return RepositoryDbSet.Where(where).FirstOrDefault(); + } + public int SaveChanges() + { + return RepositoryDataContext.SaveChanges(); + } + } +} diff --git a/Foorum.sln b/Foorum.sln index f8114cd..bca167f 100644 --- a/Foorum.sln +++ b/Foorum.sln @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DAL", "DAL\DAL.csproj", "{B EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi", "WebApi\WebApi.csproj", "{E8D27F06-E3F7-4304-899F-ADFC69297E7E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BL", "BL\BL.csproj", "{E9E385E4-C36A-42B0-8424-BC2D075916F2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {E8D27F06-E3F7-4304-899F-ADFC69297E7E}.Debug|Any CPU.Build.0 = Debug|Any CPU {E8D27F06-E3F7-4304-899F-ADFC69297E7E}.Release|Any CPU.ActiveCfg = Release|Any CPU {E8D27F06-E3F7-4304-899F-ADFC69297E7E}.Release|Any CPU.Build.0 = Release|Any CPU + {E9E385E4-C36A-42B0-8424-BC2D075916F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E9E385E4-C36A-42B0-8424-BC2D075916F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9E385E4-C36A-42B0-8424-BC2D075916F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E9E385E4-C36A-42B0-8424-BC2D075916F2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WebApi/App_Start/NinjectWebCommon.cs b/WebApi/App_Start/NinjectWebCommon.cs index f8fc7da..d280df0 100644 --- a/WebApi/App_Start/NinjectWebCommon.cs +++ b/WebApi/App_Start/NinjectWebCommon.cs @@ -1,3 +1,6 @@ +using BL.Interfaces; +using DAL.Repositories; + [assembly: WebActivatorEx.PreApplicationStartMethod(typeof(WebApi.App_Start.NinjectWebCommon), "Start")] [assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(WebApi.App_Start.NinjectWebCommon), "Stop")] @@ -10,6 +13,11 @@ namespace WebApi.App_Start using Ninject; using Ninject.Web.Common; + using System.Web.Http; + using Ninject.Web.WebApi; + using DAL; + using DAL.Interfaces; + using BL.Services; public static class NinjectWebCommon { @@ -46,6 +54,10 @@ namespace WebApi.App_Start kernel.Bind().To(); RegisterServices(kernel); + + // Support WebAPI + GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel); + return kernel; } catch @@ -61,6 +73,10 @@ namespace WebApi.App_Start /// The kernel. private static void RegisterServices(IKernel kernel) { - } + kernel.Bind().To().InRequestScope(); + kernel.Bind().To().InRequestScope(); + kernel.Bind().To().InRequestScope(); + kernel.Bind().To().InRequestScope(); + } } } diff --git a/WebApi/App_Start/WebApiConfig.cs b/WebApi/App_Start/WebApiConfig.cs index 933c8de..d937c7f 100644 --- a/WebApi/App_Start/WebApiConfig.cs +++ b/WebApi/App_Start/WebApiConfig.cs @@ -45,7 +45,7 @@ namespace WebApi // Force always json response var jsonFormatter = new JsonMediaTypeFormatter(); //optional: set serializer settings here - config.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(jsonFormatter)); + //config.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(jsonFormatter)); } } } diff --git a/WebApi/Controllers/FoorumController.cs b/WebApi/Controllers/FoorumController.cs index a0947dc..3ce5bb5 100644 --- a/WebApi/Controllers/FoorumController.cs +++ b/WebApi/Controllers/FoorumController.cs @@ -4,15 +4,22 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; +using BL.DTOs; +using BL.Interfaces; namespace WebApi.Controllers { public class FoorumController : ApiController { - // GET api/ - public IEnumerable Get() + private IFoorumService _foorumService; + public FoorumController(IFoorumService foorumService) { - return new string[] { "value1", "value2" }; + _foorumService = foorumService; + } + // GET api/ + public IEnumerable Get() + { + return _foorumService.GetAll(); } // GET api//5 diff --git a/WebApi/Web.config b/WebApi/Web.config index bf7cddb..76b88e0 100644 --- a/WebApi/Web.config +++ b/WebApi/Web.config @@ -4,7 +4,14 @@ https://go.microsoft.com/fwlink/?LinkId=301879 --> + + +
+ + + + @@ -35,6 +42,10 @@ + + + + @@ -43,4 +54,14 @@ - + + + + + + + + + + + \ No newline at end of file diff --git a/WebApi/WebApi.csproj b/WebApi/WebApi.csproj index b9951a6..4769e73 100644 --- a/WebApi/WebApi.csproj +++ b/WebApi/WebApi.csproj @@ -43,6 +43,12 @@ 4 + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll @@ -57,7 +63,10 @@ ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll - ..\packages\Ninject.Web.Common.3.2.0.0\lib\net45-full\Ninject.Web.Common.dll + ..\packages\Ninject.Web.Common.3.2.3.0\lib\net45-full\Ninject.Web.Common.dll + + + ..\packages\Ninject.Web.WebApi.3.2.4.0\lib\net45-full\Ninject.Web.WebApi.dll @@ -80,7 +89,7 @@ - ..\packages\WebActivatorEx.2.0\lib\net40\WebActivatorEx.dll + ..\packages\WebActivatorEx.2.2.0\lib\net40\WebActivatorEx.dll @@ -96,6 +105,7 @@ + @@ -120,6 +130,16 @@ + + + {e9e385e4-c36a-42b0-8424-bc2d075916f2} + BL + + + {b783887a-e5bb-4066-9b9b-abd7b4c1e269} + DAL + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/WebApi/index.html b/WebApi/index.html index d339520..3f49133 100644 --- a/WebApi/index.html +++ b/WebApi/index.html @@ -1,2 +1,16 @@

api

-foorum \ No newline at end of file +foorum + +
+ + \ No newline at end of file diff --git a/WebApi/packages.config b/WebApi/packages.config index d945096..e83c095 100644 --- a/WebApi/packages.config +++ b/WebApi/packages.config @@ -1,5 +1,6 @@  + @@ -10,7 +11,8 @@ - + - + + \ No newline at end of file