public async Task <IActionResult> OnPostAsync()
        {
            if (RegistrationForm.Birthday > DateTime.Today)
            {
                ModelState.AddModelError("RegistrationForm.Birthday", _cultureLocalizer.Text("Date must be from the past"));
                return(Page());
            }

            if (ModelState.IsValid)
            {
                var wasRegistrationCorrect = await authenticationService
                                             .Register(new Patient()
                {
                    Login     = RegistrationForm.Login,
                    Password  = RegistrationForm.Password,
                    BirthDate = RegistrationForm.Birthday.Value,
                    FirstName = RegistrationForm.FirstName,
                    LastName  = RegistrationForm.LastName,
                    FullName  = $"{RegistrationForm.FirstName} {RegistrationForm.LastName}",
                    Mail      = RegistrationForm.Mail,
                    Phone     = RegistrationForm.Phone
                });

                if (wasRegistrationCorrect)
                {
                    return(Redirect("Login"));
                }

                Msg = _cultureLocalizer.Text("Registration failed");
            }

            return(Page());
        }
Пример #2
0
        public async Task <IActionResult> OnPostAsync(int selectedDoctorId, int[] selectedReasonsIds, DateTime pickedDate)
        {
            if (ModelState.IsValid)
            {
                if (pickedDate < DateTime.UtcNow)
                {
                    ModelState.AddModelError("Date", _cultureLocalizer.Text("Date must be from the future"));
                }
                else
                {
                    Appointment.Doctor = new Doctor()
                    {
                        UserId = selectedDoctorId
                    };
                    if (selectedReasonsIds.Length > 0)
                    {
                        Appointment.AppointmentReasons = new List <Appointment2Reason>();
                        Array.ForEach(selectedReasonsIds, (reasonId) =>
                        {
                            Appointment.AppointmentReasons.Add(new Appointment2Reason()
                            {
                                ReasonId = reasonId
                            });
                        });
                    }
                    var patientId = AuthenticationUtils.GetPatientId(HttpContext);
                    if (patientId.HasValue)
                    {
                        Appointment.Patient = new Patient()
                        {
                            UserId = patientId.Value
                        };
                    }


                    Appointment.AppointmentDate = pickedDate;
                    appointmentsSetResponse     = await _appointmentsService.SetAppointment(Appointment);

                    if (appointmentsSetResponse == AppointmentSetResponse.CORRECT)
                    {
                        HttpContext.Response.Redirect(CurentCultureUtils.GetCurrentCultureLink("Appointments/AppointmentMade"));

                        return(null);
                    }
                }
            }


            await OnGetAsync();

            SelectedDoctor = selectedDoctorId;
            SelectedResons = selectedReasonsIds;
            Date           = pickedDate;
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var user = new User()
                {
                    Login    = LoginForm.Username,
                    Password = LoginForm.Password
                };
                var authenticationReponse = await authenticationService.Login(user);

                if (authenticationReponse.WasAuthenticationCorrect)
                {
                    HttpContext.Response.Redirect(CurentCultureUtils.GetCurrentCultureLink("Index"));

                    return(null);
                }
                Msg = _cultureLocalizer.Text("InvalidLogin");
            }

            return(Page());
        }