Ejemplo n.º 1
0
        /// <summary>
        /// Update specific hospital
        /// </summary>
        /// <param name="model">Hospital model</param>
        /// <returns></returns>
        public async Task <int> UpdateHospitalAsync(HospitalModel model)
        {
            int result = 0;

            #region Prepare data

            // Full address
            model.FullAddress = string.Format("{0} {1}, {2}, {3}, {4}",
                                              model.LocationAddress, model.StreetAddress, model.WardName,
                                              model.DistrictName, model.CityName);

            // Phone number
            string phoneNumber = model.PhoneNo;
            if (!string.IsNullOrEmpty(model.PhoneNo2))
            {
                phoneNumber += Constants.Slash + model.PhoneNo2;
            }
            if (!string.IsNullOrEmpty(model.PhoneNo3))
            {
                phoneNumber += Constants.Slash + model.PhoneNo3;
            }
            model.PhoneNo = phoneNumber;

            // Holiday time
            string[] holidayTime      = model.HolidayStartTime.Split(char.Parse(Constants.Minus));
            string   holidayStartTime = holidayTime[0].Trim();
            model.HolidayStartTime = holidayStartTime;
            string holidayEndTime = holidayTime[1].Trim();
            model.HolidayEndTime = holidayEndTime;

            // Ordinary time
            string[] OrdinaryTime      = model.OrdinaryStartTime.Split(char.Parse(Constants.Minus));
            string   ordinaryStartTime = OrdinaryTime[0].Trim();
            model.OrdinaryStartTime = ordinaryStartTime;
            string ordinaryEndTime = OrdinaryTime[1].Trim();
            model.OrdinaryEndTime = ordinaryEndTime;

            // Speciality list
            string speciality = string.Empty;
            if ((model.SelectedSpecialities != null) && (model.SelectedSpecialities.Count != 0))
            {
                for (int n = 0; n < model.SelectedSpecialities.Count; n++)
                {
                    if (n == (model.SelectedSpecialities.Count - 1))
                    {
                        speciality += model.SelectedSpecialities[n];
                    }
                    else
                    {
                        speciality += model.SelectedSpecialities[n] +
                                      Constants.VerticalBar.ToString();
                    }
                }
            }

            // Service list
            string service = string.Empty;
            if ((model.SelectedServices != null) && (model.SelectedServices.Count != 0))
            {
                for (int n = 0; n < model.SelectedServices.Count; n++)
                {
                    if (n == (model.SelectedServices.Count - 1))
                    {
                        service += model.SelectedServices[n];
                    }
                    else
                    {
                        service += model.SelectedServices[n] +
                                   Constants.VerticalBar.ToString();
                    }
                }
            }

            // Facility list
            string facility = string.Empty;
            if ((model.SelectedFacilities != null) && (model.SelectedFacilities.Count != 0))
            {
                for (int n = 0; n < model.SelectedFacilities.Count; n++)
                {
                    if (n == (model.SelectedFacilities.Count - 1))
                    {
                        facility += model.SelectedFacilities[n];
                    }
                    else
                    {
                        facility += model.SelectedFacilities[n] +
                                    Constants.VerticalBar.ToString();
                    }
                }
            }

            #endregion

            // Return list of dictionary words
            using (LinqDBDataContext data = new LinqDBDataContext())
            {
                result = await Task.Run(() => data.SP_UPDATE_HOSPITAL(model.HospitalID, model.HospitalName,
                                                                      model.HospitalTypeID, model.FullAddress, model.CityID, model.DistrictID,
                                                                      model.WardID, model.PhoneNo, model.Fax, model.HospitalEmail, model.Website,
                                                                      model.HolidayStartTime, model.HolidayEndTime, model.OrdinaryStartTime,
                                                                      model.OrdinaryEndTime, model.Coordinate, model.IsAllowAppointment, model.CreatedPerson,
                                                                      model.FullDescription, speciality, service, facility, model.TagsInput,
                                                                      model.PhotoFilesPath));
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <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);
        }