You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

52 lines
1.6 KiB

using System.Linq;
using Microsoft.AspNet.Identity.EntityFramework;
using Sevomin.Models;
using Sevomin.Models.Helpers;
using System.Threading.Tasks;
using System.Web.Mvc;
using Sevomin.Models.Repositories;
namespace Sevomin.WebFrontend.Controllers
{
public class HomeController : BaseController
{
IAdRepository _adRepository;
public HomeController()
: this(AdRepository.Current, new SevominUserManager(new UserStore<User>(SevominDbContext.Current)))
{
}
public HomeController(IAdRepository adRepositry, SevominUserManager userManager)
{
_adRepository = adRepositry;
UserManager = userManager;
}
public SevominUserManager UserManager { get; private set; }
public async Task<ActionResult> Index()
{
if (!Request.IsAuthenticated)
return View("Intro");
User user = await UserManager.FindByNameAsync(User.Identity.Name);
if (user is Avalin)
return View("AvalinIndex");
if (user is Dovomin)
return View("DovominIndex");
return RedirectToAction("Index", "God");
}
public ActionResult Ads(int id)
{
var ad = _adRepository.ListAll().SingleOrDefault(m => m.Id == id);
if (ad == null)
{
return HttpNotFound();
}
ad.ClickCount++;
_adRepository.Save();
return Redirect(ad.Link);
}
}
}