253 lines
6.7 KiB
C#
253 lines
6.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using TaskTrackerClientApp.Models;
|
|
using TaskTrackerContracts.BindingModels;
|
|
using TaskTrackerContracts.ViewModels;
|
|
|
|
namespace TaskTrackerClientApp.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly ILogger<HomeController> _logger;
|
|
int taskId = 0;
|
|
public HomeController(ILogger<HomeController> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
public IActionResult Index()
|
|
{
|
|
if (APIClient.Company == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return
|
|
View(APIClient.GetRequest<List<ProjectViewModel>>($"api/project/getprojectlist?companyId={APIClient.Company.Id}"));
|
|
}
|
|
public IActionResult Employees()
|
|
{
|
|
ViewBag.Employees =
|
|
APIClient.GetRequest<List<EmployeeViewModel>>($"api/employee/getemployeelist?companyId={APIClient.Company.Id}");
|
|
if (APIClient.Company == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return
|
|
View(APIClient.GetRequest<List<EmployeeViewModel>>($"api/employee/getemployeelist?companyId={APIClient.Company.Id}"));
|
|
}
|
|
public IActionResult ReportEmployee(int id)
|
|
{
|
|
ViewBag.Employees =
|
|
APIClient.GetRequest<List<EmployeeViewModel>>($"api/employee/getemployeelist?companyId={APIClient.Company.Id}");
|
|
if (APIClient.Company == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return View(APIClient.GetRequest<List<TaskViewModel>>($"api/task/gettaskemployeelist?id={id}"));
|
|
}
|
|
public IActionResult TaskEmployee(int id)
|
|
{
|
|
|
|
if (APIClient.Company == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return View(APIClient.GetRequest<List<TaskViewModel>>($"api/task/gettaskemployeelist?id={id}"));
|
|
}
|
|
[HttpGet]
|
|
public IActionResult ReportTask(DateTime dateFrom, DateTime dateTo)
|
|
{
|
|
if (APIClient.Company == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
|
|
return View(APIClient.GetRequest<List<TaskViewModel>>($"api/task/gettaskdatelist?datefrom={dateFrom}&dateTo={dateTo}&companyId={APIClient.Company.Id}"));
|
|
}
|
|
|
|
public IActionResult Tasks(int id)
|
|
{
|
|
ViewBag.Employees =
|
|
APIClient.GetRequest<List<EmployeeViewModel>>($"api/employee/getemployeelist?companyId={APIClient.Company.Id}");
|
|
|
|
if (APIClient.Company == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
taskId = id;
|
|
return
|
|
View(APIClient.GetRequest<List<TaskViewModel>>($"api/task/gettasklist?projectId={id}"));
|
|
}
|
|
|
|
public IActionResult TaskAssigments(int id)
|
|
{
|
|
if (APIClient.Company == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return
|
|
View(APIClient.GetRequest<List<TaskAssigmentViewModel>>($"api/task/gettaskassigmentlist?taskId={id}"));
|
|
}
|
|
[HttpGet]
|
|
public IActionResult Privacy()
|
|
{
|
|
if (APIClient.Company == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return View(APIClient.Company);
|
|
}
|
|
[HttpPost]
|
|
public void Privacy(string login, string password, string name)
|
|
{
|
|
if (APIClient.Company == null)
|
|
{
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
}
|
|
if (string.IsNullOrEmpty(login) ||
|
|
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(name))
|
|
{
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
}
|
|
APIClient.PostRequest("api/company/updatedata", new
|
|
CompanyBindingModel
|
|
{
|
|
Id = APIClient.Company.Id,
|
|
Name = name,
|
|
Login = login,
|
|
Password = password
|
|
});
|
|
APIClient.Company.Name = name;
|
|
APIClient.Company.Login = login;
|
|
APIClient.Company.Password = password;
|
|
Response.Redirect("Index");
|
|
}
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None,
|
|
NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel
|
|
{
|
|
RequestId =
|
|
Activity.Current?.Id ?? HttpContext.TraceIdentifier
|
|
});
|
|
}
|
|
[HttpGet]
|
|
public IActionResult Enter()
|
|
{
|
|
return View();
|
|
}
|
|
[HttpPost]
|
|
public void Enter(string login, string password)
|
|
{
|
|
if (string.IsNullOrEmpty(login) ||
|
|
string.IsNullOrEmpty(password))
|
|
{
|
|
throw new Exception("Введите логин и пароль");
|
|
}
|
|
APIClient.Company =
|
|
APIClient.GetRequest<CompanyViewModel>($"api/company/login?login={login}&password={password}");
|
|
if (APIClient.Company == null)
|
|
{
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
}
|
|
Response.Redirect("Index");
|
|
}
|
|
[HttpGet]
|
|
public IActionResult Register()
|
|
{
|
|
return View();
|
|
}
|
|
[HttpPost]
|
|
public void Register(string login, string password, string name)
|
|
{
|
|
if (string.IsNullOrEmpty(login) ||
|
|
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(name))
|
|
{
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
}
|
|
APIClient.PostRequest("api/company/register", new
|
|
CompanyBindingModel
|
|
{
|
|
Name = name,
|
|
Login = login,
|
|
Password = password
|
|
});
|
|
Response.Redirect("Enter");
|
|
return;
|
|
}
|
|
/* [HttpGet]
|
|
public IActionResult CreateTaskAssigment(int id)
|
|
{
|
|
id = taskId;
|
|
ViewBag.Tasks =
|
|
APIClient.GetRequest<List<EmployeeViewModel>>($"api/employee/gettasklist?projectId={taskId}");
|
|
var task = APIClient.GetRequest<EmployeeViewModel>($"api/task/gettask?id={id}");
|
|
if (task == null)
|
|
{
|
|
throw new Exception("gfd");
|
|
}
|
|
ViewBag.Tasks = new List<EmployeeViewModel>();
|
|
ViewBag.Tasks.Add(task);
|
|
|
|
ViewBag.Employees =
|
|
APIClient.GetRequest<List<EmployeeViewModel>>($"api/employee/getemployeelist?companyId={APIClient.Company.Id}");
|
|
return View();
|
|
}*/
|
|
[HttpPost]
|
|
public void CreateTaskAssigment(int id, int employeeId, string role)
|
|
{
|
|
if (APIClient.Company == null)
|
|
{
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
}
|
|
if (role == null)
|
|
{
|
|
Response.Redirect("/Home/TaskAssigments");
|
|
}
|
|
APIClient.PostRequest("api/task/createtaskassigment", new
|
|
TaskAssigmentBindingModel
|
|
{
|
|
EmployeeId = employeeId,
|
|
Role = role,
|
|
TaskId = id
|
|
});
|
|
|
|
Response.Redirect("/Home/TaskAssigments");
|
|
}
|
|
|
|
/* [HttpGet]
|
|
public IActionResult Create()
|
|
{
|
|
ViewBag.Products =
|
|
APIClient.GetRequest<List<ViewModel>>("api/main/getproductlist");
|
|
return View();
|
|
}*/
|
|
/*[HttpPost]
|
|
public void Create(int product, int count)
|
|
{
|
|
if (APIClient.Company == null)
|
|
{
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
}
|
|
if (count <= 0)
|
|
{
|
|
throw new Exception("Количество и сумма должны быть
|
|
больше 0");
|
|
}
|
|
APIClient.PostRequest("api/main/createorder", new
|
|
OrderBindingModel
|
|
{
|
|
ClientId = APIClient.Client.Id,
|
|
ProductId = product,
|
|
Count = count,
|
|
Sum = Calc(count, product)
|
|
});
|
|
Response.Redirect("Index");
|
|
}*/
|
|
|
|
}
|
|
} |