// GET: HotelRoom/Edit/5 public ActionResult Edit(int?id) { if (Session["User"] == null) { TempData["NotLoggedIn"] = "Please login or register to continue!"; return(RedirectToAction("Index", "Home")); } if (!Session["Role"].Equals(UserRole.Staff)) { TempData["NotAuthorized"] = "You are not authorized to perform these actions!"; return(RedirectToAction("Index", "Home")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HotelRoomViewModel hotelRoom = HotelRoomRepo.Find(id); if (hotelRoom == null) { return(HttpNotFound()); } var sizes = new List <int> { 2, 3, 5 }; ViewBag.SelectList = new SelectList(sizes); return(View(hotelRoom)); }
public void StartNight_Gameroom() { IHotelTamagotchiContext c = new FakeHotelTamagotchiContext(); IHotelRoomRepository hR = new HotelRoomRepository(c); ITamagotchiRepository tR = new TamagotchiRepository(c); HotelRoomViewModel h = new HotelRoomViewModel() { Size = 5, Type = HotelRoomType.Gameroom, }; hR.Add(h); TamagotchiViewModel t = new TamagotchiViewModel() { Name = "Test", Alive = true, HotelRoom = h, HotelRoomId = h.Id, Boredom = 50 }; tR.Add(t); NightController nC = new NightController(tR, hR); nC.StartNight(); Assert.IsTrue(tR.Find(t.Id).Boredom == 0); Assert.IsTrue(tR.Find(t.Id).Pennies == 80); }
public void BookingController_CreateBooking() { IHotelTamagotchiContext c = new FakeHotelTamagotchiContext(); IHotelRoomRepository hr = new HotelRoomRepository(c); ITamagotchiRepository tr = new TamagotchiRepository(c); BookingController bc = new BookingController(hr, tr); var ccMock = new Mock <ControllerContext>(); ccMock.SetupGet(x => x.HttpContext.Session["User"]).Returns("testUser"); ccMock.SetupGet(x => x.HttpContext.Session["Role"]).Returns(UserRole.Customer); bc.ControllerContext = ccMock.Object; FormCollection fc = new FormCollection(); TamagotchiViewModel t = new TamagotchiViewModel() { Name = "Test", Alive = true }; tr.Add(t); HotelRoomViewModel h = new HotelRoomViewModel() { Size = 5, Type = HotelRoomType.Fightroom }; hr.Add(h); fc.Add("1", "true,false"); bc.Create(fc, h); Assert.AreEqual(t.ToModel().HotelRoomId, tr.Find(t.Id).HotelRoomId); tr.Remove(t); hr.Remove(h); }
public IActionResult InfoCreate(HotelRoomViewModel model) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { if (_dbContext.HotelRoom.Count(x => x.HotelRoomName == model.HotelRoomName && x.HotelUuid == model.HotelUuid) > 0) { response.SetFailed("该房型已存在"); return(Ok(response)); } var entity = new HotelRoom(); entity.HotelRoomUuid = Guid.NewGuid(); entity.HotelUuid = model.HotelUuid; entity.HotelRoomName = model.HotelRoomName; entity.Price = model.Price; entity.Introduction = model.Introduction; entity.Address = model.Address; entity.Picture = model.Picture; entity.IsDelete = 0; _dbContext.HotelRoom.Add(entity); int res = _dbContext.SaveChanges(); if (res > 0) { ToLog.AddLog("添加", "成功:添加:酒店房型信息列表数据", _dbContext); } response.SetSuccess("房型添加成功"); return(Ok(response)); } }
public void Hotelroom_properties() { //arrange HotelRoomViewModel h = new HotelRoomViewModel() { Size = 5, Type = HotelRoomType.Gameroom }; //assert Assert.AreEqual(5, h.Size); Assert.AreEqual(HotelRoomType.Gameroom, h.Type); }
public void Hotelroom_invalid_validation() { //arrange HotelRoomViewModel h = new HotelRoomViewModel() { Size = 4, Type = HotelRoomType.Gameroom }; //act var errors = h.Validate(null); //assert Assert.AreEqual(1, errors.Count()); }
public ActionResult DeleteConfirmed(int id) { if (Session["User"] == null) { TempData["NotLoggedIn"] = "Please login or register to continue!"; return(RedirectToAction("Index", "Home")); } if (!Session["Role"].Equals(UserRole.Staff)) { TempData["NotAuthorized"] = "You are not authorized to perform these actions!"; return(RedirectToAction("Index", "Home")); } HotelRoomViewModel hotelRoom = HotelRoomRepo.Find(id); HotelRoomRepo.Remove(hotelRoom); return(RedirectToAction("Index")); }
public ActionResult Create(FormCollection formCollection, HotelRoomViewModel hotelroom) { if (!Session["Role"].Equals(UserRole.Customer)) { TempData["NotAuthorized"] = "You are not authorized to perform these actions!"; return(RedirectToAction("Index", "Home")); } hotelroom = HotelRoomRepo.Find(hotelroom.Id); List <TamagotchiViewModel> addToHotel = new List <TamagotchiViewModel>(); int i = 0; foreach (var t in TamagotchiRepo.GetAllHomelessTamagotchi()) { if (t.HotelRoomId != null) { ModelState.AddModelError(string.Empty, "You cannot book a tamagotchi that already has a room"); TempData["ViewData"] = ViewData; return(RedirectToAction("Create")); } if (i > (int)hotelroom.Size) { string sizeError = "You may only book " + (int)hotelroom.Size + " tamagotchis"; ModelState.AddModelError(string.Empty, sizeError); TempData["ViewData"] = ViewData; return(RedirectToAction("Create")); } if (formCollection[t.Id + ""] != null && formCollection[t.Id + ""].Equals("true,false")) { addToHotel.Add(t); i++; } } if (addToHotel.Count == 0) { ModelState.AddModelError(String.Empty, "You have to book atleast 1 tamagotchi"); TempData["ViewData"] = ViewData; return(RedirectToAction("Create")); } foreach (var t in addToHotel) { t.HotelRoomId = hotelroom.Id; TamagotchiRepo.SetChanged(t); } TempData["Success"] = "Succesfully created booking for hotelroom number: " + hotelroom.Id; return(RedirectToAction("Index")); }
// GET: HotelRoom/Details/5 public ActionResult Details(int?id) { if (Session["User"] == null) { TempData["NotLoggedIn"] = "Please login or register to continue!"; return(RedirectToAction("Index", "Home")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HotelRoomViewModel hotelRoom = HotelRoomRepo.Find(id); if (hotelRoom == null) { return(HttpNotFound()); } return(View(hotelRoom)); }
public ActionResult Edit([Bind(Include = "Id,Size,Type")] HotelRoomViewModel hotelRoom) { if (Session["User"] == null) { TempData["NotLoggedIn"] = "Please login or register to continue!"; return(RedirectToAction("Index", "Home")); } if (!Session["Role"].Equals(UserRole.Staff)) { TempData["NotAuthorized"] = "You are not authorized to perform these actions!"; return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { HotelRoomRepo.SetChanged(hotelRoom); return(RedirectToAction("Index")); } return(View(hotelRoom)); }
public void Test_DeleteConfirmed() { HotelRoomViewModel t = new HotelRoomViewModel() { Size = 2, Type = HotelRoomType.Workroom }; IHotelTamagotchiContext c = new FakeHotelTamagotchiContext(); IHotelRoomRepository tr = new HotelRoomRepository(c); HotelRoomController tc = new HotelRoomController(tr); var ccMock = new Mock <ControllerContext>(); ccMock.SetupGet(x => x.HttpContext.Session["User"]).Returns("testUser"); ccMock.SetupGet(x => x.HttpContext.Session["Role"]).Returns(UserRole.Staff); tc.ControllerContext = ccMock.Object; tc.Create(t); tc.DeleteConfirmed(t.Id); Assert.IsFalse(tr.GetAll().Contains(t)); }
public void Test_Edit() { HotelRoomViewModel t = new HotelRoomViewModel() { Size = 2, Type = HotelRoomType.Workroom }; IHotelTamagotchiContext c = new FakeHotelTamagotchiContext(); IHotelRoomRepository tr = new HotelRoomRepository(c); HotelRoomController tc = new HotelRoomController(tr); var ccMock = new Mock <ControllerContext>(); ccMock.SetupGet(x => x.HttpContext.Session["User"]).Returns("testUser"); ccMock.SetupGet(x => x.HttpContext.Session["Role"]).Returns(UserRole.Staff); tc.ControllerContext = ccMock.Object; tc.Create(t); t.Size = 5; tc.Edit(t); Assert.AreEqual(tr.Find(t.Id).Size, 5); tr.Remove(t); }
public IActionResult InfoEdit(HotelRoomViewModel model) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { var tdinfo = _dbContext.HotelRoom.FirstOrDefault(x => x.HotelRoomUuid == model.HotelRoomUuid); tdinfo.HotelUuid = model.HotelUuid; tdinfo.HotelRoomName = model.HotelRoomName; tdinfo.Price = model.Price; tdinfo.Introduction = model.Introduction; tdinfo.Address = model.Address; tdinfo.Picture = model.Picture; int res = _dbContext.SaveChanges(); if (res > 0) { ToLog.AddLog("编辑", "成功:编辑:酒店房型信息列表数据", _dbContext); } response.SetSuccess("编辑成功"); return(Ok(response)); } }
public ActionResult Create(int?id) { if (TempData["ViewData"] != null) { ViewData = (ViewDataDictionary)TempData["ViewData"]; } if (!Session["Role"].Equals(UserRole.Customer)) { TempData["NotAuthorized"] = "You are not authorized to perform these actions!"; return(RedirectToAction("Index", "Home")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HotelRoomViewModel hotelRoom = HotelRoomRepo.Find(id); if (hotelRoom == null) { return(HttpNotFound()); } return(View(Tuple.Create(hotelRoom, TamagotchiRepo.GetAllHomelessTamagotchi()))); }
public void SetChanged(HotelRoomViewModel entity) { _database.SetChanged(entity.ToModel()); _database.SaveChanges(); }
public void Remove(HotelRoomViewModel entity) { _database.HotelRoom.Remove(entity.ToModel()); _database.SaveChanges(); }
public IActionResult Edit(int id, HotelRoomViewModel value) { throw new NotImplementedException("TODO"); }