Last change
on this file since d76b7ee was d76b7ee, checked in by Danilo <danilo.najkov@…>, 2 years ago |
prototype final
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[057037b] | 1 | using backend.Data;
|
---|
| 2 | using backend.DTOs;
|
---|
| 3 | using backend.Entities;
|
---|
| 4 | using Microsoft.EntityFrameworkCore;
|
---|
| 5 |
|
---|
| 6 | namespace backend.Services
|
---|
| 7 | {
|
---|
| 8 | public interface IRestaurantService
|
---|
| 9 | {
|
---|
| 10 | public Task CreateRestaurant(string name, int userId);
|
---|
| 11 | public Task<RestaurantResponse> GetRestaurant();
|
---|
| 12 | }
|
---|
| 13 | public class RestaurantService : IRestaurantService
|
---|
| 14 | {
|
---|
| 15 | private readonly DataContext _context = null;
|
---|
| 16 |
|
---|
| 17 | public RestaurantService(DataContext context)
|
---|
| 18 | {
|
---|
| 19 | _context = context;
|
---|
| 20 | }
|
---|
| 21 | public async Task CreateRestaurant(string name, int userId)
|
---|
| 22 | {
|
---|
| 23 | User user = await _context.Users.FindAsync(userId);
|
---|
| 24 | Restaurant restaurant = new Restaurant() { Name = name, Owner = user};
|
---|
| 25 | await _context.Restoraunts.AddAsync(restaurant);
|
---|
| 26 | await _context.SaveChangesAsync();
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | public async Task<RestaurantResponse> GetRestaurant()
|
---|
| 30 | {
|
---|
| 31 | RestaurantResponse res = await _context.Restoraunts
|
---|
| 32 | .Select(x => new RestaurantResponse()
|
---|
| 33 | {
|
---|
| 34 | Id = x.Id,
|
---|
| 35 | Name = x.Name,
|
---|
| 36 | OwnerId = x.OwnerFk,
|
---|
| 37 | })
|
---|
| 38 | .FirstOrDefaultAsync();
|
---|
| 39 | return res;
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.