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));
            }
        }
示例#2
0
        public IActionResult Create(AppointmentModel model)
        {
            if (!(bool)SharedData.isAppointmentMenuAccessible)
            {
                return(AccessDeniedView());
            }
            var appointmentId = 0;

            try
            {
                if (ModelState.IsValid)
                {
                    var AppointmentData = new AppointmentMaster();
                    //Insert Appointment
                    if (model.Id == 0)
                    {
                        AppointmentData.HospitalId  = model.HospitalId;
                        AppointmentData.PatientName = model.PatientName;
                        AppointmentData.MR          = model.MR;
                        AppointmentData.CreatedOn   = DateTime.UtcNow;
                        AppointmentData.Deleted     = false;

                        _appointmentServices.InsertAppointment(AppointmentData);

                        appointmentId = AppointmentData.Id;
                        SaveAppointmentDates(AppointmentData);
                        AddNotification(NotificationMessage.TitleSuccess, NotificationMessage.msgAddAppointment, NotificationMessage.TypeSuccess);
                        return(RedirectToAction("Index", "Appointment"));
                    }

                    //EditAppointment
                    else
                    {
                        AppointmentData.Id          = model.Id;
                        AppointmentData.HospitalId  = model.HospitalId;
                        AppointmentData.PatientName = model.PatientName;
                        AppointmentData.MR          = model.MR;
                        _appointmentServices.UpdateAppointment(AppointmentData);
                        AddNotification(NotificationMessage.TitleSuccess, NotificationMessage.msgEditAppointment, NotificationMessage.TypeSuccess);

                        return(RedirectToAction("Index", "Appointment"));
                    }
                }
                else
                {
                    model.AvailableHospitals.Add(new SelectListItem {
                        Text = "Select Hospitals", Value = "0"
                    });
                    foreach (var c in _hospitalServices.GetAllHospital())
                    {
                        model.AvailableHospitals.Add(new SelectListItem
                        {
                            Text     = _encryptionService.DecryptText(c.HospitalName),
                            Value    = c.Id.ToString(),
                            Selected = c.Id == model.HospitalId
                        });
                    }
                    if (model.Id != 0)
                    {
                        var appointment = _appointmentServices.GetAppointmentById(model.Id);
                        foreach (var ApointmentDate in appointment.AppointmentDates)
                        {
                            var appointmentDate = new AppointmentDatesModel
                            {
                                AppointmentDates    = ApointmentDate.AppointmentDate,
                                AppointmentMasterId = ApointmentDate.AppointmentMasterId,
                                Id = ApointmentDate.Id
                            };
                            model._appointmentDates.Add(appointmentDate);
                        }
                    }

                    return(View(model));
                }
            }
            catch (Exception e)
            {
                var AppointmentData = _appointmentServices.GetAppointmentById(appointmentId);
                _appointmentServices.DeleteAppointment(AppointmentData);
                model.AvailableHospitals.Add(new SelectListItem {
                    Text = "Select Hospitals", Value = "0"
                });
                foreach (var c in _hospitalServices.GetAllHospital())
                {
                    model.AvailableHospitals.Add(new SelectListItem
                    {
                        Text     = _encryptionService.DecryptText(c.HospitalName),
                        Value    = c.Id.ToString(),
                        Selected = c.Id == model.HospitalId
                    });
                }
                AddNotification(NotificationMessage.TitleError, NotificationMessage.ErrorMsg, NotificationMessage.TypeError);

                return(View(model));
            }
        }