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 SaveInstructor(RegisterViewModel model) { // Save Address var instructorAddress = new Address { Address1 = model.AddressLine1, AddressLine2 = model.AddressLine2, Phone = model.Phone, Mobile = model.Mobile, PostCode = Convert.ToInt32(model.PostalCode), CreatedDate = DateTime.Now, CreatedBy = model.CreatedUser, }; if (model.SuburbId != 0) instructorAddress.SuburbID = model.SuburbId; DataContext.Addresses.Add(instructorAddress); SaveInDatabase(); // _instructorRepo. // Create Instructor account var instructor = new Instructor { Created_Date = DateTime.Now, InstructorId = model.InstructorId, Created_By = model.CreatedUser, InstructorNumber = "INS-" + model.LastInstructor, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, Gender = model.Gender.ToString(), Mobile = model.Mobile, Phone = model.Phone, AddressId = instructorAddress.AddressId, Status = model.Status, Areas = model.AreaIds }; DataContext.Instructors.Add(instructor); SaveInDatabase(); foreach (var iarea in model.AreaNames.Split(',')) { // Instructor Area var instructorArea = new InstructorArea { InstructorID = instructor.InstructorId, AreaId = Convert.ToInt32(iarea) }; DataContext.InstructorAreas.Add(instructorArea); SaveInDatabase(); } }