Task_Tracker_SUBD/TaskTrackerRestAPI/TaskTrackerClientApp/Controllers/TaskController.cs
2023-05-17 10:48:52 +04:00

126 lines
2.7 KiB
C#

using Microsoft.AspNetCore.Mvc;
using System.Xml.Linq;
using TaskTrackerContracts.BindingModels;
using TaskTrackerContracts.SearchModels;
using TaskTrackerContracts.ViewModels;
namespace TaskTrackerClientApp.Controllers
{
public class TaskController : Controller
{
private readonly ILogger<TaskController> _logger;
public TaskController(ILogger<TaskController> logger)
{
_logger = logger;
}
[HttpGet]
public IActionResult CreateTask()
{
ViewBag.Projects =
APIClient.GetRequest<List<ProjectViewModel>>($"api/project/getprojectlist?companyId={APIClient.Company.Id}");
return View();
}
[HttpPost]
public void CreateTask(string name, DateTime deadline, int projectId)
{
if (APIClient.Company == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/task/createtask", new
TaskBindingModel
{
DateCreate = DateTime.Now,
Name = name,
Deadline = deadline,
ProjectId = projectId,
Status = "Создано",
TaskEmployees = new Dictionary<int, (TaskTrackerModels.Models.IEmployeeModel, string)>()
}) ;
Response.Redirect("/Home/Tasks");
}
[HttpPost]
public void DeleteTask(int id, int projectId)
{
if (APIClient.Company == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/task/deletetask", new
TaskSearchModel
{
Name = "g",
ProjectId = projectId,
Id = id
});
Response.Redirect("/Home/Index");
}
[HttpGet]
public IActionResult UpdateTask()
{
ViewBag.Projects =
APIClient.GetRequest<List<ProjectViewModel>>($"api/project/getprojectlist?companyId={APIClient.Company.Id}");
return View();
}
[HttpPost]
public void UpdateTask(string name, DateTime deadline, int projectId, int id, string status)
{
if (APIClient.Company == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (status.Equals("Завершено"))
{
APIClient.PostRequest("api/task/updatetask", new
TaskBindingModel
{
DateCreate = DateTime.Now,
Name = name,
Deadline = deadline,
ProjectId = projectId,
Status = status,
Id = id,
DateDone = DateTime.Now
});
Response.Redirect("/Home/Index");
}
else
{
APIClient.PostRequest("api/task/updatetask", new
TaskBindingModel
{
DateCreate = DateTime.Now,
Name = name,
Deadline = deadline,
ProjectId = projectId,
Status = status,
Id = id,
});
Response.Redirect("/Home/Index");
}
}
}
}