Пример #1
0
        public ActionResult Create([Bind(Include = "Rooms,RoomName,Description,Capacity")] Room room)
        {
            if (ModelState.IsValid)
            {
                db.Rooms.Add(room);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(room));
        }
        public ActionResult Edit(BookingEdit booking, string bookingType)
        {
            booking.DateCreated = DateTime.Now;
            booking.CreatedBy   = User.Identity.Name.ToString();
            booking.StartDate   = booking.StartDate.AddHours(double.Parse(booking.StartTime));
            booking.EndDate     = booking.EndDate.AddHours(double.Parse(booking.EndTime));
            booking.BookingType = bookingType;



            if (ModelState.IsValid)
            {
                bool conflict = false;

                foreach (var id in booking.RoomIds)
                {
                    if (db.Bookings.Any(b => ((b.StartTime >= booking.StartDate) && (b.EndTime <= booking.EndDate)) && b.RoomId.Equals(id) && b.BookingId != booking.BookingId))
                    {
                        conflict      = true;
                        ViewBag.Error = "This room and time have been reserved.";
                    }
                }
                if (!conflict)
                {
                    if (booking.EndDate < booking.StartDate)
                    {
                        ViewBag.Error = "The End Date Can't Be Before the Start Date.";
                    }
                    else
                    {
                        foreach (var id in booking.RoomIds)
                        {
                            db.Entry(booking.GetBooking(id)).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                        return(RedirectToAction("Details", new { id = booking.BookingId }));
                    }
                }
            }
            var mgmt = new BookingMgmt(bookingRepository);

            return(View(mgmt.GetBookingEdit(booking.StartDate, booking.StartDate, booking.EndDate, booking.ViewRoomName, booking.ViewName)));
        }
Пример #3
0
        public async Task GetsExistingAppointment()
        {
            var existingAppointment = AppointmentBuilder.WithDefaultValues();

            _context.Appointments.Add(existingAppointment);
            _context.SaveChanges();
            int appointmentId = existingAppointment.Id;

            _output.WriteLine($"AppointmentId: {appointmentId}");

            var appointmentFromRepo = await _appointmentRepository.GetByIdAsync(appointmentId);

            Assert.Equal(AppointmentBuilder.TestCustomer.Id, appointmentFromRepo.CustomerId);
            Assert.Equal(AppointmentBuilder.TestEmployee.Id, appointmentFromRepo.EmployeeId);
        }