File size: 1,623 Bytes
e26fba6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MovieTube.Web.Repository;
using MovieTube.Web.Services;
using MovieFinder.Data;
namespace MovieTube.Web.Controllers
{
public class BaseMvcController : Controller
{
protected readonly IMovieRepository repository;
protected readonly IUserRepository userRepository;
protected readonly ICookieService cookieService;
protected readonly IUserProfileService userProfileService;
public BaseMvcController()
{
repository = new MovieRepository();
userRepository = new UserRepository();
cookieService = new CookieService();
userProfileService = new UserProfileService();
}
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
var cookie = Request.Cookies[Constants.CookieSessionName];
Profile = userProfileService.UpdateVisitorProfile(
cookieService.DecryptCookie(cookie != null ? cookie.Value : null),
Request.UserHostAddress, Request.Url.PathAndQuery,
Request.QueryString["lang"]);
if(cookie == null)
Response.SetCookie(new HttpCookie(Constants.CookieSessionName,
cookieService.EncryptCookie(Profile.ID)) { Expires = DateTime.Now.AddYears(100) });
base.OnActionExecuting(filterContext);
}
public VisitorProfile Profile { get; private set; }
}
}
|