Exemplo n.º 1
0
        public HttpResponseMessage searchDoctorwithFav(SearchDoctorModel searchModel)
        {
            string   timingsFrom    = null;
            string   timingsTo      = null;
            TimeSpan?appFromtimings = null;
            TimeSpan?appTotimings   = null;

            if (searchModel.language == "")
            {
                searchModel.language = null;
            }
            if (searchModel.speciality == "")
            {
                searchModel.speciality = null;
            }
            if (searchModel.name == "")
            {
                searchModel.name = null;
            }
            if (searchModel.appDate == "")
            {
                searchModel.appDate = null;
            }
            if (searchModel.appTime == "")
            {
                searchModel.appTime = null;
            }
            if (searchModel.gender == "")
            {
                searchModel.gender = null;
            }



            try
            {
                if (searchModel.appTime != null)
                {
                    List <string> timeframe = searchModel.appTime.Split(':').ToList <string>();
                    var           j         = 0;
                    foreach (var item in timeframe)
                    {
                        if (j == 0)
                        {
                            //timingsFrom = item;
                            if (item.Length == 1)
                            {
                                timingsFrom = "0" + item;
                            }
                            else
                            {
                                timingsFrom = item;
                            }
                            j++;
                            continue;
                        }
                        if (j == 1)
                        {
                            if (item.Length == 1)
                            {
                                timingsTo = "0" + item;
                            }
                            else
                            {
                                timingsTo = item;
                            }
                        }
                    }
                    DateTime dateTimeFrom = DateTime.ParseExact(timingsFrom + ":00",
                                                                "HH:mm", CultureInfo.InvariantCulture);
                    DateTime dateTimeTo = DateTime.ParseExact(timingsTo + ":00",
                                                              "HH:mm", CultureInfo.InvariantCulture);

                    appFromtimings = dateTimeFrom.TimeOfDay;
                    appTotimings   = dateTimeTo.TimeOfDay;
                }
                if (searchModel.appDate == null)
                {
                    var result = (from l in db.SearchDoctorWithShift(searchModel.language, searchModel.speciality, searchModel.name, null,
                                                                     appFromtimings, appTotimings, searchModel.gender)
                                  select new SearchDoctorWithShift_Model {
                        doctorID = l.doctorID, title = l.title,
                        firstName = l.firstName,
                        lastName = l.lastName,
                        city = l.city,
                        ProfilePhotoBase64 = l.ProfilePhotoBase64,
                        state = l.state,
                        languageName = l.languageName,
                        specialityName = l.specialityName,
                        reviewStar = l.reviewStar
                    }
                                  ).ToList();
                    var favdoc = (from l in db.FavouriteDoctors
                                  where l.patientID == searchModel.patientID && l.active == true
                                  select new FavouriteDoctorModel {
                        docID = l.doctorID, patID = l.patientID
                    }).ToList();
                    SearchDoctorResult searchResult = new SearchDoctorResult();
                    searchResult.doctor    = result;
                    searchResult.favdoctor = favdoc;

                    response = Request.CreateResponse(HttpStatusCode.OK, searchResult);
                }

                if (searchModel.appDate != null)
                {
                    try
                    {
                        string      dateString = searchModel.appDate.Trim();
                        string      format     = "dd/MM/yyyy";
                        CultureInfo provider   = CultureInfo.InvariantCulture;

                        DateTime day    = DateTime.ParseExact(dateString, format, provider);
                        var      result = (from l in db.SearchDoctorWithShift(searchModel.language, searchModel.speciality, searchModel.name, day.DayOfWeek.ToString(),
                                                                              appFromtimings, appTotimings, searchModel.gender)
                                           select new SearchDoctorWithShift_Model
                        {
                            doctorID = l.doctorID,
                            title = l.title,
                            firstName = l.firstName,
                            lastName = l.lastName,
                            city = l.city,
                            ProfilePhotoBase64 = "",
                            state = l.state,
                            languageName = l.languageName,
                            specialityName = l.specialityName,
                            reviewStar = l.reviewStar
                        }
                                           ).ToList();
                        var favdoc = (from l in db.FavouriteDoctors
                                      where l.patientID == searchModel.patientID && l.active == true
                                      select new FavouriteDoctorModel {
                            docID = l.doctorID, patID = l.patientID
                        }).ToList();
                        SearchDoctorResult searchResult = new SearchDoctorResult();
                        searchResult.doctor    = result;
                        searchResult.favdoctor = favdoc;

                        response = Request.CreateResponse(HttpStatusCode.OK, searchResult);
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("{0} is not in the correct format.", searchModel.appDate.Trim());
                    }
                }
                return(response);
            }
            catch (Exception ex)
            {
                return(ThrowError(ex, "searchDoctorwithFav in SeacrhDoctorController."));
            }
        }