public ActionResult Edit(int?id) { RoomsEditVM item; if (id == null) { item = new RoomsEditVM(); } else { Room room = this._roomRepository.GetOne(id.Value); item = new RoomsEditVM { Id = id.Value, Capacity = room.Capacity, Type = room.Type, IsFree = room.IsFree, PriceForAdult = room.PriceForAdult, PriceForChild = room.PriceForChild }; } HotelReservationsManagerDb context = new HotelReservationsManagerDb(); context.Dispose(); return(View(item)); }
public IActionResult Update(RoomsEditVM room) { if (!ModelState.IsValid) { return(RedirectToAction(nameof(RoomsController.Edit))); } context.UpdateRoom(room); return(RedirectToAction(nameof(RoomsController.Index))); }
public ActionResult Add() { RoomsEditVM item; item = new RoomsEditVM(); HotelReservationsManagerDb context = new HotelReservationsManagerDb(); context.Dispose(); return(View(item)); }
public ActionResult Add(RoomsEditVM model) { Room room = new Room { Id = model.Id, Capacity = model.Capacity, Type = model.Type, IsFree = model.IsFree, PriceForAdult = model.PriceForAdult, PriceForChild = model.PriceForChild }; this._roomRepository.Add(room); return(RedirectToAction("RoomIndex")); }
public void UpdateRoom(RoomsEditVM room) { Room roomToUpdate = this.Room.Single(i => i.Id == room.Id); if (room.Name != null) { roomToUpdate.Name = room.Name; } roomToUpdate.Number = room.Number; if (room.Description != null) { roomToUpdate.Description = room.Description; } if (room.Price != null) { roomToUpdate.Price = room.Price; } if (room.Size != null) { roomToUpdate.Size = room.Size; } SaveChanges(); }