using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using MVCTemplate.Business.Dtos; using MVCTemplate.Models; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using MVCTemplate.Business.Interfaces; using MVCTemplate.Infrastructure; namespace MVCTemplate.Controllers { [Authorize] public class HomeController : Controller { private readonly ILogger _logger; private readonly IMessageService _messageService; private readonly IModelFactory _modelFactory; public HomeController(ILogger logger, IMessageService messageService, IModelFactory modelFactory) { _logger = logger; _messageService = messageService; _modelFactory = modelFactory; } public IActionResult Index() { return View(); } [HttpPost] public async Task CreateMessage(MessageModel model) { MessageDto message = new MessageDto { Text = model.Text}; int id = await _messageService.Create(message, model.ChosenPeriod); return RedirectToAction("Link", "Home", new { id = id, share = true }); } [HttpGet] public async Task Link(int id, bool? share) { var model = await _modelFactory.PrepareLinkVM(id, share); return View(model); } public IActionResult Privacy() { return View(); } } }