Beispiel #1
0
        public async Task <IActionResult> Create(SelectPersonType selectPersonType)
        {
            if (ModelState.IsValid)
            {
                var availability = await accountService.AvailabilityEmailAsync(selectPersonType.Email, selectPersonType.Type);

                if (!availability.Any())
                {
                    // ou get do google
                    ContactModel contact = new ContactModel
                    {
                        Type  = ContactType.Email,
                        Value = selectPersonType.Email,
                    };
                    var phone = new ContactModel {
                        Type = ContactType.Phone
                    };
                    if (selectPersonType.Type == PersonType.Doctor)
                    {
                        var specialities = await specialtyService.GetSpecialtyAsync();

                        var doctormodel = new SimpleDoctorModel
                        {
                            Specialties = specialities,
                            Name        = selectPersonType.Name,
                            Password    = selectPersonType.Password
                        };

                        doctormodel.Contacts.Add(contact);
                        doctormodel.Contacts.Add(phone);

                        return(View(nameof(CreateDoctor), doctormodel));
                    }
                    else
                    {
                        var patientModel = new SimplePatientModel
                        {
                            Name     = selectPersonType.Name,
                            Password = selectPersonType.Password
                        };

                        patientModel.Contacts.Add(contact);
                        patientModel.Contacts.Add(phone);
                        return(View(nameof(CreatePatient), patientModel));
                    }
                }

                ModelState.SetModelErrors(availability);
            }

            return(View(selectPersonType));
        }