diff --git a/Source/Project.Business/Mappers/PersonMapper.cs b/Source/Project.Business/Mappers/PersonMapper.cs index 063b365..c7129e5 100644 --- a/Source/Project.Business/Mappers/PersonMapper.cs +++ b/Source/Project.Business/Mappers/PersonMapper.cs @@ -1,5 +1,4 @@ -using System; -using Project.Business.Factories; +using Project.Business.Factories; using Project.Common.Models.Request; using Project.Data.Entity; using Project.Common.Models; diff --git a/Source/Project.Business/PersonService.cs b/Source/Project.Business/PersonService.cs index 8fbfdf6..e967a4d 100644 --- a/Source/Project.Business/PersonService.cs +++ b/Source/Project.Business/PersonService.cs @@ -76,5 +76,13 @@ public PersonSelectResponse Select(PersonSelectRequest request) response.Message = "Person selected."; return response; } + + public PersonSelectPageResponse SelectPage(PersonSelectPageRequest request) + { + var response = new PersonSelectPageResponse(); + + + return response; + } } } diff --git a/Source/Project.Common/Contracts/IPersonService.cs b/Source/Project.Common/Contracts/IPersonService.cs index e11e283..e14c910 100644 --- a/Source/Project.Common/Contracts/IPersonService.cs +++ b/Source/Project.Common/Contracts/IPersonService.cs @@ -19,5 +19,12 @@ public interface IPersonService /// /// PersonSelectResponse Select(PersonSelectRequest request); + + /// + /// + /// + /// + /// + PersonSelectPageResponse SelectPage(PersonSelectPageRequest request); } } diff --git a/Source/Project.Common/Models/Request/PersonSelectPageRequest.cs b/Source/Project.Common/Models/Request/PersonSelectPageRequest.cs new file mode 100644 index 0000000..adb7518 --- /dev/null +++ b/Source/Project.Common/Models/Request/PersonSelectPageRequest.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Project.Common.Models.Request +{ + public class PersonSelectPageRequest : BaseRequest + { + public string Filter { get; set; } + public int Skip { get; set; } + public int Take { get; set; } + + public PersonSelectPageRequest(int skip, int take, string filter) + { + Skip = skip; + Take = take; + Filter = filter; + } + + public override bool IsNotValid() + { + if (Skip < 0) + { + Skip = 0; + } + + if (Take > 100) + { + Take = 100; + } + + return false; + } + } +} diff --git a/Source/Project.Common/Models/Response/PersonSelectPageResponse.cs b/Source/Project.Common/Models/Response/PersonSelectPageResponse.cs new file mode 100644 index 0000000..b6f73d4 --- /dev/null +++ b/Source/Project.Common/Models/Response/PersonSelectPageResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Project.Common.Models.Response +{ + public class PersonSelectPageResponse : BaseResponse + { + } +} diff --git a/Source/Project.Common/Project.Common.csproj b/Source/Project.Common/Project.Common.csproj index ab67db0..2c51f5d 100644 --- a/Source/Project.Common/Project.Common.csproj +++ b/Source/Project.Common/Project.Common.csproj @@ -47,9 +47,11 @@ + + diff --git a/Source/Project.WebClient/Controllers/PersonController.cs b/Source/Project.WebClient/Controllers/PersonController.cs new file mode 100644 index 0000000..b17f953 --- /dev/null +++ b/Source/Project.WebClient/Controllers/PersonController.cs @@ -0,0 +1,83 @@ + +using Project.Common.Contracts; +using Project.WebClient.ViewModels; +using Project.WebClient.Mappers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using Project.Common.Models.Request; + +namespace Project.WebClient.Controllers +{ + public class PersonController : BaseController + { + public const string LIST_URL = "/Person/List/"; + public const string DETAIL_URL = "/Person/Detail/"; + + IPersonService _personService; + + public PersonController(IPersonService personService) + { + _personService = personService; + } + + [HttpGet] + public ViewResult List(int skip = 0, int take = 100, string filter = "") + { + if (skip < 0) + { + skip = 0; + } + + if (take > 100) + { + take = 100; + } + + if (filter.Length > 10) + { + filter = filter.Substring(0, 10); + } + + var request = new PersonSelectPageRequest(skip, take, filter); + var model = _personService.SelectPage(request); + + //todo: implement + + return View(); + } + + [HttpGet] + public ActionResult New() + { + return View(); + } + + [HttpPost, ValidateAntiForgeryToken] + public ActionResult New(PersonViewModel model) + { + if (model == null) + { + return View(); + } + + var request = PersonMapper.MapRequestFromViewModel(model); + if (request.IsNotValid()) + { + model.Message = "Request is not valid!"; + return View(model); + } + + var response = _personService.Insert(request); + if (response.Status) + { + return Redirect($"{DETAIL_URL}{response.Model.UId}"); + } + + model.Message = response.Message; + return View(model); + } + } +} \ No newline at end of file diff --git a/Source/Project.WebClient/Mappers/PersonMapper.cs b/Source/Project.WebClient/Mappers/PersonMapper.cs new file mode 100644 index 0000000..7249f99 --- /dev/null +++ b/Source/Project.WebClient/Mappers/PersonMapper.cs @@ -0,0 +1,20 @@ +using Project.Common.Models.Request; +using Project.WebClient.ViewModels; + +namespace Project.WebClient.Mappers +{ + public static class PersonMapper + { + public static PersonInsertRequest MapRequestFromViewModel(PersonViewModel model) + { + var request = new PersonInsertRequest(); + + request.FirstName = model.FirstName; + request.LastName = model.LastName; + request.Email = model.Email; + request.Phone = model.Phone; + + return request; + } + } +} \ No newline at end of file diff --git a/Source/Project.WebClient/Project.WebClient.csproj b/Source/Project.WebClient/Project.WebClient.csproj index 15b9912..a36cb21 100644 --- a/Source/Project.WebClient/Project.WebClient.csproj +++ b/Source/Project.WebClient/Project.WebClient.csproj @@ -137,6 +137,10 @@ + + + + Web.config @@ -158,6 +162,7 @@ + @@ -165,7 +170,9 @@ + + diff --git a/Source/Project.WebClient/Statics/css/app.css b/Source/Project.WebClient/Statics/css/app.css index 50734fc..dcad243 100644 --- a/Source/Project.WebClient/Statics/css/app.css +++ b/Source/Project.WebClient/Statics/css/app.css @@ -2,8 +2,7 @@ font-family: Consolas; } -.sitename { - margin-top: 13px !important; - margin-bottom: -8px !important; - text-align: left; +form input { + width: 55%!important; + margin-bottom:13px!important; } diff --git a/Source/Project.WebClient/ViewModels/BaseModel.cs b/Source/Project.WebClient/ViewModels/BaseModel.cs new file mode 100644 index 0000000..7ad33a7 --- /dev/null +++ b/Source/Project.WebClient/ViewModels/BaseModel.cs @@ -0,0 +1,7 @@ +namespace Project.WebClient.ViewModels +{ + public class BaseModel + { + public string Message { get; set; } + } +} \ No newline at end of file diff --git a/Source/Project.WebClient/ViewModels/PersonViewModel.cs b/Source/Project.WebClient/ViewModels/PersonViewModel.cs index 9b245ab..e575502 100644 --- a/Source/Project.WebClient/ViewModels/PersonViewModel.cs +++ b/Source/Project.WebClient/ViewModels/PersonViewModel.cs @@ -1,11 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; - -namespace Project.WebClient.ViewModels +namespace Project.WebClient.ViewModels { - public class PersonViewModel + public class PersonViewModel : BaseModel { + public string FirstName { get; set; } + public string LastName { get; set; } + public string Email { get; set; } + public string Phone { get; set; } } } \ No newline at end of file diff --git a/Source/Project.WebClient/Views/Home/Index.cshtml b/Source/Project.WebClient/Views/Home/Index.cshtml index 5f28270..bb4f14c 100644 --- a/Source/Project.WebClient/Views/Home/Index.cshtml +++ b/Source/Project.WebClient/Views/Home/Index.cshtml @@ -1 +1,2 @@ - \ No newline at end of file +Show People + diff --git a/Source/Project.WebClient/Views/Person/Detail.cshtml b/Source/Project.WebClient/Views/Person/Detail.cshtml new file mode 100644 index 0000000..66317d4 --- /dev/null +++ b/Source/Project.WebClient/Views/Person/Detail.cshtml @@ -0,0 +1,2 @@ +Add New Person + diff --git a/Source/Project.WebClient/Views/Person/Edit.cshtml b/Source/Project.WebClient/Views/Person/Edit.cshtml new file mode 100644 index 0000000..66317d4 --- /dev/null +++ b/Source/Project.WebClient/Views/Person/Edit.cshtml @@ -0,0 +1,2 @@ +Add New Person + diff --git a/Source/Project.WebClient/Views/Person/List.cshtml b/Source/Project.WebClient/Views/Person/List.cshtml new file mode 100644 index 0000000..66317d4 --- /dev/null +++ b/Source/Project.WebClient/Views/Person/List.cshtml @@ -0,0 +1,2 @@ +Add New Person + diff --git a/Source/Project.WebClient/Views/Person/New.cshtml b/Source/Project.WebClient/Views/Person/New.cshtml new file mode 100644 index 0000000..62e67b6 --- /dev/null +++ b/Source/Project.WebClient/Views/Person/New.cshtml @@ -0,0 +1,35 @@ +@model PersonViewModel +@{ + + ViewBag.PageTitle = "New Person Form"; +} + +

@ViewBag.PageTitle

+
+ +
+ + @if (!string.IsNullOrWhiteSpace(Model?.Message)) + { +
+ Error! @Model.Message +
+ } + + + + + + + + + + + + + +
+ @Html.AntiForgeryToken() + +
+ diff --git a/Source/Project.WebClient/Views/Shared/_Layout.cshtml b/Source/Project.WebClient/Views/Shared/_Layout.cshtml index 84589fc..0f5a5bf 100644 --- a/Source/Project.WebClient/Views/Shared/_Layout.cshtml +++ b/Source/Project.WebClient/Views/Shared/_Layout.cshtml @@ -12,7 +12,7 @@
-
+

Sample Project

diff --git a/Test/Project.Business.Test/Helpers/TestHelper.cs b/Test/Project.Business.Test/Helpers/TestHelper.cs index c020bf9..e31183b 100644 --- a/Test/Project.Business.Test/Helpers/TestHelper.cs +++ b/Test/Project.Business.Test/Helpers/TestHelper.cs @@ -1,4 +1,5 @@ -using Project.Common.Models.Request; +using System; +using Project.Common.Models.Request; namespace Project.Business.Test.Helpers { @@ -19,6 +20,6 @@ public static PersonSelectRequest GetPersonSelectRequest(string uid) var request = new PersonSelectRequest(); request.UId = uid; return request; - } + } } } diff --git a/Test/Project.Business.Test/PersonServiceUnitTests.cs b/Test/Project.Business.Test/PersonServiceUnitTests.cs index 37c185c..3908424 100644 --- a/Test/Project.Business.Test/PersonServiceUnitTests.cs +++ b/Test/Project.Business.Test/PersonServiceUnitTests.cs @@ -24,5 +24,21 @@ public void PersonService_Insert_ReturnsPersonInsertResponse() //assert Assert.IsType(response); } + + [Fact] + public void PersonService_Select_ReturnsPersonSelectResponse() + { + //arrange + var request = TestHelper.GetPersonSelectRequest("test"); + + var repository = A.Fake(); + var service = new PersonService(repository); + + //act + var response = service.Select(request); + + //assert + Assert.IsType(response); + } } }