//Bhawana(30/09/2019) //Save AppointmentDate While creating new Appoinment protected virtual void SaveAppointmentDates(AppointmentMaster model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var formData = this.Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString()); String[] AppointmentDate = formData["AppointmentDates"].Split(","); String[] RowId = formData["RowId"].Split(","); for (int i = 0; i < AppointmentDate.Count(); i++) { var appointmentDates = new AppointmentDates(); appointmentDates.AppointmentDate = Convert.ToDateTime(AppointmentDate[i]); appointmentDates.AppointmentMasterId = model.Id; appointmentDates.AppointmentStatusId = (int)AppointmentStatus.Created; model.AppointmentDates.Add(appointmentDates); } _appointmentServices.UpdateAppointment(model); }
public IActionResult Create(AppointmentModel model) { ResultModel resultModel = new ResultModel(); var AppointmentData = new AppointmentMaster(); try { if (ModelState.IsValid) { if (model.ID == 0) { AppointmentData.HospitalId = model.HospitalId; AppointmentData.PatientName = model.PatientName; AppointmentData.MR = model.MR; _appointmentServices.InsertAppointment(AppointmentData); SaveAppointmentDates(AppointmentData, model._appointmentDates); resultModel.Message = ValidationMessages.Success; resultModel.Status = 1; resultModel.Response = "Appointment Created"; return(Ok(resultModel)); } else { var appointmentData = _appointmentServices.GetAppointmentById(model.ID); appointmentData.Id = model.ID; appointmentData.HospitalId = model.HospitalId; appointmentData.PatientName = model.PatientName; appointmentData.MR = model.MR; _appointmentServices.UpdateAppointment(appointmentData); SaveAppointmentDates(appointmentData, model._appointmentDates); resultModel.Message = ValidationMessages.Success; resultModel.Status = 1; resultModel.Response = "Appointment Edited"; return(Ok(resultModel)); } } else { resultModel.Message = ValidationMessages.Failure; resultModel.Status = 0; resultModel.Response = "Appointment not created"; return(Ok(resultModel)); } } catch (Exception e) { _appointmentServices.DeleteAppointment(AppointmentData); return(Ok(model)); } }