плиз. заработай
This commit is contained in:
parent
b8faed1ea0
commit
e20b32b25c
@ -1,68 +0,0 @@
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
namespace WorkerWebApp
|
||||
{
|
||||
public class APIClient
|
||||
{
|
||||
private static readonly HttpClient _client = new();
|
||||
|
||||
public static ClientViewModel? Client { get; set; } = null;
|
||||
|
||||
public static void Connect(IConfiguration configuration)
|
||||
{
|
||||
_client.BaseAddress = new Uri(configuration["IPAddress"]!);
|
||||
_client.DefaultRequestHeaders.Accept.Clear();
|
||||
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
}
|
||||
|
||||
public static T? GetRequest<T>(string requestUrl)
|
||||
{
|
||||
var response = _client.GetAsync(requestUrl);
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
Console.WriteLine(requestUrl);
|
||||
if (response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PostRequest<T>(string requestUrl, T model)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
var data = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
var response = _client.PostAsync(requestUrl, data);
|
||||
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (!response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
|
||||
public static O? PostRequestWithResult<I, O>(string requestUrl, I model)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
var data = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
var response = _client.PostAsync(requestUrl, data);
|
||||
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<O>(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
49
BeautySalonView/ClientWebApp/APIWorker.cs
Normal file
49
BeautySalonView/ClientWebApp/APIWorker.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
namespace WorkerWebApp
|
||||
{
|
||||
public class APIWorker
|
||||
{
|
||||
private static readonly HttpClient _worker = new();
|
||||
|
||||
public static WorkerViewModel? Worker { get; set; } = null;
|
||||
|
||||
public static void Connect(IConfiguration configuration)
|
||||
{
|
||||
_worker.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||
_worker.DefaultRequestHeaders.Accept.Clear();
|
||||
_worker.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
}
|
||||
|
||||
public static T? GetRequest<T>(string requestUrl)
|
||||
{
|
||||
var response = _worker.GetAsync(requestUrl);
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PostRequest<T>(string requestUrl, T model)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
var data = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
var response = _worker.PostAsync(requestUrl, data);
|
||||
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (!response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
using BeautySalonContracts.BindingModels;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace WorkerWebApp.Controllers
|
||||
{
|
||||
public class EvaluationController : Controller
|
||||
{
|
||||
public IActionResult Create()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Procedure = APIClient.GetRequest<List<ProcedureViewModel>>($"api/procedure/getall?userId={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Create(string pointsProcedure, string pointsCosmetics, int procedureId)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
APIClient.PostRequest("api/evaluation/create", new EvaluationBindingModel
|
||||
{
|
||||
ClientId = APIClient.Client.Id,
|
||||
PointsProcedure = double.Parse(pointsProcedure.Replace(".", ",")),
|
||||
PointsCosmetics = double.Parse(pointsCosmetics.Replace(".", ",")),
|
||||
ProcedureId = procedureId
|
||||
});
|
||||
Response.Redirect("/Home/Evaluation");
|
||||
}
|
||||
|
||||
public IActionResult Update(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Evaluation = APIClient.GetRequest<EvaluationBindingModel>
|
||||
($"api/evaluation/get?id={id}");
|
||||
ViewBag.Procedure = APIClient.GetRequest<List<ProcedureViewModel>>($"api/procedure/getall?userId={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Update(int id, string pointsProcedure, string pointsCosmetics, int procedureId)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
APIClient.PostRequest("api/evaluation/update", new EvaluationBindingModel
|
||||
{
|
||||
Id = id,
|
||||
PointsProcedure = double.Parse(pointsProcedure.Replace(".", ",")),
|
||||
PointsCosmetics = double.Parse(pointsCosmetics.Replace(".", ",")),
|
||||
ProcedureId = procedureId
|
||||
});
|
||||
Response.Redirect("/Home/Evaluation");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Delete(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
APIClient.PostRequest($"api/evaluation/delete",
|
||||
new ServiceBindingModel() { Id = id });
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -17,171 +17,127 @@ namespace WorkerWebApp.Controllers
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IActionResult Enter()
|
||||
public IActionResult Index()
|
||||
{
|
||||
//if (APIWorker.Worker == null)
|
||||
//{
|
||||
// return Redirect("~/Home/Enter");
|
||||
//}
|
||||
//return View(APIWorker.GetRequest<List<OrderViewModel>>($"api/main/getorders?workerId={APIWorker.Worker.Id}"));
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIWorker.Worker);
|
||||
}
|
||||
[HttpPost]
|
||||
|
||||
public void Privacy(string login, string password, string fio)
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(login) ||
|
||||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
throw new Exception("Введите логин, пароль и ФИО");
|
||||
}
|
||||
APIWorker.PostRequest("api/worker/updatedata", new WorkerBindingModel
|
||||
{
|
||||
Id = APIWorker.Worker.Id,
|
||||
FullName = fio,
|
||||
Email = login,
|
||||
Password = password
|
||||
});
|
||||
APIWorker.Worker.FullName = fio;
|
||||
APIWorker.Worker.Email = login;
|
||||
APIWorker.Worker.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))
|
||||
if (string.IsNullOrEmpty(login) ||
|
||||
string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new Exception("Введите логин и пароль");
|
||||
}
|
||||
APIClient.Client = APIClient.GetRequest<ClientViewModel>($"api/client/login?login={login}&password={password}");
|
||||
if (APIClient.Client == null)
|
||||
APIWorker.Worker =
|
||||
APIWorker.GetRequest<WorkerViewModel>($"api/worker/login?login={login}&password={password}");
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Неверный логин/пароль");
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
public IActionResult Procedure(int page)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
if (page == 0)
|
||||
{
|
||||
page = 1;
|
||||
}
|
||||
ViewBag.Procedure = APIClient.GetRequest<List<ProcedureViewModel>>
|
||||
($"api/procedure/getmany?userId={APIClient.Client.Id}&page={page}");
|
||||
ViewBag.Page = page;
|
||||
ViewBag.NumberOfPages = APIClient.GetRequest<int>
|
||||
($"api/procedure/getnumberofpages?userId={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(string login, string password, string email)
|
||||
public void Register(string login, string password, string fio)
|
||||
{
|
||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
|
||||
if (string.IsNullOrEmpty(login) ||
|
||||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
throw new Exception("Введите логин, пароль и ФИО");
|
||||
}
|
||||
APIClient.PostRequest("api/client/register", new ClientBindingModel
|
||||
APIWorker.PostRequest("api/worker/register", new
|
||||
WorkerBindingModel
|
||||
{
|
||||
ClientEmail = email,
|
||||
ClientLogin = login,
|
||||
ClientPassword = password
|
||||
FullName = fio,
|
||||
Email = login,
|
||||
Password = password
|
||||
});
|
||||
Response.Redirect("Enter");
|
||||
return;
|
||||
}
|
||||
|
||||
public IActionResult Order(int page)
|
||||
[HttpGet]
|
||||
public IActionResult Orders()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
if (page == 0)
|
||||
{
|
||||
page = 1;
|
||||
}
|
||||
ViewBag.Order = APIClient.GetRequest<List<OrderViewModel>>
|
||||
($"api/order/getmany?userId={APIClient.Client.Id}&page={page}");
|
||||
ViewBag.Page = page;
|
||||
ViewBag.NumberOfPages = APIClient.GetRequest<int>
|
||||
($"api/order/getnumberofpages?userId={APIClient.Client.Id}");
|
||||
return View();
|
||||
return View(new List<OrderViewModel>());
|
||||
}
|
||||
|
||||
public IActionResult Evaluation(int page)
|
||||
[HttpGet]
|
||||
public IActionResult Procedures()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
if (page == 0)
|
||||
{
|
||||
page = 1;
|
||||
}
|
||||
ViewBag.Evaluation = APIClient.GetRequest<List<EvaluationViewModel>>
|
||||
($"api/evaluation/getmany?userId={APIClient.Client.Id}&page={page}");
|
||||
ViewBag.Page = page;
|
||||
ViewBag.NumberOfPages = APIClient.GetRequest<int>
|
||||
($"api/evaluation/getnumberofpages?userId={APIClient.Client.Id}");
|
||||
return View();
|
||||
return View(new List<ProcedureViewModel>());
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
[HttpGet]
|
||||
public IActionResult Evaluations()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
return View(new List<EvaluationViewModel>());
|
||||
}
|
||||
|
||||
public IActionResult FormationOrder()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult FormingAnEvaluation()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult LinkingProceduresForSelectedOrders()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult ServiceList()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.IsAllowed = true;
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public int[]? ServiceList([FromBody] ServiceBindingModel listModel)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Array.Empty<int>();
|
||||
}
|
||||
byte[]? file = APIClient.PostRequestWithResult<ServiceBindingModel, byte[]>
|
||||
("api/client/ListServices", listModel);
|
||||
return file!.Select(b => (int)b).ToArray();
|
||||
}
|
||||
|
||||
public IActionResult OrderFormationAccordingProcedures()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Report()
|
||||
{
|
||||
return View();
|
||||
return View(new List<ProcedureViewModel>()); //вот тут вопрос
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
public IActionResult OrderList()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Mails()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
|
||||
return View(new List<OrderViewModel>()); //тут тоже вопрос
|
||||
}
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
using BeautySalonContracts.BindingModels;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using WorkerWebApp;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace WorkerWebApp.Controllers
|
||||
{
|
||||
public class OrderController : Controller
|
||||
{
|
||||
public IActionResult Create()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Create([FromBody] OrderBindingModel orderModel)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
orderModel.ClientId = APIClient.Client.Id;
|
||||
APIClient.PostRequest("api/order/create", orderModel);
|
||||
}
|
||||
|
||||
public IActionResult Update(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Id = id;
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Update([FromBody] OrderBindingModel orderModel)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
orderModel.ClientId = APIClient.Client.Id;
|
||||
APIClient.PostRequest("api/order/update", orderModel);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Delete(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
APIClient.PostRequest($"api/order/delete",
|
||||
new OrderBindingModel() { Id = id });
|
||||
return;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ServiceViewModel>? GetAllServices()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
var services = APIClient.GetRequest<List<ServiceViewModel>>($"api/service/getall");
|
||||
return services;
|
||||
}
|
||||
|
||||
public OrderViewModel? Get(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
OrderViewModel? order = APIClient
|
||||
.GetRequest<OrderViewModel>($"api/order/get?id={id}");
|
||||
return order;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? GetAllByUser()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
List<OrderViewModel>? order = APIClient
|
||||
.GetRequest< List<OrderViewModel>>($"api/order/GetAllByUser?userId={APIClient.Client.Id}");
|
||||
return order;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
using BeautySalonContracts.BindingModels;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using WorkerWebApp;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace WorkerWebApp.Controllers
|
||||
{
|
||||
public class ProcedureController : Controller
|
||||
{
|
||||
public IActionResult Create()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Create([FromBody] ProcedureBindingModel procedureModel)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
procedureModel.ClientId = APIClient.Client.Id;
|
||||
APIClient.PostRequest("api/procedure/create", procedureModel);
|
||||
}
|
||||
|
||||
public IActionResult Update(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Id = id;
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Update([FromBody] ProcedureBindingModel procedureModel)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
procedureModel.ClientId = APIClient.Client.Id;
|
||||
APIClient.PostRequest("api/procedure/update", procedureModel);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Delete(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
APIClient.PostRequest($"api/procedure/delete",
|
||||
new ProcedureBindingModel() { Id = id });
|
||||
return;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<CosmeticViewModel>? GetAllCosmetics()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
var cosmetics = APIClient.GetRequest<List<CosmeticViewModel>>($"api/cosmetic/getall");
|
||||
return cosmetics;
|
||||
}
|
||||
|
||||
public ProcedureViewModel? Get(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
ProcedureViewModel? procedure = APIClient
|
||||
.GetRequest<ProcedureViewModel>($"api/procedure/get?id={id}");
|
||||
return procedure;
|
||||
}
|
||||
|
||||
public List<ProcedureViewModel>? GetAllByUser()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
List<ProcedureViewModel>? procedures = APIClient.GetRequest<List<ProcedureViewModel>>
|
||||
($"api/procedure/getallbyuser?userId={APIClient.Client.Id}");
|
||||
return procedures;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +1,21 @@
|
||||
@{
|
||||
ViewData["Title"] = "Вход";
|
||||
ViewData["Title"] = "Enter";
|
||||
}
|
||||
|
||||
<h4 class="fw-bold">Вход в приложение</h4>
|
||||
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Вход в приложение</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
<label for="login" class="form-label">Логин:</label>
|
||||
<input id="login" name="login" type="text" class="form-control" aria-label="Login">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Пароль:</label>
|
||||
<input id="password" name="password" type="password" class="form-control" aria-label="Password">
|
||||
</div>
|
||||
<button type="submit" class="btn button-primary">
|
||||
Войти
|
||||
</button>
|
||||
<div class="row">
|
||||
<div class="col-4">Логин:</div>
|
||||
<div class="col-8"><input type="text" name="login" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Пароль:</div>
|
||||
<div class="col-8"><input type="password" name="password" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Вход" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
@ -36,6 +36,7 @@
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
</tbody>
|
||||
|
@ -1,67 +0,0 @@
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
namespace StorekeeperWebApp
|
||||
{
|
||||
public class APIClient
|
||||
{
|
||||
private static readonly HttpClient _client = new();
|
||||
|
||||
public static StaffMemberViewModel? Client { get; set; } = null;
|
||||
|
||||
public static void Connect(IConfiguration configuration)
|
||||
{
|
||||
_client.BaseAddress = new Uri(configuration["IPAddress"]!);
|
||||
_client.DefaultRequestHeaders.Accept.Clear();
|
||||
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
}
|
||||
|
||||
public static T? GetRequest<T>(string requestUrl)
|
||||
{
|
||||
var response = _client.GetAsync(requestUrl);
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PostRequest<T>(string requestUrl, T model)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
var data = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
var response = _client.PostAsync(requestUrl, data);
|
||||
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (!response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
|
||||
public static O? PostRequestWithResult<I, O>(string requestUrl, I model)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
var data = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
var response = _client.PostAsync(requestUrl, data);
|
||||
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<O>(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
49
BeautySalonView/StaffMemberWebApp/APIStorekeeper.cs
Normal file
49
BeautySalonView/StaffMemberWebApp/APIStorekeeper.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
namespace StorekeeperWebApp
|
||||
{
|
||||
public class APIStorekeeper
|
||||
{
|
||||
private static readonly HttpClient _storekeeper = new();
|
||||
|
||||
public static StorekeeperViewModel? Storekeeper { get; set; } = null;
|
||||
|
||||
public static void Connect(IConfiguration configuration)
|
||||
{
|
||||
_storekeeper.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||
_storekeeper.DefaultRequestHeaders.Accept.Clear();
|
||||
_storekeeper.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
}
|
||||
|
||||
public static T? GetRequest<T>(string requestUrl)
|
||||
{
|
||||
var response = _storekeeper.GetAsync(requestUrl);
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PostRequest<T>(string requestUrl, T model)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
var data = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
var response = _storekeeper.PostAsync(requestUrl, data);
|
||||
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (!response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
using BeautySalonContracts.BindingModels;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace StorekeeperWebApp.Controllers
|
||||
{
|
||||
public class CosmeticController : Controller
|
||||
{
|
||||
public IActionResult Create()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Create(string brand, string cosmeticName, string cosmeticPrice)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
APIClient.PostRequest("api/cosmetic/create", new CosmeticBindingModel
|
||||
{
|
||||
LaborCostId = APIClient.Client.Id,
|
||||
Brand = brand,
|
||||
CosmeticName = cosmeticName,
|
||||
CosmeticPrice = double.Parse(cosmeticPrice.Replace(".", ","))
|
||||
|
||||
});
|
||||
Response.Redirect("/Home/Cosmetic");
|
||||
}
|
||||
|
||||
public IActionResult Update(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Service = APIClient.GetRequest<ServiceBindingModel>
|
||||
($"api/service/get?id={id}");
|
||||
ViewBag.Procedure = APIClient.GetRequest<ProcedureBindingModel>
|
||||
($"api/procedure/get?id={id}");
|
||||
ViewBag.Cosmetic = APIClient.GetRequest<List<LaborCostsViewModel>>
|
||||
($"api/cosmetic/getall?userId={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Update(int id, string brand, string cosmeticName, string cosmeticPrice)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
APIClient.PostRequest("api/cosmetic/update", new CosmeticBindingModel
|
||||
{
|
||||
Id = id,
|
||||
Brand = brand,
|
||||
CosmeticName = cosmeticName,
|
||||
CosmeticPrice = double.Parse(cosmeticPrice.Replace(".", ","))
|
||||
});
|
||||
Response.Redirect("/Home/Wishes");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Delete(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
APIClient.PostRequest($"api/cosmetic/delete",
|
||||
new ServiceBindingModel() { Id = id });
|
||||
return;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ProcedureViewModel>? GetAllProcedures()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
var procedures = APIClient.GetRequest<List<ProcedureViewModel>>($"api/procedure/getall");
|
||||
return procedures;
|
||||
}
|
||||
[HttpGet]
|
||||
public List<CosmeticViewModel>? GetAllByUser()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var cosmetics = APIClient.GetRequest<List<CosmeticViewModel>>
|
||||
($"api/cosmetic/getallbyuser?userId={APIClient.Client.Id}");
|
||||
return cosmetics;
|
||||
}
|
||||
}
|
||||
}
|
@ -10,183 +10,171 @@ namespace SStorekeeperWebApp.Controllers
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return
|
||||
View(APIStorekeeper.GetRequest<List<OrderViewModel>>($"api/main/getorders?storekeeperId={APIStorekeeper.Storekeeper.Id}"));
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIStorekeeper.Storekeeper);
|
||||
}
|
||||
[HttpPost]
|
||||
public void Privacy(string login, string password, string fio)
|
||||
{
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(login) ||
|
||||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
throw new Exception("Введите логин, пароль и ФИО");
|
||||
}
|
||||
APIStorekeeper.PostRequest("api/storekeeper/updatedata", new StorekeeperBindingModel
|
||||
{
|
||||
Id = APIStorekeeper.Storekeeper.Id,
|
||||
FullName = fio,
|
||||
Email = login,
|
||||
Password = password
|
||||
});
|
||||
APIStorekeeper.Storekeeper.FullName = fio;
|
||||
APIStorekeeper.Storekeeper.Email = login;
|
||||
APIStorekeeper.Storekeeper.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))
|
||||
if (string.IsNullOrEmpty(login) ||
|
||||
string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new Exception("Введите логин и пароль");
|
||||
}
|
||||
APIClient.Client = APIClient.GetRequest<StaffMemberViewModel>($"api/staffmember/login?login={login}&password={password}");
|
||||
if (APIClient.Client == null)
|
||||
APIStorekeeper.Storekeeper =
|
||||
APIStorekeeper.GetRequest<StorekeeperViewModel>($"api/storekeeper/login?login={login}&password={password}");
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
throw new Exception("Неверный логин/пароль");
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
public IActionResult LaborCosts(int page)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
if (page == 0)
|
||||
{
|
||||
page = 1;
|
||||
}
|
||||
ViewBag.LaborCosts = APIClient.GetRequest<List<LaborCostsViewModel>>
|
||||
($"api/laborcosts/getmany?userId={APIClient.Client.Id}&page={page}");
|
||||
ViewBag.Page = page;
|
||||
ViewBag.NumberOfPages = APIClient.GetRequest<int>
|
||||
($"api/laborcosts/getnumberofpages?userId={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
public IActionResult Cosmetic(int page)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
if (page == 0)
|
||||
{
|
||||
page = 1;
|
||||
}
|
||||
ViewBag.Cosmetic = APIClient.GetRequest<List<CosmeticViewModel>>
|
||||
($"api/cosmetic/getmany?userId={APIClient.Client.Id}&page={page}");
|
||||
ViewBag.Page = page;
|
||||
ViewBag.NumberOfPages = APIClient.GetRequest<int>
|
||||
($"api/cosmetic/getnumberofpages?userId={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
public IActionResult Service(int page)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
if (page == 0)
|
||||
{
|
||||
page = 1;
|
||||
}
|
||||
ViewBag.Service = APIClient.GetRequest<List<ServiceViewModel>>
|
||||
($"api/service/getmany?userId={APIClient.Client.Id}&page={page}");
|
||||
ViewBag.Page = page;
|
||||
ViewBag.NumberOfPages = APIClient.GetRequest<int>
|
||||
($"api/service/getnumberofpages?userId={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult LaborCostsService()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult ListCosmetics()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.IsAllowed = true;
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public int[]? ListCosmetics([FromBody] CosmeticBindingModel listModel)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Array.Empty<int>();
|
||||
}
|
||||
byte[]? file = APIClient.PostRequestWithResult<CosmeticBindingModel, byte[]>
|
||||
("api/report/ListCosmetics", listModel);
|
||||
return file!.Select(b => (int)b).ToArray();
|
||||
}
|
||||
|
||||
public IActionResult ProcedureCosmetic()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(string login, string password, string email)
|
||||
public void Register(string login, string password, string fio)
|
||||
{
|
||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
|
||||
if (string.IsNullOrEmpty(login) ||
|
||||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
throw new Exception("Введите логин, пароль и ФИО");
|
||||
}
|
||||
APIClient.PostRequest("api/staffmember/register", new StaffMemberBindingModel
|
||||
APIStorekeeper.PostRequest("api/storekeeper/register", new
|
||||
StorekeeperBindingModel
|
||||
{
|
||||
StaffMemberEmail = email,
|
||||
StaffMemberLogin = login,
|
||||
StaffMemberPassword = password
|
||||
FullName = fio,
|
||||
Email = login,
|
||||
Password = password
|
||||
});
|
||||
Response.Redirect("Enter");
|
||||
return;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
//повар
|
||||
[HttpGet]
|
||||
public IActionResult Services()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
return View(new List<ServiceViewModel>());
|
||||
}
|
||||
public IActionResult Report()
|
||||
[HttpGet]
|
||||
public IActionResult ServiceCreate()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult ServiceCosmetic()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
return View(new List<ServiceViewModel>());
|
||||
}
|
||||
[HttpPost]
|
||||
public List<ServiceViewModel>? Report([FromBody] StaffMemberBindingModel reportModel)
|
||||
public void ServiceCreate(string serviceName, int servicePrice, int experience)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
/*if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
reportModel.StaffMemberFIO = APIClient.Client.Id;
|
||||
List<ServiceViewModel>? list = APIClient.PostRequestWithResult
|
||||
<StaffMemberBindingModel, List<ServiceViewModel>>
|
||||
("api/report/GetServicesReportData", reportModel);
|
||||
return list;
|
||||
throw new Exception("Вход только авторизованным");
|
||||
}*/
|
||||
APIStorekeeper.PostRequest("api/chef/chefcreate", new ServiceBindingModel
|
||||
{
|
||||
StorekeeperId = APIStorekeeper.Storekeeper.Id,
|
||||
ServiceName = serviceName,
|
||||
ServicePrice = servicePrice,
|
||||
|
||||
});
|
||||
Response.Redirect("Chefs");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult LaborCostUpdate()
|
||||
{
|
||||
return View(new List<LaborCostsViewModel>());//тут тоже вопрос
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Mails()
|
||||
public IActionResult Cosmetics()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
|
||||
return View(new List<CosmeticViewModel>());//уверенности ноль
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult CosmeticCreate()
|
||||
{
|
||||
return View(new List<CosmeticViewModel>());
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult CosmeticUpdate()
|
||||
{
|
||||
return View(new List<CosmeticViewModel>());
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult LaborCosts()
|
||||
{
|
||||
return View(new List<LaborCostsViewModel>());
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Report()
|
||||
{
|
||||
return View(new List<ServiceViewModel>());//вопрос
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult List()
|
||||
{
|
||||
return View(new List<CosmeticViewModel>());//вопрос
|
||||
}
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
using BeautySalonContracts.BindingModels;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace StorekeeperWebApp.Controllers
|
||||
{
|
||||
public class LaborCostsController : Controller
|
||||
{
|
||||
public IActionResult Create()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Create(int numberHours, string difficulty)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
APIClient.PostRequest("api/laborcosts/create", new LaborCostsBindingModel
|
||||
{
|
||||
StaffMemberId = APIClient.Client.Id,
|
||||
NumberHours = numberHours,
|
||||
Difficulty = difficulty
|
||||
}); ;
|
||||
Response.Redirect("/Home/LaborCosts");
|
||||
}
|
||||
|
||||
public IActionResult Update(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.LaborCosts = APIClient.GetRequest<LaborCostsBindingModel>($"api/laborcosts/get?id={id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Update(int id, int numberHours, string difficulty)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
APIClient.PostRequest("api/laborcosts/update", new LaborCostsBindingModel
|
||||
{
|
||||
Id = id,
|
||||
NumberHours = numberHours,
|
||||
Difficulty = difficulty
|
||||
});
|
||||
Response.Redirect("/Home/LaborCosts");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Delete(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
APIClient.PostRequest($"api/laborcosts/delete",
|
||||
new ServiceBindingModel() { Id = id });
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
using BeautySalonContracts.BindingModels;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace StorekeeperWebApp.Controllers
|
||||
{
|
||||
public class ServiceController : Controller
|
||||
{
|
||||
public IActionResult Create()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.LaborCostsList = APIClient.GetRequest<List<LaborCostsViewModel>>($"api/laborcosts/getall?userId={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Create(string serviceName, string servicePrice, int laborCostsId)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
APIClient.PostRequest("api/service/create", new ServiceBindingModel
|
||||
{
|
||||
StaffMemberId = APIClient.Client.Id,
|
||||
ServiceName = serviceName,
|
||||
ServicePrice = double.Parse(servicePrice.Replace(".", ",")),
|
||||
});
|
||||
Response.Redirect("/Home/Service");
|
||||
}
|
||||
|
||||
public IActionResult Update(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Service = APIClient.GetRequest<ServiceBindingModel>
|
||||
($"api/service/get?id={id}");
|
||||
ViewBag.LaborCostsList = APIClient.GetRequest<List<LaborCostsViewModel>>
|
||||
($"api/laborcosts/getall?userId={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Update(int id, string serviceName, string servicePrice, int laborCostsId)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
APIClient.PostRequest("api/service/update", new ServiceBindingModel
|
||||
{
|
||||
Id = id,
|
||||
StaffMemberId = APIClient.Client.Id,
|
||||
ServiceName = serviceName,
|
||||
ServicePrice = double.Parse(servicePrice.Replace(".", ",")),
|
||||
});
|
||||
Response.Redirect("/Home/Service");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Delete(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
APIClient.PostRequest($"api/service/delete",
|
||||
new ServiceBindingModel() { Id = id });
|
||||
return;
|
||||
}
|
||||
|
||||
public IActionResult Bind(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.ServiceId = id;
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Bind([FromBody] ServiceBindingModel serviceModel)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("403");
|
||||
}
|
||||
APIClient.PostRequest("api/service/update", serviceModel);
|
||||
}
|
||||
|
||||
public ServiceViewModel? Get(int id)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
ServiceViewModel? service = APIClient
|
||||
.GetRequest<ServiceViewModel>($"api/service/get?id={id}");
|
||||
return service;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user