редактирование доделать

This commit is contained in:
dasha 2023-04-08 14:19:28 +04:00
parent bd9ec0284a
commit 7103e43d37
5 changed files with 24 additions and 8 deletions

View File

@ -80,6 +80,7 @@ namespace SushiBarDatabaseImplement.Models
{ // удалили те, которых нет в модели
context.ShopSushi.RemoveRange(shopSushi.Where(rec => !model.ListSushi.ContainsKey(rec.SushiId)));
context.SaveChanges();
shopSushi = context.ShopSushi.Where(rec => rec.ShopId == model.Id).ToList();
// обновили количество у существующих записей
foreach (var updateSushi in shopSushi)
{

View File

@ -9,7 +9,8 @@ namespace SushiBarDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D8KMQQU\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
// D8KMQQU comp JC256C6 nout
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-JC256C6\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -37,14 +37,14 @@ namespace SushiBarRestApi.Controllers
}
[HttpGet]
public Tuple<ShopViewModel, Dictionary<int, (ISushiModel, int)>>? GetShop(int shopId)
public Tuple<ShopViewModel, List<Tuple<string, int>>>? GetShop(int shopId)
{
try
{
var elem = _shop.ReadElement(new ShopSearchModel { Id = shopId });
if (elem == null)
return null;
return Tuple.Create(elem, elem.ListSushi);
return Tuple.Create(elem, elem.ListSushi.Select(x => Tuple.Create(x.Value.Item1.SushiName, x.Value.Item2)).ToList());
}
catch (Exception ex)
{

View File

@ -155,14 +155,28 @@ namespace SushiBarShopApp.Controllers
}
[HttpGet]
public Tuple<ShopViewModel, Dictionary<int, (ISushiModel, int)>>? GetShop(int shopId)
public Tuple<ShopViewModel, string>? GetShop(int shopId)
{
if (APIClient.Access == false)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
var result = APIClient.GetRequest<Tuple<ShopViewModel, Dictionary<int, (ISushiModel, int)>>>($"api/shop/getshop?shopid={shopId}");
return result;
var result = APIClient.GetRequest<Tuple<ShopViewModel, List<Tuple<string, int>>>>($"api/shop/getshop?shopid={shopId}");
if (result == null)
{
return default;
}
string table = "";
for (int i = 0; i < result.Item2.Count; i++)
{
var sushi = result.Item2[i].Item1;
var count = result.Item2[i].Item2;
table += "<tr>";
table += $"<td>{sushi}</td>";
table += $"<td>{count}</td>";
table += "</tr>";
}
return Tuple.Create(result.Item1, table);
}
public IActionResult AddSushi()

View File

@ -49,7 +49,7 @@
</th>
</tr>
</thead>
<tbody id="table">
<tbody id="table-elements">
</tbody>
</table>
@ -69,7 +69,7 @@
$('#address').val(result.item1.address);
$('#date').val(result.item1.dateOpening);
$('#count').val(result.item1.maxCountSushi);
$('#table').html(result.item2);
$('#table-elements').html(result.item2);
}
});
};