Esempio n. 1
0
        public async Task <IActionResult> PutVarorModel(int id, VarorModel varorModel)
        {
            if (id != varorModel.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutRestaurant(int id, Restaurant restaurant)
        {
            if (id != restaurant.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IActionResult> PutRestaurants([FromRoute] int id, [FromBody] Restaurants restaurants)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != restaurants.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("Name,Location,Id,Cusine")] Restaurant restaurant)
        {
            if (ModelState.IsValid)
            {
                _context.Add(restaurant);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(restaurant));
        }
Esempio n. 5
0
        public async Task <Restaurant> AddAsync(Restaurant restaurant, CancellationToken cancellationToken = default)
        {
            var addResult = await _dbContext.AddAsync(restaurant, cancellationToken);

            int effectedRows = await _dbContext.SaveChangesAsync();

            if (effectedRows == 0)
            {
                return(null);
            }

            return(addResult.Entity);
        }
Esempio n. 6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            Cuisines = _htmlHelper.GetEnumSelectList <CuisineType>();

            _context.Attach(Restaurant).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RestaurantExists(Restaurant.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                Cuisines = _htmlHelper.GetEnumSelectList <CuisineType>();
                return(Page());
            }

            _context.Restaurants.Add(Restaurant);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }