Пример #1
0
        public async Task <IActionResult> GetUserTurns([FromBody] UserTurnsFilterDTO filterModel, int pageIndex, int limit = 12)
        {
            if (string.IsNullOrEmpty(CurrentUserName))
            {
                return(Unauthorized());
            }

            filterModel.UserMobile = CurrentUserName;

            var(totalCount, _, doctors) = await _turnsService.GetUserTurnsListPagingAsync(filterModel, RequestLang, HostAddress, pageIndex, limit);

            var result = new UserTurnsResultDTO
            {
                TotalCount = totalCount,
                Turns      = doctors
            };

            return(Ok(result));
        }
Пример #2
0
        public async Task <(long totalCount, int totalPages, List <UserTurnItemDTO>)> GetUserTurnsListPagingAsync(UserTurnsFilterDTO filterModel, Lang lang, string hostAddress, int page = 0, int pageSize = 12)
        {
            if (filterModel == null || string.IsNullOrEmpty(filterModel.UserMobile))
            {
                return(0, 0, new List <UserTurnItemDTO>());
            }

            var person = await _userService.GetPersonByMobileAsync(filterModel.UserMobile);

            if (person == null)
            {
                return(0, 0, new List <UserTurnItemDTO>());
            }

            var query = _appointmentService.Table.IgnoreQueryFilters().Where(x => x.PersonId == person.Id);

            if (!string.IsNullOrEmpty(filterModel.FilterString))
            {
                query = query.Where(x => (Global.Doctor + " " + x.ServiceSupply.Person.FullName + " " + x.ServiceSupply.Person.FullName_Ar + " " + x.ServiceSupply.Person.FullName_Ku).Contains(filterModel.FilterString));
            }

            if (filterModel.Status != null)
            {
                query = query.Where(x => x.Status == filterModel.Status || (filterModel.Status == AppointmentStatus.Pending && x.Status == AppointmentStatus.Unknown && x.Description.Contains("#Requested")));
            }

            if (filterModel.From != null)
            {
                query = query.Where(x => x.Start_DateTime >= filterModel.From);
            }

            if (filterModel.To != null)
            {
                query = query.Where(x => x.Start_DateTime <= filterModel.To);
            }

            if (filterModel.CenterType != null)
            {
                query = query.Where(x => x.ServiceSupply.ShiftCenter.Type == filterModel.CenterType);
            }

            var totalCount = await query.LongCountAsync();

            var totalPages = (int)Math.Ceiling((double)totalCount / pageSize);

            var turns = await query.OrderBy(x => x.Start_DateTime).Skip(pageSize * page).Take(pageSize).Select(x => new UserTurnItemDTO
            {
                Id = x.Id,
                ServiceSupplyId = x.ServiceSupplyId,
                Date            = x.Start_DateTime.ToShortDateString(),
                StartTime       = x.Start_DateTime.ToShortTimeString(),
                EndTime         = x.End_DateTime.ToShortTimeString(),
                Status          = x.Status,
                DoctorName      = lang == Lang.KU ? x.ServiceSupply.Person.FullName_Ku : lang == Lang.AR ? x.ServiceSupply.Person.FullName_Ar :  x.ServiceSupply.Person.FullName,
                DoctorAvatar    = x.ServiceSupply.Person.RealAvatar,
                DayOfWeek       = Utils.ConvertDayOfWeek(x.Start_DateTime.DayOfWeek.ToString()),
                IsRated         = x.Rate != null,
                AverageRating   = (x.Rate != null) ? x.Rate.Rating : 5,
                TrackingCode    = x.UniqueTrackingCode,
                CenterServiceId = x.ShiftCenterServiceId,
                Service         = lang == Lang.KU ? x.ShiftCenterService.Service.Name_Ku : lang == Lang.AR ? x.ShiftCenterService.Service.Name_Ar : x.ShiftCenterService.Service.Name
            }).ToListAsync();

            foreach (var item in turns)
            {
                var x = await _serviceSupplyService.GetServiceSupplyByIdAsync(item.ServiceSupplyId);

                if (x != null)
                {
                    var firstExpertise = x?.DoctorExpertises.FirstOrDefault();

                    item.DoctorExpertiseCategory = firstExpertise != null ? lang == Lang.AR ? firstExpertise.Expertise.ExpertiseCategory.Name_Ar : lang == Lang.KU ? firstExpertise.Expertise.ExpertiseCategory.Name_Ku : firstExpertise.Expertise.ExpertiseCategory.Name : "";
                }
            }

            return(totalCount, totalPages, turns);
        }