public ActionResult Create() { var model = new BookingAppointment(); model.DrivingTypeList = new SelectList(_autogearRepo.DrivingTypeItems(), "Value", "Text"); if (User.IsInRole("Admin")) { model.StudentList = new SelectList(_studentRepo.GetStudents(), "Value", "Text"); model.InstructorList = new SelectList(_instructorRepo.GetInstructorNames(), "Value", "Text"); } else { model.StudentList = new SelectList(_studentRepo.GetInstructorStudents(User.Identity.GetUserId()), "Value", "Text"); model.InstructorList = new SelectList(_instructorRepo.GetInstructorNames(User.Identity.GetUserId()), "Value", "Text"); } return View(model); }
public ActionResult Create(BookingAppointment bookingAppointment) { if (ModelState.IsValid) { var currentUser = Request.GetOwinContext().Authentication.User.Identity.GetUserId(); bookingAppointment.StudentId = bookingAppointment.StudentId; if (!string.IsNullOrEmpty(bookingAppointment.InstructorNumber)) { var instructor = _instructorRepo.GetInstructorById(bookingAppointment.InstructorNumber); if (instructor != null) { bookingAppointment.InstructorId = instructor.InstructorId; bookingAppointment.InstructorName = instructor.FirstName + " " + instructor.LastName; } } _studentRepo.SaveStudentAppointment(bookingAppointment, currentUser); return View("Index"); } bookingAppointment.StudentList = new SelectList(_studentRepo.GetStudents(), "Value", "Text", bookingAppointment.StudentId); bookingAppointment.InstructorList = new SelectList(_instructorRepo.GetInstructorNames(), "Value", "Text", bookingAppointment.InstructorNumber); bookingAppointment.DrivingTypeList = new SelectList(_autogearRepo.DrivingTypeItems(), "Value", "Text", bookingAppointment.BookingType); return View(bookingAppointment); }
public BookingAppointment GetBookingDetailsById(int bookingId) { var bookingDetailsById = new BookingAppointment(); var bookingDetails = TblStudentBookings.SingleOrDefault(s => s.BookingId == bookingId); if (bookingDetails != null) { bookingDetailsById.BookingId = bookingDetails.BookingId; bookingDetailsById.InstructorId = bookingDetails.InstructorId; bookingDetailsById.StartDate = bookingDetails.StartDate; bookingDetailsById.EndDate = bookingDetails.EndDate; bookingDetailsById.BookingType = bookingDetails.Type; bookingDetailsById.PickupLocation = bookingDetails.PickupLocation; if (bookingDetails.StopTime != null) bookingDetailsById.StopTime = (TimeSpan) bookingDetails.StopTime; if (bookingDetails.StartTime != null) bookingDetailsById.StartTime = (TimeSpan) bookingDetails.StartTime; var studentDetails = TblStudents.SingleOrDefault(s => s.StudentId == bookingDetails.StudentId); if (studentDetails != null) { bookingDetailsById.StudentId = studentDetails.StudentId; bookingDetailsById.StudentName = studentDetails.FirstName + " " + studentDetails.LastName; } } return bookingDetailsById; }
public void SaveStudentAppointment(BookingAppointment bookingAppointment, string currentUser) { var studentDetails = TblStudents.FirstOrDefault(s => s.StudentId == bookingAppointment.StudentId); if (studentDetails != null) { var startDate = Convert.ToDateTime(bookingAppointment.StartDate); var endDate = Convert.ToDateTime( bookingAppointment.EndDate); var days =endDate.Subtract(startDate).Days; if (startDate == endDate) days += 1; for (var i = 0; i < days; i++) { var bookingDate = new DateTime(startDate.Year, startDate.Month, startDate.Day + i); var bookingDetails = DataContext.Bookings.FirstOrDefault(s => s.BookingId == bookingAppointment.BookingId && s.StartDate == bookingAppointment.StartDate ) ?? new Booking(); bookingDetails.InstructorId = bookingAppointment.InstructorId; bookingDetails.BookingDate = DateTime.Now; bookingDetails.StartTime = bookingAppointment.StartTime; bookingDetails.EndTime = bookingAppointment.StopTime; bookingDetails.Status = bookingAppointment.BookingType; bookingDetails.StudentId = studentDetails.StudentId; bookingDetails.CreatedBy = currentUser; bookingDetails.CreatedDate = DateTime.Now; bookingDetails.StartDate = bookingDate; bookingDetails.EndDate = bookingDate; bookingDetails.PickupLocation = bookingAppointment.PickupLocation; bookingDetails.Type = bookingAppointment.BookingType; bookingDetails.Remarks = bookingAppointment.RemarksForInstructor; bookingDetails.DrivingTestStatus = bookingAppointment.DrivingTestStatus; if(GetBookingsCountByStudentId(bookingAppointment.StudentId) == 0) { bookingDetails.IsFirst = true; } else { bookingDetails.IsFirst = false; } if (bookingAppointment.BookingType == "Canceled") { bookingDetails.CancelledReason = bookingAppointment.CancelReason; bookingDetails.CancelledDate = DateTime.Now; } if (bookingAppointment.BookingId == 0) DataContext.Bookings.Add(bookingDetails); else { bookingDetails.ModifiedBy = currentUser; bookingDetails.ModifiedDate = DateTime.Now; } DataContext.SaveChanges(); } } }
public ActionResult Edit(BookingAppointment bookingAppointment) { if (ModelState.IsValid) { var currentUser = Request.GetOwinContext().Authentication.User.Identity.GetUserId(); var studentId = Convert.ToInt32(bookingAppointment.StudentId); var student = _studentRepo.TblStudents.FirstOrDefault(s => s.StudentId == studentId); if (student != null) { bookingAppointment.StudentName = student.FirstName + " " + student.LastName; bookingAppointment.StudentId = student.StudentId; } if (!string.IsNullOrEmpty(bookingAppointment.InstructorNumber)) { var instructor = _instructorRepo.GetInstructorById(bookingAppointment.InstructorNumber); if (instructor != null) { bookingAppointment.InstructorId = instructor.InstructorId; bookingAppointment.InstructorName = instructor.FirstName + " " + instructor.LastName; } } _studentRepo.SaveStudentAppointment(bookingAppointment, currentUser); return View("Index"); } return View(); }
public ActionResult SaveAppointment(BookingAppointment model) { Console.WriteLine("Test"); var currentUser = Request.GetOwinContext().Authentication.User.Identity.GetUserId(); if (ModelState.IsValid) { if (_instructorRepo.CheckIsAnyAppointmentsForInsturcotrOrStudent(model) && model.BookingId == 0) { return Json(new Status { StatusName = "Error", Message = "Instructor or Student are booked in this timings" }); } var instructor = new Instructor(); if (!string.IsNullOrEmpty(model.InstructorNumber)) { instructor = _instructorRepo.GetInstructorById(model.InstructorNumber); if (instructor != null) model.InstructorId = instructor.InstructorId; } var student = _studentRepo.GetStudentById(model.StudentId); _studentRepo.SaveStudentAppointment(model, currentUser); string startdate = Convert.ToDateTime(model.StartDate).ToString("dd/MM/yyyy"); string enddate = Convert.ToDateTime(model.EndDate).ToString("dd/MM/yyyy"); //EmailAPI.SendEmailToStudent(student.FirstName, startdate + " " + model.StartTime, enddate + " " + model.StopTime, model.PickupLocation, instructor.FirstName + " " + instructor.LastName, model.MobileNumber, instructor.Email // , student.Email); //SMSAPI.SendSMStoStudent(student.FirstName, startdate + " " + model.StartTime, enddate + " " + model.StopTime, model.PickupLocation, instructor.FirstName + " " + instructor.LastName, instructor.Mobile, model.MobileNumber); return Json(new Status {StatusName = "Success", Message = ""}); } var drivingTypeItems = _autogearRepo.DrivingTypeItems(); if (model.BookingId > 0) drivingTypeItems.Add(_autogearRepo.CancelledItem()); model.StudentList = new SelectList(_studentRepo.GetStudents(), "Value", "Text", model.StudentId); model.InstructorList = new SelectList(_instructorRepo.GetInstructorNames(), "Value", "Text", model.InstructorNumber); model.DrivingTypeList = new SelectList(drivingTypeItems, "Value", "Text", model.BookingType); return View("BookingAppointment", model); }
public void SaveBookingAppointment(BookingAppointment bookingAppointment) { var currentUser = Request.GetOwinContext().Authentication.User.Identity.GetUserId(); if (!string.IsNullOrEmpty(bookingAppointment.InstructorNumber)) { var instructor = _instructorRepo.GetInstructorById(bookingAppointment.InstructorNumber); if (instructor != null) bookingAppointment.InstructorId = instructor.InstructorId; } _studentRepo.SaveStudentAppointment(bookingAppointment, currentUser); }
public BookingAppointment GetBookingAppointmentById(int bookingAppointmentId) { var booking = TblBookings.FirstOrDefault(s => s.BookingId == bookingAppointmentId); var bookingAppointment = new BookingAppointment { BookingId = bookingAppointmentId }; if (booking != null) { bookingAppointment.StudentId = booking.StudentId; var instructor = TblInstructors.FirstOrDefault(s => s.InstructorId == booking.InstructorId); if (instructor != null) bookingAppointment.InstructorNumber = instructor.InstructorNumber; if (booking.StartTime != null) bookingAppointment.StartTime = booking.StartTime.Value; if (booking.StopTime != null) bookingAppointment.StopTime = booking.StopTime.Value; bookingAppointment.StartDate = booking.StartDate; bookingAppointment.EndDate = booking.EndDate; bookingAppointment.PickupLocation = booking.PickupLocation; bookingAppointment.BookingType = booking.Type; bookingAppointment.DrivingTestStatus = booking.DrivingTestStatus; } return bookingAppointment; }
public Boolean CheckIsAnyAppointmentsForInsturcotrOrStudent(BookingAppointment appointment) { Boolean flag = false; var instructor = TblInstructors.FirstOrDefault(s => s.InstructorNumber == appointment.InstructorNumber); var instructorBookings = TblBookings.Where( s => s.InstructorId == instructor.InstructorId && s.Type != "Canceled" && ( (appointment.StartDate >= s.StartDate && s.EndDate>=appointment.StartDate) ||(appointment.EndDate>=s.StartDate && appointment.EndDate<= s.EndDate))&& ((appointment.StartTime >= s.StartTime && appointment.StartTime <= s.StopTime) || (appointment.StopTime >= s.StartTime && appointment.StopTime <= s.StopTime))).ToList(); var studentBookings = TblBookings.Where( s => s.StudentId == appointment.StudentId && s.Type != "Canceled" && ((appointment.StartDate >= s.StartDate && appointment.StartDate <= s.EndDate) || (appointment.EndDate>= s.StartDate && appointment.EndDate <= s.EndDate))&& ((appointment.StartTime >= s.StartTime && appointment.StartTime <= s.StopTime) || (appointment.StopTime >= s.StartTime && appointment.StopTime <= s.StopTime))).ToList(); //var leaves = // TblInstructorLeaves.Where( // s => s.InstructorId == instructor.InstructorId && // ( (appointment.StartDate <= s.StartDate && s.EndDate >= appointment.StartDate)||(appointment.EndDate>=s.StartDate&&appointment.EndDate<=s.EndDate)) // ).ToList(); if (instructorBookings.Count > 0 || studentBookings.Count > 0)// || leaves.Count > 0) flag = true; return flag; }