public void RoomAvailabilityCreate() { RoomAvailabilitiesController controller = new RoomAvailabilitiesController(); RoomAvailability roomAvail = new RoomAvailability(); roomAvail.AccomodationId = 1; roomAvail.ArrivalDate = new DateTime(2015, 9, 22); roomAvail.DepartureDate = new DateTime(2016, 9, 28); roomAvail.IsPaid = true; roomAvail.RoomAvailabilityId = 0; roomAvail.RoomId = 1; roomAvail.TotalPrice = 100; roomAvail.UserId = "1"; var result = controller.Create(roomAvail); Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); Assert.IsNotNull(result); }
public void RoomAvailabilityInvalidInput() { RoomAvailabilitiesController controller = new RoomAvailabilitiesController(); RoomAvailability roomAvail = new RoomAvailability(); roomAvail.AccomodationId = 1; roomAvail.ArrivalDate = new DateTime(2015, 9, 22); roomAvail.DepartureDate = new DateTime(2016, 9, 28); roomAvail.IsPaid = true; roomAvail.RoomAvailabilityId = 0; roomAvail.RoomId = 1; roomAvail.TotalPrice = -100; roomAvail.UserId = "1"; var context = new ValidationContext(roomAvail, null, null); var results = new List<ValidationResult>(); TypeDescriptor.AddProviderTransparent(new AssociatedMetadataTypeTypeDescriptionProvider(typeof(RoomAvailability), typeof(RoomAvailability)), typeof(RoomAvailability)); var isModelStateValid = Validator.TryValidateObject(roomAvail, context, results, true); Assert.AreEqual(false, isModelStateValid); }
public ActionResult ReserveRoomConfirmed(int? id,DateTime ArrivalDate, DateTime DepartureDate, bool IsPaid, double TotalPrice, string UserId,double Price) { Room roomToReserve = db.Rooms.SingleOrDefault(x => x.RoomId == id); RoomAvailability roomToAddToAvailabilityDB = new RoomAvailability(); roomToAddToAvailabilityDB.AccomodationId = roomToReserve.AccomodationId; roomToAddToAvailabilityDB.ArrivalDate = ArrivalDate; roomToAddToAvailabilityDB.DepartureDate = DepartureDate; roomToAddToAvailabilityDB.IsPaid = IsPaid; roomToAddToAvailabilityDB.RoomId = roomToReserve.RoomId; roomToAddToAvailabilityDB.TotalPrice = TotalPrice; roomToAddToAvailabilityDB.UserId = UserId; if (String.IsNullOrEmpty(UserId)) { roomToReserve.TempArrivalDate = ArrivalDate; roomToReserve.TempDepartureDate = DepartureDate; roomToReserve.TempIsPaid = IsPaid; roomToReserve.TempTotalPrice = TotalPrice; roomToReserve.TempUserId = UserId; roomToReserve.Price = Price; ModelState.AddModelError("TempUserId", "You need to be registered user. Please register to reserve room and continue reservation process."); return View("ReserveRoom", roomToReserve); } else { ApplicationUser userIdForCheck; try { userIdForCheck = db.Users.First(x => x.Id == UserId); } catch { ModelState.AddModelError("TempUserId", "You need to be registered user. Please register to reserve room and continue reservation process."); return View("ReserveRoom", roomToReserve); } } db.RoomAvailabilities.Add(roomToAddToAvailabilityDB); string temp = Convert.ToString(roomToAddToAvailabilityDB.AccomodationId); var data = new Message { AccomodationId = roomToAddToAvailabilityDB.AccomodationId, Content = "You have new reservation. Please check your panel", senderName = "New reservation", ReceiverId = temp, SentDate=DateTime.UtcNow, Seen=false, ReceiverName="System Message"}; db.Messages.Add(data); db.SaveChanges(); ViewBag.reservation = "You have successfully reserved room!"; return RedirectToAction("Index", "Accomodations", new {reserved=1 }); }
public IHttpActionResult ReserveRoomConfirmed([FromBody]ReserveConfirmationModel model) { string userEmail = User.Identity.Name; Room roomToReserve = db.Rooms.SingleOrDefault(x => x.RoomId == model.id); RoomAvailability roomToAddToAvailabilityDB = new RoomAvailability(); roomToAddToAvailabilityDB.AccomodationId = roomToReserve.AccomodationId; roomToAddToAvailabilityDB.ArrivalDate = model.ArrivalDate; roomToAddToAvailabilityDB.DepartureDate = model.DepartureDate; roomToAddToAvailabilityDB.IsPaid = model.IsPaid; roomToAddToAvailabilityDB.RoomId = roomToReserve.RoomId; roomToAddToAvailabilityDB.TotalPrice = model.TotalPrice; roomToAddToAvailabilityDB.UserId = model.UserId; roomToAddToAvailabilityDB.UserEmail = userEmail; if (model.UserId == "unregistered") { return ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Please sign in or register in order to continue reservation process.")); } else { BitBooking.DAL.Models.ApplicationUser userIdForCheck; try { userIdForCheck = db.Users.First(x => x.Id == model.UserId); } catch { return ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Please sign in or register in order to continue reservation process.")); } } string temp = Convert.ToString(roomToAddToAvailabilityDB.AccomodationId); var data = new Message { AccomodationId = roomToAddToAvailabilityDB.AccomodationId, Content = "You have new reservation. Please check your panel", senderName = "New reservation", ReceiverId = temp, SentDate = DateTime.Now, Seen = false, ReceiverName = "System Message" }; db.Messages.Add(data); db.RoomAvailabilities.Add(roomToAddToAvailabilityDB); db.SaveChanges(); return Ok("You have sucessfully reserved a room!"); }