AppController.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using DutchTreat.Data;
  2. using DutchTreat.Services;
  3. using DutchTreat.ViewModels;
  4. using Microsoft.AspNetCore.Authorization;
  5. using Microsoft.AspNetCore.Mvc;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace DutchTreat.Controllers
  12. {
  13. public class AppController : Controller
  14. {
  15. private readonly IMailService _mailService;
  16. private readonly IDutchRepository _repository;
  17. public AppController(IMailService mailService, IDutchRepository repository)
  18. {
  19. _mailService = mailService;
  20. _repository = repository;
  21. }
  22. public IActionResult Index()
  23. {
  24. var results = _repository.GetAllProducts();
  25. return View();
  26. }
  27. [HttpGet("Contact")]
  28. public IActionResult Contact()
  29. {
  30. return View();
  31. }
  32. [HttpPost("Contact")]
  33. public IActionResult Contact(ContactViewModel model)
  34. {
  35. if (ModelState.IsValid)
  36. {
  37. _mailService.SendMessage("", model.Subject, $"From: {model.Name} - {model.Email}, Message: {model.Message}");
  38. ViewBag.UserMessage = "Mail Sent";
  39. ModelState.Clear();
  40. }
  41. return View();
  42. }
  43. public IActionResult About()
  44. {
  45. ViewBag.Title = "About Us";
  46. return View();
  47. }
  48. public IActionResult Shop()
  49. {
  50. var results = _repository.GetAllProducts();
  51. return View(results);
  52. }
  53. }
  54. }