/// <summary> /// Creates an UserViewModel given an User object. /// </summary> /// <param name="user">User object to be used as source of values.</param> /// <param name="practice"> </param> /// <param name="medicalEntity">medical entity, if the user is a doctor. If medical entity is null, medical entity won't be added to the view-model even if the user is a doctor</param> /// <param name="medicalSpecialty">medical specialty, if the user is a doctor. If medical specialty is null, medical specialty won't be added to the view-model even if the user is a doctor</param> /// <returns>A new UserViewModel with informations copied from the User object.</returns> public static UserViewModel GetViewModel( [NotNull] User user, [NotNull] Practice practice, SYS_MedicalEntity medicalEntity = null, SYS_MedicalSpecialty medicalSpecialty = null) { if (user == null) { throw new ArgumentNullException("user"); } if (practice == null) { throw new ArgumentNullException("practice"); } var address = user.Person.Addresses.SingleOrDefault(); var viewModel = new UserViewModel(); FillUserViewModel(user, practice, viewModel); viewModel.Address = address == null ? new AddressViewModel() : new AddressViewModel { CEP = address.CEP, City = address.City, Complement = address.Complement, Neighborhood = address.Neighborhood, StateProvince = address.StateProvince, Street = address.Street }; var userDoctor = user.Doctor; if (userDoctor != null) { FillDoctorViewModel(user, medicalEntity, medicalSpecialty, viewModel, userDoctor); } return(viewModel); }
internal static void FillDoctorViewModel(User user, SYS_MedicalEntity medicalEntity, SYS_MedicalSpecialty medicalSpecialty, UserViewModel viewModel, Doctor doctor) { viewModel.MedicCRM = doctor.CRM; viewModel.MedicalSpecialtyId = medicalSpecialty != null ? medicalSpecialty.Id : (int?)null; viewModel.MedicalSpecialtyName = medicalSpecialty != null ? medicalSpecialty.Name : null; viewModel.MedicalEntityId = medicalEntity != null ? medicalEntity.Id : (int?)null; viewModel.MedicalEntityName = medicalEntity != null ? medicalEntity.Name : null; viewModel.MedicalEntityJurisdiction = (int)(TypeEstadoBrasileiro)Enum.Parse( typeof(TypeEstadoBrasileiro), user.Doctor.MedicalEntityJurisdiction); }