namespace OnlineHomeService.Filters
public class ActionLogCustomFilter : ActionFilterAttribute, IActionFilter
void IActionFilter.OnActionExecuting(ActionExecutedContext filterContext)
IGenericRepository<ActionLog> respository = new IGenericRepository<ActionLog>();
ActionLog oAction = new ActionLog()
Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
Action = string.Concat(filterContext.ActionDescriptor.ActionName),
IP = filterContext.HttpContext.Request.UserHostAddress,
Timestamp = filterContext.HttpContext.Timestamp
respository.Insert(oAction);
this.OnActionExecuting(filterContext);
namespace OnlineHomeService.Filters
public class CustomAuthorizeFilter : AuthorizeAttribute
public string AllowedUser { get; set; }
public override void OnAuthorization(AuthorizationContext filterContext)
base.OnAuthorization(filterContext);
string userName = (string)HttpContext.Current.Session["UserID"];
if (AllowedUser != null && !(userName.ToUpper() == "ADMIN"))
HandleUnauthorizedRequest(filterContext);
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary{{"controller", "Login"}, {"action", "LogOff"}});
DateTime myDate = new DateTime();
string us = myDate.ToString(new CultureInfo("en-US"));
namespace OnlineHomeService.Controllers
public class UserController1 : Controller
private IGenericRepository<Users> repository = null;
this.repository = new GenericRepository<Users>();
public ActionResult Index()
var User = repository.SelectAll().ToList();
ViewBag.CurrentDate = DateTime.Now.ToShortDateString();
if(CultureInfo.CurrentCulture.Name == "en-US")
ViewBag.GreetingMessage = Resources.HomeResources.Greeting;
ViewBag.CurrentCulture = "en-US";
if(CultureInfo.CurrentCulture.Name == "fr-FR")
ViewBag.GreetingMessage = Resources.HomeResources.GreetingFrench;
ViewBag.CurrentCulture = "fr-FR";
public ActionResult CreateUser()
public ActionResult DeleteUser()
public ActionResult DetailsUser()
public ActionResult EditUser()
namespace OnlineHomeService.Models
public class CustomEmailValidator: ValidationAttribute
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
string emailId = (string)value;
var emailAddr = new System.Net.Mail.MailAddress(emailId);
return new ValidationResult("The email addrss should be a valid email address. For example: JohnDoe@emample.com");
return ValidationResult.Success;
return new ValidationResult("The email addrss should be a valid email address. For example: JohnDoe@emample.com");
namespace OnlineHomeService.Models
public class CustomMobileValidator : ValidationAttribute
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
string mobileNumber = (string)value;
if (mobileNumber != null)
isValid = float.TryParse(mobileNumber, out outputfloat);
if (mobileNumber.Length == 10)
return new ValidationResult("The contact number is not correct");
return ValidationResult.Success;
return new ValidationResult("The contact number is not correct");
namespace OnlineHomeService.Models
public class CustomPasswordValidator : ValidationAttribute
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
string password = (string)value;
if (password.Length >= 0 && password.Length <= 10)
return new ValidationResult("The password must be 6 to 8 characters length");
return ValidationResult.Success;
return new ValidationResult("The password must be 6 to 8 characters length");
namespace OnlineHomeService.Models
public class CustomUsernameValidator : ValidationAttribute
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
string username = (string)value;
if (string.IsNullOrWhiteSpace(username) && username.Length > 10)
return new ValidationResult("The username must not more than 10 character long");
return ValidationResult.Success;
return new ValidationResult("The username must not more than 10 character long");
namespace OnlineHomeService.Models
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[CustomUsernameValidator]
public string Username { get; set; }
[CustomPasswordValidator]
public string Password { get; set; }
public string ContactNo { get; set; }
public string Email { get; set; }
namespace OnlineHomeService.ViewModel
public class DisplayBookingViewModel : BookingViewModel
public List<Booking> BookingList { get; set; }
public List<Service> Service { get; set; }
@model IEnumerable<OnlineHomeService.ViewModel.DisplayBookingViewModel>
ViewBag.Title = "Booking History";
@foreach (var item in Model.BookingList)
@Html.DisplayFor(modelItem => item.ServiceId)
@Html.DisplayFor(modelItem => item.Rate)
@Html.DisplayFor(modelItem => item.Address)
@Html.DisplayFor(modelItem => item.Username)
<tr><td>No booking history found!!</td></tr>
@model IEnumerable<OnlineHomeService.Models.Service>
ViewBag.Title = "Search for Service";
<h2>Search for Service</h2>
@using (Html.BeginForm("Search", "Service", "Index"))
@Html.DropDownListFor(x => x.SelectedType, Model.TypeList.Select(x => new SelectedListItem() { Text = x.Type.ToString(), Value = x.Type.ToString() }))
<input type="Submit" value="Search" id="btnSearch" />
@using (Html.BeginForm ("Index","Home",FormMethod.Get ))
<b>Search by:</b>@Html.RadioButton("searchBy","Name")<text> Name</text>
@Html.RadioButton("searchBy","Gender")<text>Gender</text><br />
@Html.TextBox("Search");<input type="submit" value="Search" />
if (searchby == "Gender")
return View(db.Employees.Where(x => x.Gender == search || search ==null).ToList());
return View(db.Employees.Where(x => x.Name.StartsWith(search)).ToList());
public ActionResult DisplaySearchResults(string searchText)
return PartialView("SearchResults", model);
Models.TrainingMVCContext db = new Models.TrainingMVCContext();
public PartialViewResult SearchPeople(string keyword)
var data = db.PersonalDetails.Where(f => f.FirstName.Contains(keyword)).ToList();
return PartialView(data);
$('#btn').click(function(){
$('#searchresult').load('@Url.Content("~/Person/Search")'); or $("#divResult").load('/Person/Search?criteria=' + $("#txtSearch").val());
<h1>This is from main view upper.</h1>
@Html.Partial("_MyPartialView", Model.Department )
Html.RenderPartial("_MyPartialView", Model.Department);
<h1>This is from main view lower.</h1>
<input type="button" value="Click" id="btnClick"/>
copy below code in _MyPartialView
@model List<PartialViewDemo.Models.Department>
<h6> This below table content is from partial view</h6>
<table cellspacing="0"width="50%" border="1">
@foreach (var dept in Model)
@model PartialViewDemo.Models.Company
<meta name="viewport" content="width=device-width" />
<h1>This is from main view upper.</h1>
@Html.Partial("_MyPartialView", Model.Department )
Html.RenderPartial("_MyPartialView", Model.Department);
<h1>This is from main view lower.</h1>
<input type="button" value="Click" id="btnClick"/>
<script src="~/Content/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$('#btnClick').click(function(data) {
$.post("@Url.Action("ShowPartailView", "Home")", function(data) {
$('#divTest').append(data);
And in the _MySecondPartial.cshtml
<h3> Testing for partial view</h3>
Service -> _SearchResult.cshtml
@model IEnumerable<OnlineHomeService.ViewModel.DisplayBookingViewModel>
@foreach (var item in Model.BookingList>
@Html.DisplayFor(modelItem => item.ServiceId)
@Html.DisplayFor(modelItem => item.Rate)
@Html.DisplayFor(modelItem => item.Address)
@Html.DisplayFor(modelItem => item.Username)
namespace OnlineHomeService.Controllers
public class BookingController : Controller
public ActionResult Index()
DisplayBookingViewModel dpv = new DisplayBookingViewModel();
if(Session["UserID"] == null)
return RedirectToAction("Login", "Login");
var booking = (from b in bookingRepo.SelectAll()
where b.Username == Session["UserID"].ToString()
dpv.BookingList = booking;
public ActionResult Booking(int serviceId)
if (Session["UserID"] == null)
return RedirectToAction("Login", "Login");
var booking = GenerateData(serviceId, Session["UserID"].ToString());
public Booking GenerateData(int serviceId, string usreID)