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.

51 lines
1.6 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. using System.Linq;
  2. using Microsoft.AspNet.Identity.EntityFramework;
  3. using Sevomin.Models;
  4. using Sevomin.Models.Helpers;
  5. using System.Threading.Tasks;
  6. using System.Web.Mvc;
  7. using Sevomin.Models.Repositories;
  8. namespace Sevomin.WebFrontend.Controllers
  9. {
  10. public class HomeController : BaseController
  11. {
  12. IAdRepository _adRepository;
  13. public HomeController()
  14. : this(AdRepository.Current, new SevominUserManager(new UserStore<User>(SevominDbContext.Current)))
  15. {
  16. }
  17. public HomeController(IAdRepository adRepositry, SevominUserManager userManager)
  18. {
  19. _adRepository = adRepositry;
  20. UserManager = userManager;
  21. }
  22. public SevominUserManager UserManager { get; private set; }
  23. public async Task<ActionResult> Index()
  24. {
  25. if (!Request.IsAuthenticated)
  26. return View("Intro");
  27. User user = await UserManager.FindByNameAsync(User.Identity.Name);
  28. if (user is Avalin)
  29. return View("AvalinIndex");
  30. if (user is Dovomin)
  31. return View("DovominIndex");
  32. return RedirectToAction("Index", "God");
  33. }
  34. public ActionResult Ads(int id)
  35. {
  36. var ad = _adRepository.ListAll().SingleOrDefault(m => m.Id == id);
  37. if (ad == null)
  38. {
  39. return HttpNotFound();
  40. }
  41. ad.ClickCount++;
  42. _adRepository.Save();
  43. return Redirect(ad.Link);
  44. }
  45. }
  46. }