Example #1
0
        public async Task <IActionResult> Profile(string username)
        {
            var user = await _userHelper.GetUserByEmailAsync(this.User.Identity.Name);

            if (username != null && !await _userHelper.IsUserInRoleAsync(user, RoleNames.Client))
            {
                user = await _userHelper.GetUserByEmailAsync(username);
            }

            if (user != null)
            {
                var model = _converterHelper.UserToUserProfileViewModel(user);

                if (await _userHelper.IsUserInRoleAsync(user, RoleNames.Doctor))
                {
                    var doctor = await _doctorRepository.GetDoctorByUserAsync(user);

                    model.Doctor       = doctor;
                    model.Appointments = await _appointmentRepository.GetDoctorsAppointmentsAsync(user.UserName);

                    model.SpecializationId = doctor.SpecializationId;
                    model.Specializations  = _specializationRepository.GetComboSpecializations();
                }
                else
                {
                    model.Appointments = await _appointmentRepository.GetAppointmentsAsync(user.UserName);

                    model.Animals = await _animalRepository.GetAnimalsAsync(user.UserName);

                    model.SpecializationId = 1; //SE NAO PASSAR UMA SPECIALIZATIONID DIFERENTE DE 0 O MODELO NÃO SE TORNA VÁLIDO
                }

                return(View(model));
            }
            ;

            return(NotFound());
        }