-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Serdar Büyüktemiz
committed
Apr 10, 2016
1 parent
4848d0c
commit 5e489a9
Showing
20 changed files
with
256 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
Source/Project.Common/Models/Request/PersonSelectPageRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Source/Project.Common/Models/Response/PersonSelectPageResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Project.WebClient.ViewModels | ||
{ | ||
public class BaseModel | ||
{ | ||
public string Message { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
| ||
<a href="/Person/List" class="btn btn-primary">Show People</a> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<a href="/Person/New" class="btn btn-primary pull-right">Add New Person</a> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<a href="/Person/New" class="btn btn-primary pull-right">Add New Person</a> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<a href="/Person/New" class="btn btn-primary pull-right">Add New Person</a> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
@model PersonViewModel | ||
@{ | ||
|
||
ViewBag.PageTitle = "New Person Form"; | ||
} | ||
|
||
<h2>@ViewBag.PageTitle</h2> | ||
<br /> | ||
|
||
<form method="post"> | ||
|
||
@if (!string.IsNullOrWhiteSpace(Model?.Message)) | ||
{ | ||
<div class="alert alert-danger"> | ||
<strong>Error!</strong> @Model.Message | ||
</div> | ||
} | ||
|
||
<label for="FirstName">First Name</label> | ||
<input type="text" name="FirstName" id="FirstName" class="form-control" /> | ||
|
||
<label for="LastName">Last Name</label> | ||
<input type="text" name="LastName" id="LastName" class="form-control" /> | ||
|
||
<label for="Email">Email</label> | ||
<input type="email" name="Email" id="Email" class="form-control" /> | ||
|
||
<label for="Phone">Phone</label> | ||
<input type="text" name="Phone" id="Phone" class="form-control" /> | ||
|
||
<br/> | ||
@Html.AntiForgeryToken() | ||
<button type="submit" class="btn btn-primary">Save</button> | ||
</form> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters