/// <summary> /// Load specific hospital in database /// </summary> /// <param name="hospitalId">Hospital ID</param> /// <returns></returns> public async Task <HospitalModel> LoadSpecificHospital(int hospitalId) { // Create new Hospital model to store data that returned from database HospitalModel model = new HospitalModel(); using (LinqDBDataContext data = new LinqDBDataContext()) { #region Load single hospital data model = await Task.Run(() => (from h in data.SP_LOAD_SPECIFIC_HOSPITAL(hospitalId) select new HospitalModel() { HospitalID = h.Hospital_ID, HospitalName = h.Hospital_Name, HospitalTypeID = (h.Hospital_Type != null) ? h.Hospital_Type.Value : 0, FullAddress = h.Address, WardID = (h.Ward_ID != null) ? h.Ward_ID.Value : 0, DistrictID = (h.District_ID != null) ? h.District_ID.Value : 0, CityID = (h.City_ID != null) ? h.City_ID.Value : 0, PhoneNo = h.Phone_Number, Fax = h.Fax, HospitalEmail = h.Email, Website = h.Website, OrdinaryStartTime = h.Ordinary_Start_Time.Value.Hours.ToString(Constants.Format2Digit) + h.Ordinary_Start_Time.Value.Minutes.ToString(Constants.Format2Digit) + h.OrDinary_End_Time.Value.Hours.ToString(Constants.Format2Digit) + h.OrDinary_End_Time.Value.Minutes.ToString(Constants.Format2Digit), HolidayStartTime = h.Holiday_Start_Time.Value.Hours.ToString(Constants.Format2Digit) + h.Holiday_Start_Time.Value.Minutes.ToString(Constants.Format2Digit) + h.Holiday_End_Time.Value.Hours.ToString(Constants.Format2Digit) + h.Holiday_End_Time.Value.Minutes.ToString(Constants.Format2Digit), Coordinate = h.Coordinate, FullDescription = h.Full_Description, IsAllowAppointment = (h.Is_Allow_Appointment != null) ? h.Is_Allow_Appointment.Value : false, IsActive = (h.Is_Active != null) ? h.Is_Active.Value : false, CreatedPerson = (h.Created_Person != null) ? h.Created_Person.Value : 0, CityName = h.City_Name, DistrictName = h.District_Name, WardName = h.Ward_Name }).SingleOrDefault()); #endregion #region Load photo model.PhotoList = (await Task.Run(() => (from p in data.Photos where p.Hospital_ID == model.HospitalID select p).ToList())); #endregion #region Load persons in charged model.PersonInCharged = await Task.Run(() => (from u in data.Users where u.Hospital_ID.Equals(hospitalId) select u.Email).FirstOrDefault()); #endregion #region Load list of specialities model.SelectedSpecialities = await Task.Run(() => (from hs in data.Hospital_Specialities where hs.Hospital_ID.Equals(hospitalId) select hs.Speciality_ID.ToString()).ToList()); #endregion #region Load list of services model.SelectedServices = await Task.Run(() => (from hs in data.Hospital_Services where hs.Hospital_ID.Equals(hospitalId) select hs.Service_ID.ToString()).ToList()); #endregion #region Load list of facilities model.SelectedFacilities = await Task.Run(() => (from hf in data.Hospital_Facilities where hf.Hospital_ID.Equals(hospitalId) select hf.Facility_ID.ToString()).ToList()); #endregion #region Load list of tag keywords List <string> tagKeyWords = await Task.Run(() => (from t in data.Tags join th in data.Tag_Hospitals on t.Word_ID equals th.Word_ID where th.Hospital_ID.Equals(hospitalId) select t.Word).ToList()); for (int n = 0; n < tagKeyWords.Count; n++) { if (n == (tagKeyWords.Count - 1)) { model.TagsInput += tagKeyWords[n]; } else { model.TagsInput += tagKeyWords[n] + Constants.Comma; } } #endregion #region Arrange data // Address string[] addressList = model.FullAddress.Split(Char.Parse(Constants.Comma)); string[] detailAddress = addressList[0].Split(Char.Parse(Constants.WhiteSpace)); model.LocationAddress = detailAddress[0]; for (int n = 1; n < detailAddress.Count(); n++) { model.StreetAddress += detailAddress[n] + Constants.WhiteSpace; } model.StreetAddress = model.StreetAddress.Trim(); // Phone number string[] phoneNumberList = model.PhoneNo.Split(Char.Parse(Constants.Slash)); int phoneNumberQuantity = phoneNumberList.Count(); if (phoneNumberQuantity == 2) { model.PhoneNo = phoneNumberList[0]; if (phoneNumberList[1].Contains(Constants.OpenBracket) || phoneNumberList[1].Contains(Constants.CloseBracket) || (phoneNumberList[1].Length <= 8)) { model.PhoneNo2 = phoneNumberList[1]; } else { model.PhoneNo3 = phoneNumberList[1]; } } if (phoneNumberQuantity == 3) { model.PhoneNo = phoneNumberList[0]; model.PhoneNo2 = phoneNumberList[1]; model.PhoneNo3 = phoneNumberList[2]; } #endregion } // Return HospitalModel return(model); }