コード例 #1
0
        public async Task <ActionResult <RestaurantUnit> > PostRestaurantUnit(RestaurantUnit restaurantUnit)
        {
            _context.restaurantUnits.Add(restaurantUnit);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRestaurantUnit", new { id = restaurantUnit.UnitId }, restaurantUnit));
        }
コード例 #2
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());
        }
コード例 #3
0
        public async Task <IActionResult> PutRestaurantUnit(int id, RestaurantUnit restaurantUnit)
        {
            if (id != restaurantUnit.UnitId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #4
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));
        }