public ActionResult Create(Room room, HttpPostedFileBase image1) { if (image1 != null) { room.BrandImage = new byte[image1.ContentLength]; image1.InputStream.Read(room.BrandImage, 0, image1.ContentLength); } if (room.BrandImage == null) { ModelState.AddModelError("", "Please upload an image !"); } if (ModelState.IsValid) { foreach (Room r in db.Rooms) { if (r.Name == room.Name) { ModelState.AddModelError("Name", "Room already exists !"); return(View(room)); } } db.Rooms.Add(room); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(room)); }
public ActionResult Create([Bind(Include = "Id,Name,Capacity")] Room room) { if (ModelState.IsValid) { db.Rooms.Add(room); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(room)); }
public ActionResult Create([Bind(Include = "Id,Name,StartDate,EndDate,RoomId")] Reservation reservation) { if (ModelState.IsValid) { db.Reservations.Add(reservation); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RoomId = new SelectList(db.Rooms, "Id", "Name", reservation.RoomId); return(View(reservation)); }
public ActionResult Create(CreateReservationsVM reservation) { // Validari if (reservation.Name == null) { ModelState.AddModelError("Name", "Enter name!"); } if (reservation.Name == null) { ModelState.AddModelError("Subject", "Enter subject name!"); } if (reservation.RoomId <= 0) { ModelState.AddModelError("RoomId", "Select room name!"); } DateTime currentDateTime = System.DateTime.Now.Date; if (reservation.ReservationDate < currentDateTime) { ModelState.AddModelError("ReservationDate", "Wrong date!"); } if (reservation.ReservationDate == currentDateTime) { if (GetHour(reservation.StartHour).CompareTo(currentDateTime.Hour) == -1) { ModelState.AddModelError("StartHour", "Wrong Hours!"); } } if (reservation.StartHour.CompareTo(reservation.EndHour) == 0) { ModelState.AddModelError("", "Choose different hours!"); } if (reservation.StartHour == null && reservation.EndHour == null) { ModelState.AddModelError("StartHour", "Enter Hours!"); ModelState.AddModelError("EndHour", "Enter Hours!"); } else { int isDifferentHours = reservation.StartHour.CompareTo(reservation.EndHour); if (isDifferentHours == 1) { ModelState.AddModelError("EndHour", "The last Last Hour cannot be less then Start Hour!"); } } // Validarea suprema foreach (var elem in db.Reservations) { if (reservation.RoomId == elem.RoomId) { if (reservation.StartHour != null && reservation.EndHour != null) { if (reservation.ReservationDate.Date == elem.EndDate.Date && reservation.ReservationDate.Date == elem.StartDate.Date) { ModelState.AddModelError("", "This reservation is already in memory!"); } } } } if (ModelState.IsValid) { Reservation r = new Reservation() { Id = reservation.Id, Name = reservation.Name, Subject = reservation.Subject, RoomId = reservation.RoomId, }; r.StartDate = new DateTime(reservation.ReservationDate.Year, reservation.ReservationDate.Month, reservation.ReservationDate.Day, GetHour(reservation.StartHour), GetMinute(reservation.StartHour), 0); r.EndDate = new DateTime(reservation.ReservationDate.Year, reservation.ReservationDate.Month, reservation.ReservationDate.Day, GetHour(reservation.EndHour), GetMinute(reservation.EndHour), 0); db.Reservations.Add(r); db.SaveChanges(); return(RedirectToAction("Index")); } int actualHourVal = GetCurrentHour(); int actualMinuteVal = GetCurrentMinute(); List <string> listOfHours = new List <string>(); List <string> listOfStartHour = new List <string>(); List <string> listOfEndHour = new List <string>(); listOfHours = GetListOfHours(); ViewBag.ListOfStartHours = new SelectList(listOfHours); ViewBag.ListOfEndHours = new SelectList(listOfHours); ViewBag.RoomId = new SelectList(db.Rooms, "Id", "Name", reservation.RoomId); return(View(reservation)); }