370 lines
9.5 KiB
C#
370 lines
9.5 KiB
C#
|
using ComputerShopImplementerApp.Models;
|
|||
|
using ComputerShopContracts.BindingModels;
|
|||
|
using ComputerShopContracts.ViewModels;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
using System.Diagnostics;
|
|||
|
using ComputerShopDataModels.Models;
|
|||
|
using Microsoft.Extensions.Hosting;
|
|||
|
|
|||
|
namespace ComputerShopImplementerApp.Controllers
|
|||
|
{
|
|||
|
public class HomeController : Controller
|
|||
|
{
|
|||
|
private readonly ILogger<HomeController> _logger;
|
|||
|
|
|||
|
public HomeController(ILogger<HomeController> logger)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
}
|
|||
|
|
|||
|
public IActionResult Index()
|
|||
|
{
|
|||
|
if (APIUser.User == null)
|
|||
|
{
|
|||
|
return Redirect("~/Home/Enter");
|
|||
|
}
|
|||
|
return View(/*APIUser.GetRequest<List<OrderViewModel>>($"api/main/getorders?userId={APIUser.User.Id}")*/);
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public IActionResult Privacy()
|
|||
|
{
|
|||
|
if (APIUser.User == null)
|
|||
|
{
|
|||
|
return Redirect("~/Home/Enter");
|
|||
|
}
|
|||
|
return View(APIUser.User);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public IActionResult CreateComponent()
|
|||
|
{
|
|||
|
return View();
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public IActionResult CreateProduct()
|
|||
|
{
|
|||
|
return View();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
|
|||
|
public IActionResult CreateRequest()
|
|||
|
{
|
|||
|
List<AssemblyViewModel> products = new List<AssemblyViewModel>
|
|||
|
{
|
|||
|
new AssemblyViewModel
|
|||
|
{
|
|||
|
Id = 1,
|
|||
|
AssemblyName = "Сборка 1",
|
|||
|
Cost = 105,
|
|||
|
UserId = 1
|
|||
|
},
|
|||
|
new AssemblyViewModel
|
|||
|
{
|
|||
|
Id = 2,
|
|||
|
AssemblyName = "Сборка 2",
|
|||
|
Cost = 205,
|
|||
|
UserId = 1
|
|||
|
}
|
|||
|
};
|
|||
|
return View(products);
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public IActionResult CreateAssembly()
|
|||
|
{
|
|||
|
var components = new List<ComponentViewModel>();
|
|||
|
components.Add(new ComponentViewModel
|
|||
|
{
|
|||
|
Id = 1,
|
|||
|
ComponentName = "Комплектующее 1",
|
|||
|
Cost = 55.5,
|
|||
|
Description = "Описание",
|
|||
|
UserId = 1
|
|||
|
});
|
|||
|
components.Add(new ComponentViewModel
|
|||
|
{
|
|||
|
Id = 2,
|
|||
|
ComponentName = "Комплектующее 2",
|
|||
|
Cost = 15,
|
|||
|
Description = "Описание",
|
|||
|
UserId = 1
|
|||
|
});
|
|||
|
return View(components);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
|
|||
|
public IActionResult CreateBatch()
|
|||
|
{
|
|||
|
List<ProductViewModel> products = new List<ProductViewModel>
|
|||
|
{
|
|||
|
new ProductViewModel
|
|||
|
{
|
|||
|
Id = 1,
|
|||
|
ProductName = "Товар 1",
|
|||
|
Cost = 10.99,
|
|||
|
UserId = 1,
|
|||
|
Description = "Описание",
|
|||
|
BatchId = 1
|
|||
|
},
|
|||
|
new ProductViewModel
|
|||
|
{
|
|||
|
Id = 1,
|
|||
|
ProductName = "Товар 1",
|
|||
|
Cost = 18,
|
|||
|
UserId = 1,
|
|||
|
Description = "Описание",
|
|||
|
BatchId = 2
|
|||
|
}
|
|||
|
};
|
|||
|
return View(products);
|
|||
|
}
|
|||
|
|
|||
|
public IActionResult IndexComponent()
|
|||
|
{
|
|||
|
var components = new List<ComponentViewModel>();
|
|||
|
components.Add(new ComponentViewModel
|
|||
|
{
|
|||
|
Id = 1,
|
|||
|
ComponentName = "Комплектующее 1",
|
|||
|
Cost = 55.5,
|
|||
|
Description = "Описание",
|
|||
|
UserId = 1
|
|||
|
});
|
|||
|
components.Add(new ComponentViewModel
|
|||
|
{
|
|||
|
Id = 2,
|
|||
|
ComponentName = "Комплектующее 2",
|
|||
|
Cost = 15,
|
|||
|
Description = "Описание",
|
|||
|
UserId = 1
|
|||
|
});
|
|||
|
return View(components);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public IActionResult IndexProduct()
|
|||
|
{
|
|||
|
List<ProductViewModel> products = new List<ProductViewModel>
|
|||
|
{
|
|||
|
new ProductViewModel
|
|||
|
{
|
|||
|
Id = 1,
|
|||
|
ProductName = "Товар 1",
|
|||
|
Cost = 10.99,
|
|||
|
UserId = 1,
|
|||
|
Description = "Описание",
|
|||
|
BatchId = 1
|
|||
|
},
|
|||
|
new ProductViewModel
|
|||
|
{
|
|||
|
Id = 1,
|
|||
|
ProductName = "Товар 1",
|
|||
|
Cost = 18,
|
|||
|
UserId = 1,
|
|||
|
Description = "Описание",
|
|||
|
BatchId = 2
|
|||
|
}
|
|||
|
};
|
|||
|
return View(products);
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
|
|||
|
public IActionResult IndexRequest()
|
|||
|
{
|
|||
|
List<RequestViewModel> products = new List<RequestViewModel>
|
|||
|
{
|
|||
|
new RequestViewModel
|
|||
|
{
|
|||
|
Id = 1,
|
|||
|
AssemblyId = 1
|
|||
|
},
|
|||
|
new RequestViewModel
|
|||
|
{
|
|||
|
Id = 2,
|
|||
|
AssemblyId = 2
|
|||
|
},
|
|||
|
};
|
|||
|
return View(products);
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
|
|||
|
public IActionResult IndexAssembly()
|
|||
|
{
|
|||
|
List<AssemblyViewModel> products = new List<AssemblyViewModel>
|
|||
|
{
|
|||
|
new AssemblyViewModel
|
|||
|
{
|
|||
|
Id = 1,
|
|||
|
AssemblyName = "Сборка 1",
|
|||
|
Cost = 105,
|
|||
|
UserId = 1
|
|||
|
},
|
|||
|
new AssemblyViewModel
|
|||
|
{
|
|||
|
Id = 2,
|
|||
|
AssemblyName = "Сборка 2",
|
|||
|
Cost = 205,
|
|||
|
UserId = 1
|
|||
|
}
|
|||
|
};
|
|||
|
return View(products);
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public IActionResult IndexBatch()
|
|||
|
{
|
|||
|
List<BatchViewModel> products = new List<BatchViewModel>
|
|||
|
{
|
|||
|
new BatchViewModel
|
|||
|
{
|
|||
|
Id = 1,
|
|||
|
ProductId = 1
|
|||
|
},
|
|||
|
new BatchViewModel
|
|||
|
{
|
|||
|
Id = 2,
|
|||
|
ProductId = 2
|
|||
|
},
|
|||
|
};
|
|||
|
return View(products);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
|
|||
|
public IActionResult ComponentRequestAssemblyReport()
|
|||
|
{
|
|||
|
List<ComponentRequestAssemblyReportViewModel> detailTimeReports = new List<ComponentRequestAssemblyReportViewModel>
|
|||
|
{
|
|||
|
new ComponentRequestAssemblyReportViewModel
|
|||
|
{
|
|||
|
ComponentName = "Комплектующее 1",
|
|||
|
DateRequests = new List<DateTime> { DateTime.Today, DateTime.Now },
|
|||
|
Assemblies = new List<string> {"Сборка 1", "Сборка 2"}
|
|||
|
},
|
|||
|
new ComponentRequestAssemblyReportViewModel
|
|||
|
{
|
|||
|
ComponentName = "Комплектующее 2",
|
|||
|
DateRequests = new List<DateTime> { DateTime.Today, DateTime.Now },
|
|||
|
Assemblies = new List<string> {"Сборка 3", "Сборка 4"}
|
|||
|
},
|
|||
|
};
|
|||
|
return View(detailTimeReports);
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
|
|||
|
public IActionResult ComponentBatchReport()
|
|||
|
{
|
|||
|
List<ComponentBatchReportViewModel> detailTimeReports = new List<ComponentBatchReportViewModel>
|
|||
|
{
|
|||
|
new ComponentBatchReportViewModel
|
|||
|
{
|
|||
|
ComponentName = "Комплектующее 1",
|
|||
|
DateBatch = new List<DateTime> { DateTime.Today, DateTime.Now },
|
|||
|
},
|
|||
|
new ComponentBatchReportViewModel
|
|||
|
{
|
|||
|
ComponentName = "Комплектующее 1",
|
|||
|
DateBatch = new List<DateTime> { DateTime.Today, DateTime.Now },
|
|||
|
}
|
|||
|
};
|
|||
|
return View(detailTimeReports);
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public IActionResult ReportsMenu()
|
|||
|
{
|
|||
|
return View();
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void Privacy(string fio, string phonenumber, string login, string password, string email)
|
|||
|
{
|
|||
|
if (APIUser.User == null)
|
|||
|
{
|
|||
|
throw new Exception("Требуется авторизация");
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
|
|||
|
{
|
|||
|
throw new Exception("Требуется логин, пароль и email");
|
|||
|
}
|
|||
|
APIUser.PostRequest("api/user/updatedata", new UserBindingModel
|
|||
|
{
|
|||
|
Id = APIUser.User.Id,
|
|||
|
Fio = fio,
|
|||
|
PhoneNumber = phonenumber,
|
|||
|
Login = login,
|
|||
|
Password = password,
|
|||
|
Email = email
|
|||
|
});
|
|||
|
|
|||
|
APIUser.User.Fio = fio;
|
|||
|
APIUser.User.PhoneNumber = phonenumber;
|
|||
|
APIUser.User.Password = password;
|
|||
|
APIUser.User.Email = email;
|
|||
|
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("Введите логин и пароль");
|
|||
|
}
|
|||
|
APIUser.User = APIUser.GetRequest<UserViewModel>($"api/user/loginimplementer?login={login}&password={password}");
|
|||
|
if (APIUser.User == null)
|
|||
|
{
|
|||
|
throw new Exception("Не верный логин или пароль");
|
|||
|
}
|
|||
|
Response.Redirect("Index");
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public IActionResult Register()
|
|||
|
{
|
|||
|
return View();
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void Register(string fio, string phonenumber, string login, string password, string email)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
|
|||
|
{
|
|||
|
throw new Exception("Введите логин, пароль, почту");
|
|||
|
}
|
|||
|
APIUser.PostRequest("api/user/registerimplementer", new UserBindingModel
|
|||
|
{
|
|||
|
Fio = fio,
|
|||
|
PhoneNumber = phonenumber,
|
|||
|
Login = login,
|
|||
|
Password = password,
|
|||
|
Email = email
|
|||
|
});
|
|||
|
Response.Redirect("Enter");
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|