public ActionResult Edit(int id, HotelEdit model) { if (!ModelState.IsValid) { PopulateDestinations(model.DestinationId); return(View(model)); } if (model.HotelId != id) { PopulateDestinations(model.DestinationId); ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateHotelService(); if (service.UpdateHotel(model)) { TempData["SaveResult"] = "Your Hotel was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your Hotel could not be updated."); return(View()); }
private async Task <bool> SetStarStateAsync(int noteId, bool newState) { if (RequestContext.Principal.IsInRole("Admin")) { // Do admin stuff } // Create the service var userId = Guid.Parse(User.Identity.GetUserId()); var service = new HotelService(userId); // Get the note var detail = await service.GetHotelByIdAsync(noteId); // Create the NoteEdit model with new star state var updatedHotel = new HotelEdit { Id = detail.Id, Name = detail.Name, IsFavorite = newState, BuildingNumber = detail.BuildingNumber, StreetAddress = detail.StreetAddress, City = detail.City, State = detail.State, ZipCode = detail.ZipCode, }; // Return a value indicating whether the update succeeded return(await service.UpdateHotelAsync(updatedHotel)); }
public async Task <ActionResult> Edit(int hotelId, HotelEdit model) { try { if (!ModelState.IsValid) { return(View(model)); } if (model.Id != hotelId) { ModelState.AddModelError("", "Id mismatch."); return(View(model)); } var service = CreateHotelService(); if (!await service.UpdateHotelAsync(model)) { ModelState.AddModelError("", "Could not update hotel."); return(View(model)); } return(RedirectToAction("Index")); } catch { return(View(model)); } }
public bool UpdateHotel(HotelEdit hotel) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Hotels.Single(e => e.HotelId == hotel.HotelId && e.OwnerId == _UserId); entity.HotelId = hotel.HotelId; entity.HotelName = hotel.Name; entity.Location = hotel.Location; return(ctx.SaveChanges() == 1); } }
public IHttpActionResult Put(HotelEdit Hotel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateHotelService(); if (!service.UpdateHotel(Hotel)) { return(InternalServerError()); } return(Ok("The hotel has been updated.")); }
// GET: Hotel/Edit/{id} public ActionResult Edit(int id) { var service = CreateHotelService(); var detail = service.GetHotelById(id); var model = new HotelEdit { HotelId = detail.HotelId, Name = detail.Name, Address = detail.Address, Comment = detail.Comment }; PopulateDestinations(detail.DestinationId); return(View(model)); }
public bool UpdateHotel(HotelEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Hotels .SingleOrDefault(e => e.HotelId == model.HotelId && e.OwnerId == _userId); entity.Name = model.Name; entity.Comment = model.Comment; entity.Address = model.Address; entity.ModifiedUtc = DateTimeOffset.Now; return(ctx.SaveChanges() == 1); } }
// GET: Hotel/Edit/5 //[Authorize(Roles = "Admin,Manager")] public async Task <ActionResult> Edit(int hotelId) { var service = CreateHotelService(); var hotel = await service.GetHotelByIdAsync(hotelId); var model = new HotelEdit { Id = hotel.Id, Name = hotel.Name, BuildingNumber = hotel.BuildingNumber, StreetAddress = hotel.StreetAddress, City = hotel.City, State = hotel.State, ZipCode = hotel.ZipCode, }; return(View(model)); }
public async Task <bool> UpdateHotelAsync(HotelEdit model) { using (var db = new ApplicationDbContext()) { var hotel = await db.Hotels.FindAsync(model.Id); if (hotel is null) { return(false); } hotel.Name = model.Name; hotel.IsFavorite = model.IsFavorite; hotel.BuildingNumber = model.BuildingNumber; hotel.StreetAddress = model.StreetAddress; hotel.City = model.City; hotel.State = model.State; hotel.ZipCode = model.ZipCode; hotel.ModifiedAt = DateTimeOffset.UtcNow; return(await db.SaveChangesAsync() == 1); } }