source: resTools_backend/backend/Services/MenuService.cs@ cc4db18

Last change on this file since cc4db18 was cc4db18, checked in by Danilo <danilo.najkov@…>, 2 years ago

reservation module changes + contact module + menu module

  • Property mode set to 100644
File size: 1.3 KB
Line 
1using backend.Data;
2using backend.DTOs;
3using backend.Entities;
4using Microsoft.EntityFrameworkCore;
5
6namespace backend.Services
7{
8 public interface IMenuService
9 {
10 public Task AddMenu(CreateMenuItemRequest menu);
11 public Task RemoveMenu(int id);
12 }
13 public class MenuService : IMenuService
14 {
15 private readonly DataContext _context = null;
16 public MenuService(DataContext context)
17 {
18 _context = context;
19 }
20 public async Task AddMenu(CreateMenuItemRequest menu)
21 {
22 var res = await _context.Restoraunts.FirstOrDefaultAsync();
23 if(res.Menu == null)
24 {
25 res.Menu = new List<MenuItem>();
26 }
27 res.Menu.Add(new MenuItem()
28 {
29 Title = menu.Title,
30 Description = menu.Description,
31 Price = menu.Price
32 });
33 _context.Restoraunts.Update(res);
34 await _context.SaveChangesAsync();
35 }
36
37 public async Task RemoveMenu(int id)
38 {
39 var res = await _context.Restoraunts.Include(x => x.Menu).FirstOrDefaultAsync();
40 res.Menu = res.Menu.Where(x => x.Id != id).ToList();
41 _context.Restoraunts.Update(res);
42 await _context.SaveChangesAsync();
43 }
44 }
45}
Note: See TracBrowser for help on using the repository browser.