Beispiel #1
0
        public async Task <ActionResult> Edit(int id, RestaurantEdit note)
        {
            if (!ModelState.IsValid)
            {
                return(View(note));
            }
            if (note.RestaurantId != id)
            {
                ModelState.AddModelError("", "ID Mismatch");
                ViewBag.MenuId = await GetMenuAsync();

                ViewBag.AreaId = await GetAreaAsync();

                return(View(note));
            }
            var service = CreateRestaurantService();

            if (await service.UpdateRestaurantAsync(note))
            {
                TempData["SaveResult"] = "Restaurant informations successfully updated.";
                return(RedirectToAction("Index"));
            }
            ViewBag.MenuId = await GetMenuAsync();

            ViewBag.AreaId = await GetAreaAsync();

            ModelState.AddModelError("", "Restaurant informations could not be updated.");
            return(View(note));
        }
Beispiel #2
0
        public async Task <ActionResult> Edit(int id)
        {
            var service = CreateRestaurantService();
            var detail  = await service.GetRestaurantByIdAsync(id);

            var model =
                new RestaurantEdit
            {
                RestaurantId = detail.RestaurantId,
                Name         = detail.Name,
                Phone        = detail.Phone,
                Address      = detail.Address,
                Email        = detail.Email,
                OpeningTime  = detail.OpeningTime,
                ClosingTime  = detail.ClosingTime,
                AreaId       = detail.AreaId,
                //Review=detail.Review,
                Latitude  = detail.Latitude,
                Longitude = detail.Longitude
            };

            ViewBag.SyncOrAsync = "Asynchronous";
            ViewBag.AreaId      = await GetAreaAsync();

            ViewBag.MenutId = await GetMenuAsync();

            return(View(model));
        }
        public async Task <bool> UpdateRestaurantAsync(RestaurantEdit category)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = await
                             ctx
                             .Restaurants
                             .Where(e => e.RestaurantId == category.RestaurantId)
                             .FirstOrDefaultAsync();

                entity.Name        = category.Name;
                entity.Phone       = category.Phone;
                entity.Email       = category.Email;
                entity.Address     = category.Address;
                entity.OpeningTime = category.OpeningTime;
                entity.ClosingTime = category.ClosingTime;
                entity.AreaId      = category.AreaId;
                //entity.Review = category.Review;
                entity.Latitude  = category.Latitude;
                entity.Longitude = category.Longitude;
                //entity.MenuId = category.MenuId;

                return(await ctx.SaveChangesAsync() == 1);
            }
        }
        public IHttpActionResult Put(RestaurantEdit restaurant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateRestaurantService();

            if (!service.UpdateRestaurant(restaurant))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
        public async Task <IActionResult> PostRestaurant([FromForm] RestaurantEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _db.Restaurants.Add(new Restaurant()
            {
                Name     = model.Name,
                Location = model.Location,
            });

            await _db.SaveChangesAsync();

            return(Ok());
        }
Beispiel #6
0
 public bool UpdateRestaurant(RestaurantEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var entity = ctx
                      .Restaurants
                      .Single(e => e.RestaurantId == model.RestaurantId && e.OwnerId == _userId);
         entity.RestaurantId  = model.RestaurantId;
         entity.Name          = model.Name;
         entity.Address       = model.Address;
         entity.Description   = model.Description;
         entity.ContactNumber = model.ContactNumber;
         entity.ContactEmail  = model.ContactEmail;
         entity.Rating        = model.Rating;
         return(ctx.SaveChanges() == 1);
     }
 }
        public async Task <IActionResult> UpdateRestaurant([FromForm] RestaurantEdit model, [FromRoute] int id)
        {
            var oldRestaurant = await _db.Restaurants.FindAsync(id);

            if (oldRestaurant == null)
            {
                return(NotFound());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (!string.IsNullOrEmpty(model.Name))
            {
                oldRestaurant.Name = model.Name;
            }
            if (!string.IsNullOrEmpty(model.Location))
            {
                oldRestaurant.Location = model.Location;
            }
            await _db.SaveChangesAsync();

            return(Ok());
        }