public Restaunrant Add(Restaunrant restaunrant)
 {
     restaunrant.Id = restaunrants.Max(r => r.Id) + 1;
     restaunrants.Add(restaunrant);
     restaunrant.Id = restaunrants.Max(r => r.Id) + 1;
     return(restaunrant);
 }
        public async Task <ActionResult <Restaunrant> > PostRestaunrant(Restaunrant restaunrant)
        {
            _context.Restaunrants.Add(restaunrant);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRestaunrant", new { id = restaunrant.Id }, restaunrant));
        }
        public async Task <IActionResult> PutRestaunrant(int id, Restaunrant restaunrant)
        {
            if (id != restaunrant.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public Restaunrant Update(Restaunrant restaunrant)
        {
            var entity = _db.Restaunrants.Attach(restaunrant);

            entity.State = EntityState.Modified;
            return(restaunrant);
        }
示例#5
0
        public IActionResult OnGet(int restaurantId)
        {
            Restaunrant = _restaurantData.GteById(restaurantId);
            if (Restaunrant == null)
            {
                return(RedirectToPage("./NotFound"));
            }

            return(Page());
        }
        public Restaunrant Update(Restaunrant restaunrantUpdate)
        {
            var restaurant = restaunrants
                             .SingleOrDefault(r => r.Id == restaunrantUpdate.Id);

            if (restaurant != null)
            {
                restaurant.Name     = restaunrantUpdate.Name;
                restaurant.Cuisine  = restaunrantUpdate.Cuisine;
                restaurant.Location = restaunrantUpdate.Location;
            }
            return(restaurant);
        }
示例#7
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Restaunrant = await _context.Restaunrants.FirstOrDefaultAsync(m => m.Id == id);

            if (Restaunrant == null)
            {
                return(NotFound());
            }
            return(Page());
        }
示例#8
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Restaunrant = await _context.Restaunrants.FindAsync(id);

            if (Restaunrant != null)
            {
                _context.Restaunrants.Remove(Restaunrant);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
示例#9
0
        public IActionResult OnGet(int?restaurantId)
        {
            Cuisines = _htmlHelper.GetEnumSelectList <CuisineType>();
            if (restaurantId.HasValue)
            {
                Restaunrant = _restaurantData.GteById(restaurantId.Value);
            }
            else
            {
                Restaunrant = new Restaunrant();
            }

            if (Restaunrant == null)
            {
                return(RedirectToPage("./NotFound"));
            }

            return(Page());
        }
示例#10
0
        public IActionResult OnPost(Restaunrant restaunrant)
        {
            if (!ModelState.IsValid)
            {
                Cuisines = _htmlHelper.GetEnumSelectList <CuisineType>();
                return(Page());
            }

            if (restaunrant.Id > 0)
            {
                Restaunrant = _restaurantData.Update(restaunrant);
            }
            else
            {
                Restaunrant = _restaurantData.Add(restaunrant);
            }

            _restaurantData.Commit();
            TempData["Message"] = "Restaurant saved";
            return(RedirectToPage("./Detail", new { restaurantId = Restaunrant.Id }));
        }
 public Restaunrant Add(Restaunrant restaunrant)
 {
     _db.Add(restaunrant);
     return(restaunrant);
 }