Ejemplo n.º 1
0
        public async Task <IActionResult> PutRestaurantUnit(int id, RUDTO restaurantUnit)
        {
            var location   = _context.locations.Where(l => l.id == restaurantUnit.LocationId).SingleOrDefault();
            var restaurant = _context.restaurants.Where(r => r.RestaurantId == restaurantUnit.RestaurantId).SingleOrDefault();
            var ru         = new RestaurantUnit
            {
                Tel         = restaurantUnit.Tel,
                EmployeeNo  = restaurantUnit.EmployeeNo,
                OpeningDate = restaurantUnit.OpeningDate,
                ClosingDate = restaurantUnit.ClosingDate,
                Capacity    = restaurantUnit.Capacity,
                Restaurant  = restaurant,
                Location    = location
            };

            _context.Entry(restaurantUnit).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RestaurantUnitExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <RestaurantUnit> > PostRestaurantUnit(RUDTO rUDTO)
        {
            var location   = _context.locations.Where(l => l.id == rUDTO.LocationId).SingleOrDefault();
            var restaurant = _context.restaurants.Where(r => r.RestaurantId == rUDTO.RestaurantId).SingleOrDefault();
            var ru         = new RestaurantUnit
            {
                Tel         = rUDTO.Tel,
                EmployeeNo  = rUDTO.EmployeeNo,
                OpeningDate = rUDTO.OpeningDate,
                ClosingDate = rUDTO.ClosingDate,
                Capacity    = rUDTO.Capacity,
                Restaurant  = restaurant,
                Location    = location
            };

            _context.restaurantUnits.Add(ru);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRestaurantUnit", new { id = ru.UnitId }, ru));
        }