interim commit
This commit is contained in:
parent
40c8117b7f
commit
35aef0cdb5
@ -3,6 +3,7 @@ using CanteenContracts.BusinessLogicsContracts;
|
||||
using CanteenContracts.SearchModel;
|
||||
using CanteenContracts.StoragesContracts;
|
||||
using CanteenContracts.View;
|
||||
using CanteenDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -22,6 +23,28 @@ namespace CanteenBusinessLogic.BusinessLogics
|
||||
_logger = logger;
|
||||
_productStorage = productStorage;
|
||||
}
|
||||
|
||||
public bool AddCooksToProduct(ProductSearchModel model, ICookModel cook)
|
||||
{
|
||||
var product = _productStorage.GetElement(model);
|
||||
product.ProductCooks[cook.Id] = cook;
|
||||
if (_productStorage.Update(new()
|
||||
{
|
||||
Id = product.Id,
|
||||
ProductName = product.ProductName,
|
||||
Price = product.Price,
|
||||
ManagerId = product.ManagerId,
|
||||
ProductCooks = product.ProductCooks
|
||||
|
||||
}) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Create(ProductBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
@ -0,0 +1,17 @@
|
||||
using CanteenContracts.SearchModel;
|
||||
using CanteenContracts.View;
|
||||
using CanteenDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CanteenContracts.BindingModels
|
||||
{
|
||||
public class ProductCookBindingModel
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
public List<ICookModel> Cooks { get; set; } = new();
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using CanteenContracts.BindingModels;
|
||||
using CanteenContracts.SearchModel;
|
||||
using CanteenContracts.View;
|
||||
using CanteenDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -16,5 +17,6 @@ namespace CanteenContracts.BusinessLogicsContracts
|
||||
bool Create(ProductBindingModel model);
|
||||
bool Update(ProductBindingModel model);
|
||||
bool Delete(ProductBindingModel model);
|
||||
bool AddCooksToProduct(ProductSearchModel model, ICookModel cook);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,10 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CanteenDataModels\CanteenDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -4,12 +4,14 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CanteenContracts.View
|
||||
{
|
||||
public class ProductViewModel : IProductModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название продукта")]
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
|
||||
@ -21,7 +23,12 @@ namespace CanteenContracts.View
|
||||
|
||||
public Dictionary<int, ICookModel> ProductCooks { get; set; } = new();
|
||||
|
||||
public int Id { get; set; }
|
||||
public ProductViewModel() { }
|
||||
[JsonConstructor]
|
||||
public ProductViewModel(Dictionary<int, CookViewModel> ProductCooks)
|
||||
{
|
||||
this.ProductCooks = ProductCooks.ToDictionary(x => x.Key, x => x.Value as ICookModel);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace CanteenDatabaseImplement.Implements
|
||||
{
|
||||
public DishViewModel? GetElement(DishSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue && string.IsNullOrEmpty(model.DishName))
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace CanteenDatabaseImplement.Implements
|
||||
{
|
||||
public ManagerViewModel? GetElement(ManagerSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password) && string.IsNullOrEmpty(model.PhoneNumber) && !model.Id.HasValue)
|
||||
if (string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ namespace CanteenDatabaseImplement.Implements
|
||||
|
||||
public ProductViewModel? GetElement(ProductSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue && string.IsNullOrEmpty(model.ProductName))
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -46,7 +46,7 @@ namespace CanteenDatabaseImplement.Implements
|
||||
|
||||
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ProductName))
|
||||
if (!model.ManagerId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
@ -56,7 +56,7 @@ namespace CanteenDatabaseImplement.Implements
|
||||
return context.Products
|
||||
.Include(x => x.Cooks)
|
||||
.ThenInclude(x => x.Cook)
|
||||
.Where(x => (model.Id.HasValue && x.Id == model.Id) || (model.ManagerId.HasValue && model.ManagerId == x.ManagerId))
|
||||
.Where(x => ((model.Id.HasValue && x.Id == model.Id) || (model.ManagerId.HasValue && model.ManagerId == x.ManagerId)))
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
@ -112,8 +112,9 @@ namespace CanteenDatabaseImplement.Implements
|
||||
}
|
||||
|
||||
product.Update(model);
|
||||
|
||||
context.SaveChanges();
|
||||
if (model.ProductCooks != null)
|
||||
product.UpdateProductCooks(context, model);
|
||||
context.Database.CommitTransaction();
|
||||
|
||||
return product.GetViewModel;
|
||||
|
@ -8,84 +8,6 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace CanteenDatabaseImplement.Models
|
||||
{
|
||||
//public class Product : IProductModel
|
||||
//{
|
||||
// public int Id { get; private set; }
|
||||
// [Required]
|
||||
// public string ProductName { get; private set; } = string.Empty;
|
||||
// [Required]
|
||||
// public double Cost { get; private set; }
|
||||
// [Required]
|
||||
// public int ManagerId { get; private set; }
|
||||
// private Dictionary<int, ICookModel>? _productCooks = null;
|
||||
// [NotMapped]
|
||||
// public Dictionary<int, ICookModel> ProductCooks
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if (_productCooks == null)
|
||||
// {
|
||||
// _productCooks = Cooks.ToDictionary(record => record.CookId, record => record.Cook as ICookModel);
|
||||
// }
|
||||
// return _productCooks;
|
||||
// }
|
||||
// }
|
||||
// [ForeignKey("ProductId")]
|
||||
// public virtual List<ProductCook> Cooks { get; set; } = new();
|
||||
// [ForeignKey("ProductId")]
|
||||
// public virtual List<DishProduct> Dishes { get; set; } = new();
|
||||
// public static Product? Create(CanteenDatabase context, ProductBindingModel model)
|
||||
// {
|
||||
// return new Product()
|
||||
// {
|
||||
// Id = model.Id,
|
||||
// ProductName = model.ProductName,
|
||||
// Cost = model.Cost,
|
||||
// Cooks = model.ProductCooks.Select(x => new ProductCook
|
||||
// {
|
||||
// Cook = context.Cooks.First(y => y.Id == x.Key)
|
||||
// }).ToList()
|
||||
// };
|
||||
// }
|
||||
|
||||
// public void Update(ProductBindingModel model)
|
||||
// {
|
||||
// ProductName = model.ProductName;
|
||||
// Cost = model.Cost;
|
||||
// }
|
||||
|
||||
// public ProductViewModel GetViewModel => new()
|
||||
// {
|
||||
// Id = Id,
|
||||
// ProductName = ProductName,
|
||||
// Cost = Cost,
|
||||
// ProductCooks = ProductCooks,
|
||||
// ManagerId = ManagerId
|
||||
// };
|
||||
|
||||
// public void UpdateCooks(CanteenDatabase context, ProductBindingModel model)
|
||||
// {
|
||||
// var productCooks = context.ProductCooks.Where(record => record.ProductId == model.Id).ToList();
|
||||
// if (productCooks != null && productCooks.Count > 0)
|
||||
// {
|
||||
// context.ProductCooks.RemoveRange(productCooks.Where(record => !model.ProductCooks.ContainsKey(record.CookId)));
|
||||
// context.SaveChanges();
|
||||
// }
|
||||
|
||||
// var product = context.Products.First(x => x.Id == Id);
|
||||
// foreach (var pc in model.ProductCooks)
|
||||
// {
|
||||
// context.ProductCooks.Add(new ProductCook
|
||||
// {
|
||||
// Product = product,
|
||||
// Cook = context.Cooks.First(x => x.Id == pc.Key),
|
||||
// });
|
||||
// context.SaveChanges();
|
||||
// }
|
||||
|
||||
// _productCooks = null;
|
||||
// }
|
||||
//}
|
||||
public class Product : IProductModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
@ -133,7 +55,7 @@ namespace CanteenDatabaseImplement.Models
|
||||
ManagerId = model.ManagerId,
|
||||
Cooks = model.ProductCooks.Select(x => new ProductCook
|
||||
{
|
||||
Cook = context.Cooks.First(y => y.Id == x.Key),
|
||||
Cook = context.Cooks.First(y => y.Id == x.Key)
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
@ -157,7 +79,7 @@ namespace CanteenDatabaseImplement.Models
|
||||
public void UpdateProductCooks(CanteenDatabase context, ProductBindingModel model)
|
||||
{
|
||||
var productCookers = context.ProductCook.Where(rec => rec.ProductId == model.Id).ToList();
|
||||
if (productCookers != null && (productCookers.Count() > 0))
|
||||
if (productCookers != null)
|
||||
{
|
||||
context.ProductCook.RemoveRange(productCookers.Where(rec => !model.ProductCooks.ContainsKey(rec.CookId)));
|
||||
context.SaveChanges();
|
||||
|
@ -7,7 +7,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<Optimize>True</Optimize>
|
||||
<Optimize>False</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<Optimize>False</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,7 +1,12 @@
|
||||
using CanteenContracts.BindingModels;
|
||||
using CanteenContracts.SearchModel;
|
||||
using CanteenContracts.View;
|
||||
using CanteenDatabaseImplement.Models;
|
||||
using CanteenDataModels.Models;
|
||||
using CanteenManagerApp.Models;
|
||||
using FluentNHibernate.Conventions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
|
||||
|
||||
@ -15,7 +20,7 @@ namespace CanteenManagerApp.Controllers
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Index()
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
@ -25,87 +30,12 @@ namespace CanteenManagerApp.Controllers
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Cooks()
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Cooks = APIClient.GetRequest<List<CookViewModel>>($"api/main/getcooklist?managerId={APIClient.Manager.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Products()
|
||||
{
|
||||
ViewBag.Products = new List<ProductViewModel>();
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Dishes()
|
||||
{
|
||||
ViewBag.Dishes = new List<DishViewModel>();
|
||||
return View();
|
||||
}
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult CreateCook()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateCook(string FIO, string position)
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
throw new Exception("Доступ возможен только авторизованным пользователям");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(FIO))
|
||||
{
|
||||
throw new Exception("ФИО не должно быть пустым");
|
||||
}
|
||||
|
||||
APIClient.PostRequest("api/main/createcook", new CookBindingModel
|
||||
{
|
||||
ManagerId = APIClient.Manager.Id,
|
||||
FIO = FIO,
|
||||
Position = position
|
||||
});
|
||||
|
||||
Response.Redirect("Cooks");
|
||||
}
|
||||
[HttpPost]
|
||||
public IActionResult DeleteCook(int CookId)
|
||||
{
|
||||
APIClient.PostRequest("api/main/deletecook", new CookBindingModel { Id = CookId }); ;
|
||||
return Redirect("~/Home/Cooks");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateProduct()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateDish()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Enter()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Enter(string login, string password)
|
||||
{
|
||||
@ -155,5 +85,284 @@ namespace CanteenManagerApp.Controllers
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Cooks()
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Cooks = APIClient.GetRequest<List<CookViewModel>>($"api/main/getcooklist? ={APIClient.Manager.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateCook()
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateCook(string FIO, string position)
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
throw new Exception("Доступ возможен только авторизованным пользователям");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(FIO))
|
||||
{
|
||||
throw new Exception("ФИО не должно быть пустым");
|
||||
}
|
||||
|
||||
APIClient.PostRequest("api/main/createcook", new CookBindingModel
|
||||
{
|
||||
ManagerId = APIClient.Manager.Id,
|
||||
FIO = FIO,
|
||||
Position = position
|
||||
});
|
||||
|
||||
Response.Redirect("Cooks");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult DeleteCook(int CookId)
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
APIClient.PostRequest("api/main/deletecook", new CookBindingModel { Id = CookId }); ;
|
||||
return Redirect("~/Home/Cooks");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult UpdateCook()
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateCook(string FIO, string postition)
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
throw new Exception("Доступ возможен только авторизованным пользователям");
|
||||
}
|
||||
APIClient.PostRequest("api/main/updatecook", new CookBindingModel
|
||||
{
|
||||
Id = APIClient.Manager.Id,
|
||||
FIO = FIO,
|
||||
Position = postition
|
||||
});
|
||||
Response.Redirect("Cooks");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Products()
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Products = APIClient.GetRequest<List<ProductViewModel>>($"api/main/getproductlist?managerId={APIClient.Manager.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateProduct()
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Cooks = APIClient.GetRequest<List<CookViewModel>>($"api/main/getcooklist?managerId={APIClient.Manager.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateProduct(string name, double price)
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
throw new Exception("Доступ возможен только авторизованным пользователям");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception("Наименование продукта не должно быть пустым");
|
||||
}
|
||||
APIClient.PostRequest("api/main/createproduct", new ProductBindingModel
|
||||
{
|
||||
ManagerId = APIClient.Manager.Id,
|
||||
ProductName = name,
|
||||
Price = price
|
||||
});
|
||||
|
||||
Response.Redirect("Products");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult AddCooksToProduct()
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Products = APIClient.GetRequest<List<ProductViewModel>>($"api/main/getproductlist?managerId={APIClient.Manager.Id}");
|
||||
ViewBag.Cooks = APIClient.GetRequest<List<CookViewModel>>($"api/main/getcooklist?managerId={APIClient.Manager.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddCooksToProduct(int selectedProduct, int selectedCook)
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
throw new Exception("Доступ возможен только авторизованным пользователям");
|
||||
}
|
||||
|
||||
if (selectedProduct <= 0)
|
||||
{
|
||||
throw new Exception("Должен быть выбран продукт");
|
||||
}
|
||||
if (selectedCook <= 0)
|
||||
{
|
||||
throw new Exception("Должен быть выбран повар");
|
||||
}
|
||||
APIClient.PostRequest("api/main/addcookstoproduct", Tuple.Create
|
||||
(
|
||||
new ProductSearchModel { Id = selectedProduct },
|
||||
new CookViewModel { Id = selectedCook }
|
||||
));
|
||||
|
||||
Response.Redirect("Products");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult DeleteProduct(int productId)
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
APIClient.PostRequest("api/main/deleteproduct", new ProductBindingModel { Id = productId });
|
||||
return Redirect("~/Home/Products");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult UpdateProduct()
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateProduct(string productName, double price)
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
throw new Exception("Доступ возможен только авторизованным пользователям");
|
||||
}
|
||||
APIClient.PostRequest("api/main/updateproduct", new ProductBindingModel
|
||||
{
|
||||
Id = APIClient.Manager.Id,
|
||||
ProductName = productName,
|
||||
Price = price
|
||||
});
|
||||
Response.Redirect("Products");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Dishes()
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Dishes = APIClient.GetRequest<List<DishViewModel>>($"api/main/getdishlist?managerId={APIClient.Manager.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateDish()
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateDish(string dishName, double price)
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
throw new Exception("Доступ возможен только авторизованным пользователям");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(dishName))
|
||||
{
|
||||
throw new Exception("Наименование блюда не должно быть пустым");
|
||||
}
|
||||
|
||||
APIClient.PostRequest("api/main/createdish", new DishBindingModel
|
||||
{
|
||||
ManagerId = APIClient.Manager.Id,
|
||||
DishName = dishName,
|
||||
Price = price
|
||||
});
|
||||
|
||||
Response.Redirect("Dishes");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult DeleteDish(int dishId)
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
APIClient.PostRequest("api/main/deletedish", new DishBindingModel { Id = dishId });
|
||||
return Redirect("~/Home/Dishes");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult UpdateDish()
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateDish(string dishName, double price)
|
||||
{
|
||||
if (APIClient.Manager == null)
|
||||
{
|
||||
throw new Exception("Доступ возможен только авторизованным пользователям");
|
||||
}
|
||||
APIClient.PostRequest("api/main/updatedish", new DishBindingModel
|
||||
{
|
||||
Id = APIClient.Manager.Id,
|
||||
DishName = dishName,
|
||||
Price = price
|
||||
});
|
||||
Response.Redirect("Dishes");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
@using CanteenContracts.View;
|
||||
@{
|
||||
ViewData["Title"] = "AddCooksToProduct";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Привязка повара к продукту</h2>
|
||||
</div>
|
||||
<style>
|
||||
.row {
|
||||
margin-top: 10px;
|
||||
}
|
||||
</style>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Продукты:</div>
|
||||
<div class="col-8">
|
||||
<select name="selectedProduct">
|
||||
@foreach (var product in ViewBag.Products as List<ProductViewModel>)
|
||||
{
|
||||
<option value="@product.Id">@product.ProductName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Повар:</div>
|
||||
<div class="col-8">
|
||||
<select name="selectedCook">
|
||||
@foreach (var cook in ViewBag.Cooks as List<CookViewModel>)
|
||||
{
|
||||
<option value="@cook.Id">@cook.FIO</option>
|
||||
}
|
||||
</select>
|
||||
</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>
|
@ -1,4 +1,4 @@
|
||||
|
||||
@using CanteenContracts.View;
|
||||
@{
|
||||
ViewData["Title"] = "Product";
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
<h2 class="display-4">Добавление продукта</h2>
|
||||
</div>
|
||||
<style>
|
||||
.row{
|
||||
.row {
|
||||
margin-top: 10px;
|
||||
}
|
||||
</style>
|
||||
@ -14,14 +14,24 @@
|
||||
<div class="row">
|
||||
<div class="col-4">Название продукта:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" name="FIO" id="FIO" />
|
||||
@* <select id="bouquet" name="bouquet" class="form-control" asp-items="@(new SelectList(@ViewBag.Bouquets, "Id", "BouquetName"))"></select>*@
|
||||
<input type="text" name="name" id="name" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Цена:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" name="position" id="position" />
|
||||
<input type="text" name="price" id="price" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Цена:</div>
|
||||
<div class="col-8">
|
||||
<select name="selectedCooks" multiple>
|
||||
@foreach (var cook in ViewBag.Cooks as List<CookViewModel>)
|
||||
{
|
||||
<option value="@cook.Id">@cook.FIO</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
@ -1,32 +1,59 @@
|
||||
@{
|
||||
ViewData["Title"] = "Dishes";
|
||||
ViewData["Title"] = "Products";
|
||||
}
|
||||
<body>
|
||||
<div class="container">
|
||||
<h2>Список блюд</h2>
|
||||
<button type="button" class="btn btn-info" onclick="location.href='@Url.Action("CreateDish", "Home")'">Добавить блюдо</button>
|
||||
<button type="button" class="btn btn-danger" onclick="location.href='@Url.Action("CreateDish", "Home")'">Удалить блюдо</button>
|
||||
<button type="button" class="btn btn-warning" onclick="location.href='@Url.Action("CreateDish", "Home")'">Обновить блюдо</button>
|
||||
<h2>Список список продуктов</h2>
|
||||
<a type="button" class="btn btn-success" href="/Home/CreateCook">Добавить продукт</a>
|
||||
<button type="submit" class="btn btn-danger" form="selectCookForm">Удалить продукт</button>
|
||||
<a type="button" class="btn btn-warning" href="/Home/UpdateCook">Обновить продукт</a>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Номер</th>
|
||||
<th>Название блюда</th>
|
||||
<th>Название</th>
|
||||
<th>Цена</th>
|
||||
<th>Менеджер</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var cook in ViewBag.Dishes)
|
||||
@foreach (var cook in ViewBag.Cooks)
|
||||
{
|
||||
<tr>
|
||||
<tr onclick="selectCook(this)">
|
||||
<td>@cook.Id</td>
|
||||
<td>@cook.DishName</td>
|
||||
<td>@cook.Name</td>
|
||||
<td>@cook.Price</td>
|
||||
<td>@cook.ManagerId</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
<form id="selectCookForm" method="post" action="/Home/DeleteCook">
|
||||
<input type="hidden" id="ProductId" name="ProductId" value="" />
|
||||
</form>
|
||||
<style>
|
||||
.selected-row {
|
||||
background-color: lightgray;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function selectCook(row) {
|
||||
var ProductId = document.getElementById("ProductId");
|
||||
var previousValue = ProductId.value;
|
||||
var currentValue = row.cells[0].innerText;
|
||||
|
||||
if (previousValue === currentValue) {
|
||||
ProductId.value = "";
|
||||
row.classList.remove("selected-row");
|
||||
} else {
|
||||
ProductId.value = currentValue;
|
||||
|
||||
var rows = document.getElementsByTagName("tr");
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
rows[i].classList.remove("selected-row");
|
||||
}
|
||||
|
||||
row.classList.add("selected-row");
|
||||
}
|
||||
}
|
||||
</script>
|
@ -7,15 +7,15 @@
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Логин:</div>
|
||||
<div class="col-8"><input type="text" name="login" value="@Model.Login" /></div>
|
||||
<div class="col-8"><input type="text" name="login" value="@ViewBag.Data.Login" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Пароль:</div>
|
||||
<div class="col-8"><input type="password" name="password" value="@Model.Password" /></div>
|
||||
<div class="col-8"><input type="password" name="password" value="@ViewBag.Data.Password" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">ФИО:</div>
|
||||
<div class="col-8"><input type="text" name="fio" value="@Model.ClientFIO" /></div>
|
||||
<div class="col-8"><input type="text" name="fio" value="@ViewBag.Data.ClientFIO" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
|
@ -1,32 +1,61 @@
|
||||
@{
|
||||
@using CanteenContracts.View;
|
||||
@{
|
||||
ViewData["Title"] = "Products";
|
||||
}
|
||||
<body>
|
||||
<div class="container">
|
||||
<h2>Список продуктов</h2>
|
||||
<button type="button" class="btn btn-info" onclick="location.href='@Url.Action("CreateProduct", "Home")'">Добавить продукт</button>
|
||||
<button type="button" class="btn btn-danger" onclick="location.href='@Url.Action("CreateProduct", "Home")'">Удалить продукт</button>
|
||||
<button type="button" class="btn btn-warning" onclick="location.href='@Url.Action("CreateProduct", "Home")'">Обновить продукт</button>
|
||||
<a type="button" class="btn btn-success" href="/Home/CreateProduct">Добавить продукт</a>
|
||||
<button type="submit" class="btn btn-danger" form="selectProductForm">Удалить продукт</button>
|
||||
<a type="button" class="btn btn-warning" href="/Home/UpdateProduct">Обновить продукт</a>
|
||||
<a type="button" class="btn btn-warning" href="/Home/AddCooksToProduct">Привязать повара</a>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Номер</th>
|
||||
<th>Название продукта</th>
|
||||
<th>Название</th>
|
||||
<th>Цена</th>
|
||||
<th>Менеджер</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var cook in ViewBag.Products)
|
||||
@foreach (var product in ViewBag.Products)
|
||||
{
|
||||
<tr>
|
||||
<td>@cook.Id</td>
|
||||
<td>@cook.ProductName</td>
|
||||
<td>@cook.Price</td>
|
||||
<td>@cook.ManagerId</td>
|
||||
<tr onclick="selectProduct(this)">
|
||||
<td>@product.Id</td>
|
||||
<td>@product.ProductName</td>
|
||||
<td>@product.Price</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
<form id="selectProductForm" method="post" action="/Home/DeleteProduct">
|
||||
<input type="hidden" id="ProductId" name="ProductId" value="" />
|
||||
</form>
|
||||
<style>
|
||||
.selected-row {
|
||||
background-color: lightgray;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function selectProduct(row) {
|
||||
var productIdInput = document.getElementById("ProductId");
|
||||
var previousValue = productIdInput.value;
|
||||
var currentValue = row.cells[0].innerText;
|
||||
|
||||
if (previousValue === currentValue) {
|
||||
productIdInput.value = "";
|
||||
row.classList.remove("selected-row");
|
||||
} else {
|
||||
productIdInput.value = currentValue;
|
||||
|
||||
var rows = document.getElementsByTagName("tr");
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
rows[i].classList.remove("selected-row");
|
||||
}
|
||||
|
||||
row.classList.add("selected-row");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -6,10 +6,10 @@
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (Model.ShowRequestId)
|
||||
@if (ViewBag.Data.ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||
<strong>Request ID:</strong> <code>@ViewBag.Data.RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<Optimize>True</Optimize>
|
||||
<Optimize>False</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<Optimize>False</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -2,6 +2,7 @@ using CanteenContracts.BindingModels;
|
||||
using CanteenContracts.BusinessLogicsContracts;
|
||||
using CanteenContracts.SearchModel;
|
||||
using CanteenContracts.View;
|
||||
using CanteenDataModels.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CanteenRestApi.Controllers
|
||||
@ -39,6 +40,19 @@ namespace CanteenRestApi.Controllers
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<ProductViewModel>? GetProductList(int managerId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _product.ReadList(new ProductSearchModel { ManagerId = managerId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during loading list of bouquets");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<TablewareViewModel>? GetTablewareList()
|
||||
{
|
||||
try
|
||||
@ -77,6 +91,7 @@ namespace CanteenRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteCook(CookBindingModel model)
|
||||
{
|
||||
@ -90,6 +105,7 @@ namespace CanteenRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateDish(DishBindingModel model)
|
||||
{
|
||||
@ -116,5 +132,19 @@ namespace CanteenRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddCooksToProduct(Tuple<ProductSearchModel, CookViewModel> model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_product.AddCooksToProduct(model.Item1, model.Item2);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during loading list of bouquets");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<Optimize>True</Optimize>
|
||||
<Optimize>False</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<Optimize>False</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -6,10 +6,10 @@
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (Model.ShowRequestId)
|
||||
@if (ViewBag.Data.ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||
<strong>Request ID:</strong> <code>@ViewBag.Data.RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user