public ActionResult List() { var countries = _stateProvinceService.GetAllStateProvince(); var model = countries.Select(c => new StateProvinceViewModel { Id = c.Id, Name = c.Name, CountryName = _countryService.GetCountryById(c.CountryId).Name, DisplayOrder = c.DisplayOrder, Abbreviation = c.Abbreviation, Published = c.Published, CountryId = c.CountryId }).ToList(); return(View(model)); }
/// <summary> /// Import doctors from XLSX file /// </summary> /// <param name="stream">Stream</param> /// <param name="userId"></param> /// <param name="iRow"></param> public virtual void ImportDoctorsFromXlsx(Stream stream, string userId, int iRow) { //property array var properties = new[] { new PropertyByName <Doctor>("FirstName"), new PropertyByName <Doctor>("LastName"), new PropertyByName <Doctor>("Email"), new PropertyByName <Doctor>("PhoneNumber"), new PropertyByName <Doctor>("Gender"), new PropertyByName <Doctor>("Speciality"), new PropertyByName <Doctor>("ShortProfile"), new PropertyByName <Doctor>("RegistrationNumber"), new PropertyByName <Doctor>("DateOfBirth"), new PropertyByName <Doctor>("Address1"), new PropertyByName <Doctor>("Address2"), new PropertyByName <Doctor>("Hospital"), new PropertyByName <Doctor>("Pincode"), new PropertyByName <Doctor>("City"), new PropertyByName <Doctor>("State"), new PropertyByName <Doctor>("Country"), new PropertyByName <Doctor>("FaxNumber"), new PropertyByName <Doctor>("Website"), new PropertyByName <Doctor>("ConsultationFee"), new PropertyByName <Doctor>("IsAvailability") }; var manager = new PropertyManager <Doctor>(properties); //var tt = manager.GetProperty("FaxNumber").StringValue.Trim(); //var tt1 = manager.GetProperty("Hospital").StringValue.Trim(); //var tt2 = manager.GetProperty("PhoneNumber").StringValue.Trim(); //var tt3 = manager.GetProperty("Website").StringValue.Trim(); using (var xlPackage = new ExcelPackage(stream)) { // get the first worksheet in the workbook var worksheet = xlPackage.Workbook.Worksheets.FirstOrDefault(); if (worksheet == null) { throw new DptsException("No worksheet found"); } if (userId != null && iRow > 0) { var allColumnsAreEmpty = manager.GetProperties .Select(property => worksheet.Cells[iRow, property.PropertyOrderPosition]) .All(cell => cell == null || cell.Value == null || String.IsNullOrEmpty(cell.Value.ToString())); if (allColumnsAreEmpty) { throw new DptsException("column are empty"); } manager.ReadFromXlsx(worksheet, iRow); string sds = manager.GetProperty("IsAvailability").StringValue; string dsdsd = manager.GetProperty("ConsultationFee").StringValue; bool rre = bool.Parse(manager.GetProperty("IsAvailability").StringValue); decimal ds = decimal.Parse(manager.GetProperty("ConsultationFee").StringValue); #region DoctorInfo var doctor = new Doctor { DoctorId = userId, Gender = manager.GetProperty("Gender").StringValue, ShortProfile = manager.GetProperty("ShortProfile").StringValue, // Language = manager.GetProperty("Qualifications").StringValue, RegistrationNumber = manager.GetProperty("RegistrationNumber").StringValue, DateOfBirth = manager.GetProperty("DateOfBirth").StringValue, IsAvailability = bool.Parse(manager.GetProperty("IsAvailability").StringValue), ConsultationFee = decimal.Parse(manager.GetProperty("ConsultationFee").StringValue) }; _doctorService.AddDoctor(doctor); #endregion #region Specialities if (!string.IsNullOrWhiteSpace(manager.GetProperty("Speciality").StringValue) && !string.IsNullOrWhiteSpace(doctor.DoctorId)) { var specilities = manager.GetProperty("Speciality").StringValue.Trim(); foreach (var item in specilities.Split(',').ToList()) { var spec = _specialityService.GetAllSpeciality(false).Where(s => s.Title.Contains(item)).FirstOrDefault(); if (spec != null) { var sp = new SpecialityMapping { Speciality_Id = spec.Id, Doctor_Id = doctor.DoctorId, DateCreated = DateTime.UtcNow, DateUpdated = DateTime.UtcNow }; if (!_specialityService.IsDoctorSpecialityExists(sp)) { _specialityService.AddSpecialityByDoctor(sp); } } } //foreach (var specilityMap in specilities.Split(',').ToList().Select(item => new SpecialityMapping //{ // Speciality_Id = // Doctor_Id = doctor.DoctorId, // DateCreated = DateTime.UtcNow, // DateUpdated = DateTime.UtcNow //}).Where(specilityMap => !_specialityService.IsDoctorSpecialityExists(specilityMap))) //{ // _specialityService.AddSpecialityByDoctor(specilityMap); //} } #endregion #region Address if (!string.IsNullOrWhiteSpace(doctor.DoctorId) && !string.IsNullOrWhiteSpace(manager.GetProperty("Pincode").StringValue) && !string.IsNullOrWhiteSpace(manager.GetProperty("Address1").StringValue) && !string.IsNullOrWhiteSpace(manager.GetProperty("City").StringValue) && !string.IsNullOrWhiteSpace(manager.GetProperty("State").StringValue) && !string.IsNullOrWhiteSpace(manager.GetProperty("Country").StringValue)) { int countryId = 0; int stateId = 0; string rr1 = manager.GetProperty("Country").StringValue.Trim(); string rr2 = manager.GetProperty("Address1").StringValue.Trim(); string rr3 = manager.GetProperty("City").StringValue.Trim(); var country = _countryService.GetAllCountries().Where(c => c.Name.Contains(manager.GetProperty("Country").StringValue.Trim())).FirstOrDefault(); countryId = (country == null) ? 0 : country.Id; string rr = manager.GetProperty("State").StringValue.Trim(); var states = _stateProvinceService.GetAllStateProvince().Where(c => c.Name.Contains(rr)).FirstOrDefault(); stateId = (states == null) ? 0 : states.Id; var address = new Address { StateProvinceId = stateId, //_, CountryId = countryId, Address1 = manager.GetProperty("Address1").StringValue.Trim(), Address2 = manager.GetProperty("Address2").StringValue.Trim(), Hospital = manager.GetProperty("Hospital").StringValue.Trim(), FaxNumber = manager.GetProperty("FaxNumber").StringValue.Trim(), PhoneNumber = manager.GetProperty("PhoneNumber").StringValue.Trim(), Website = manager.GetProperty("Website").StringValue.Trim(), ZipPostalCode = manager.GetProperty("Pincode").StringValue.Trim(), City = manager.GetProperty("City").StringValue.Trim() }; string docAddress = address.Address1 + ", " + address.City + ", " + states.Name + ", " + address.ZipPostalCode; var geoCoodrinate = GetGeoCoordinate(docAddress); if (geoCoodrinate.Count == 2) { address.Latitude = geoCoodrinate[Constants.Lat]; address.Longitude = geoCoodrinate[Constants.Lng]; } else { var geoCoodrinates = GetGeoCoordinate(address.ZipPostalCode); if (geoCoodrinates.Count == 2) { address.Latitude = geoCoodrinates[Constants.Lat]; address.Longitude = geoCoodrinates[Constants.Lng]; } } _addressService.AddAddress(address); if (doctor != null) { var addrMap = new AddressMapping { AddressId = address.Id, UserId = doctor.DoctorId }; _addressService.AddAddressMapping(addrMap); } } #endregion } } }