public async Task <IActionResult> Index(PhysicianSpecialization specialization, DateTime startDate, AppointmentType appointmentType)
        {
            var model = new AddAppointmentViewModel
            {
                FreeTerms = new List <Appointment>()
            };

            if (startDate < DateTime.Now)
            {
                return(View(model));
            }

            try
            {
                var builder = new StringBuilder("Appointments/free/?");
                var query   = HttpUtility.ParseQueryString(string.Empty);
                query["specialization"] = specialization.ToString();
                query["startDate"]      = startDate.ToString("MM.dd.yyyy"); // little hack
                query["type"]           = appointmentType.ToString();
                builder.Append(query.ToString());

                model.FreeTerms = await _client.SendRequestAsync <List <Appointment> >(HttpMethod.Get, builder.ToString());

                return(View(model));
            }
            catch (HttpRequestException)
            {
                ModelState.AddModelError("TryAgain", _localizer["TryAgain"]);
                return(View(model));
            }
        }
        public AddAppointment(int id)
        {
            InitializeComponent();
            var addAppointmentViewModel = new AddAppointmentViewModel(id);

            DataContext = addAppointmentViewModel;
        }
        public ActionResult AddAppointment(AddAppointmentViewModel viewModel)
        {
            if (appointmentsService.IsValidModelState())
            {
                Appointment appointment = new Appointment();

                double          summedMinutes = 0;
                List <Activity> activities    = activitiesService.GetAll(a => viewModel.CheckedRows.Contains(a.ActivityId)).ToList();
                foreach (Activity activity in activities)
                {
                    summedMinutes += activity.Duration;
                    appointment.Activities.Add(activity);
                }

                DateTime startDateTime = viewModel.StartDateTime;
                appointment.StartDateTime = startDateTime;
                TimeSpan summedDuration = TimeSpan.FromMinutes(summedMinutes);
                DateTime endDateTime    = startDateTime.Add(summedDuration);
                appointment.EndDateTime = endDateTime;
                appointment.UserId      = LoginUserSession.Current.UserId;
                bool hasSavedSuccessfully = appointmentsService.Add(appointment);
                if (hasSavedSuccessfully)
                {
                    TempData["SuccessfullMessage"] = "Appointment added successfully";
                    return(RedirectToAction("ViewAppointments", "Appointments"));
                }
                else
                {
                    TempData["ErrorMessage"] = "There was a server error while adding the appointment.";
                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(View(viewModel));
        }
        private void FillAddAppointmentViewModel(AddAppointmentViewModel model)
        {
            var patients = _patientService.GetPatients();
            var doctors  = _staffService.GetStaffs();

            model.Patients = patients.OrderBy(p => p.FullName).ToList();
            model.Doctors  = doctors.OrderBy(d => d.FullName).ToList();
        }
Example #5
0
        public AddAppointmentWindow()
        {
            InitializeComponent();
            AddAppointmentViewModel viewModel = new AddAppointmentViewModel();

            DataContext           = viewModel;
            viewModel.CloseWindow = new Action(Close);
        }
        public IActionResult AddAppointment(int id = 0)
        {
            AppUser user     = GetUser().Result;
            int     DoctorId = (int)user.DoctorId;

            AddAppointmentViewModel model = new AddAppointmentViewModel()
            {
                PlaceId = id, place = repository.GetPlaceById(id), DoctorId = DoctorId
            };

            return(View(model));
        }
        public AddAppointmentPage(List <Models.Patients> _Patients, List <Models.Departments> DepartmentsList, List <Models.Doctors> _Doctors)
        {
            var TheViewModel = new AddAppointmentViewModel();

            BindingContext = TheViewModel;

            InitializeComponent();

            DateName.MinimumDate = DateTime.Now;
            //DateName.MinimumDate = Convert.ToDateTime("1/1/1980");

            PatientName.ItemsSource    = _Patients.ToList();
            DepartmentName.ItemsSource = DepartmentsList.ToList();
            DoctortName.ItemsSource    = _Doctors.ToList();
        }
        public IActionResult AddAppointment(AddAppointmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var succeeded = _patientService.UpdateBackground(model.PatientId, model.PatientBackground);

                if (!succeeded)
                {
                    return(this.InternalServerError());
                }

                Debug.Assert(model.Date != null, "model.Date != null");
                Debug.Assert(model.Time != null, "model.Time != null");
                var appointmentDateTime = model.Date.Value.Date + model.Time.Value.TimeOfDay;

                var error = _appointmentsService.AddAppointment(new AddAppointmentRequest
                {
                    CreatedAt       = DateTime.Now,
                    Date            = appointmentDateTime,
                    Description     = model.Description,
                    PatientId       = model.PatientId,
                    StaffId         = model.DoctorId,
                    CreatorUserType = UserTypeEnum.STAFF
                });

                switch (error)
                {
                case null:
                    return(RedirectToAction("Index"));

                case ResponseErrorEnum.StaffAlreadyHasAppointmentOnDateTime:
                    ModelState.AddModelError(nameof(model.Time), "The doctor already has an appointment at this time.");
                    break;

                default:
                    return(this.InternalServerError());
                }
            }

            var indexModel = new AppointmentsViewModel();

            FillAppointmentViewModel(indexModel);
            indexModel.AddAppointmentViewModel = model;
            FillAddAppointmentViewModel(model);
            indexModel.OpenAddAppointmentModal = true;
            return(View("Index", indexModel));
        }
        public IActionResult AddAppointment(AddAppointmentViewModel model)
        {
            DateTime now = time.GetTime();


            if (model.Appointment.AppointmentDate.HasValue && model.Appointment.AppointmentStart.HasValue && model.Appointment.AppointmentEnd.HasValue)
            {
                if (now.Date > model.Appointment.AppointmentDate)
                {
                    ModelState.AddModelError("Appointment.AppointmentDate", "Podaj późniejszą datę");
                }
                else if (now.Date == model.Appointment.AppointmentDate)
                {
                    now = now.AddHours(1);
                    int value = DateTime.Compare(model.Appointment.AppointmentStart.Value, now);

                    if (value <= 0)
                    {
                        ModelState.AddModelError("Appointment.AppointmentStart", "Podaj późniejszą godzinę");
                    }
                }
                else if (repository.CheckIfAppointmentExists(model))
                {
                    ModelState.AddModelError("Appointment.AppointmentStart", "Posiadasz już wizytę w tych godzinach");
                }
                else if (model.Appointment != null && ((DateTime)model.Appointment.AppointmentStart).Day < ((DateTime)model.Appointment.AppointmentEnd).Day || ((DateTime)model.Appointment.AppointmentStart).Day > ((DateTime)model.Appointment.AppointmentEnd).Day)
                {
                    ModelState.AddModelError("Appointment.AppointmentStart", "Wizyta może trwać tylko jeden dzień");
                }
            }



            if (ModelState.IsValid)
            {
                repository.AddAppointment(model);
                return(RedirectToAction("ManageAppointments"));
            }
            else
            {
                return(View("AddAppointment", model));
            }
        }
        public ActionResult AddAppointment()
        {
            IEnumerable <Activity> dbActivities = activitiesService.GetAll();

            List <ActivityRow>      activityRows = new List <ActivityRow>();
            AddAppointmentViewModel viewModel    = new AddAppointmentViewModel();
            DateTime currentTime = DateTime.Now;

            viewModel.StartDateTime = currentTime;
            viewModel.EndDateTime   = currentTime;

            foreach (Activity activity in dbActivities)
            {
                ActivityRow activityRow = new ActivityRow();
                activityRow.activity  = activity;
                activityRow.isChecked = false;
                activityRows.Add(activityRow);
            }
            viewModel.activityRows = activityRows;
            return(View(viewModel));
        }
Example #11
0
 public IActionResult Add(AddAppointmentViewModel viewModel)
 {
     return(View(viewModel));
 }
Example #12
0
 public AddAppointmentView(MainViewModel mainVM)
 {
     InitializeComponent();
     DataContext = new AddAppointmentViewModel(mainVM);
 }
Example #13
0
        public ActionResult UpdateAppointment(AddAppointmentViewModel model)
        {
            try
            {
                IAccountService account_service = StructureMap.ObjectFactory.GetInstance <IAccountService>();
                IGroupService   group_service   = StructureMap.ObjectFactory.GetInstance <IGroupService>();
                Appointment     appointment     = null;

                if (!model.Id.IsNullOrEmpty())
                {
                    long id = Int64.Parse(model.Id);

                    appointment = service.GetObject(id);

                    if (appointment.IsAllDay)
                    {
                        var start = model.StartTime;
                        var date  = model.StartDate;
                        model.EndDate = date;
                        model.EndTime = TimeSpan.Parse(start).Add(TimeSpan.Parse("02:00")).ToString();
                    }

                    if (!model.Details.IsNullOrEmpty())
                    {
                        appointment.Details = model.Details;
                    }

                    appointment.IsAllDay = model.IsAllDay;

                    if (model.EndDate == "Invalid date")
                    {
                        model.EndDate = model.StartDate;
                    }

                    if (!model.IsAllDay)
                    {
                        appointment.StartTime = DateTime.Parse(model.StartDate).Add(TimeSpan.Parse(model.StartTime));
                        appointment.EndTime   = (DateTime?)(DateTime.Parse(model.EndDate)).Add(TimeSpan.Parse(model.EndTime));
                    }
                    else
                    {
                        appointment.StartTime = DateTime.Parse(model.StartDate);
                        appointment.EndTime   = DateTime.Parse(model.EndDate);
                    }

                    appointment.Visibily = byte.Parse(model.Visiblity);

                    if (!model.Place.IsNullOrEmpty())
                    {
                        appointment.Place = model.Place;
                    }

                    service.SaveObject(appointment);
                }
                else
                {
                    appointment = new Appointment()
                    {
                        Title        = model.Title,
                        StartTime    = model.IsAllDay ? DateTime.Parse(model.StartDate) : DateTime.Parse(model.StartDate).Add(TimeSpan.Parse(model.StartTime)),
                        EndTime      = model.IsAllDay ? DateTime.Parse(model.EndDate) : DateTime.Parse(model.EndDate).Add(TimeSpan.Parse(model.EndTime)),
                        Details      = model.Details,
                        IsAllDay     = model.IsAllDay,
                        CreationTime = DateTime.Now,
                        CreatorId    = Account.Id,
                        Place        = model.Place,
                        Visibily     = Byte.Parse(model.Visiblity),
                    };

                    service.SaveObject(appointment);

                    if (!model.ShareInfo.IsNullOrEmpty() && model.ShareInfo != "|")
                    {
                        foreach (string str in model.ShareInfo.Split('|'))
                        {
                            if (str.StartsWith("g-"))
                            {
                                var str2 = str.Substring(2);
                                service.SendAppointmentToGroup(appointment, Int64.Parse(str2));
                            }
                            else if (str.IsNullOrEmpty())
                            {
                                ;
                            }
                            else
                            {
                                service.SendAppointmentInvition(appointment, Int64.Parse(str));
                            }
                        }
                    }
                }

                return(Content("success"));
            }
            catch (Exception e)
            {
                return(Content(e.Message));
            }
        }