Пример #1
0
        public IDictionary <string, ConsultantSchedule> GetConsultantScheduleWebApi(int dealerId, string clientDateTime)
        {
            var consultants = _dealerConsultantsRepository.Value.GetQuery()
                              .Where(x => x.DealerId == dealerId).ToList();

            var schedule = _dealerConsultantSchedulesRepository.Value.GetQuery()
                           .Where(x => x.DealerConsultant.DealerId == dealerId)
                           //.OrderBy(x => x.TimeFrom)
                           .ToList();

            if (!schedule.Any())
            {
                return(new Dictionary <string, ConsultantSchedule>());
            }

            var userDateTime = DateTime.Now;

            if (clientDateTime != null)
            {
                userDateTime = DateTime.Parse(clientDateTime);
            }

            var dateNow = userDateTime.Date;

            var inspectionOrders =
                _inspectionOrdersRepository.Value.GetQuery()
                .Where(x =>
                       x.DealerId == dealerId && x.ToType == OrderToTypes.Consultant &&
                       x.OrderDateTime >= dateNow)
                .ToList();

            var result = new Dictionary <string, ConsultantSchedule>();

            foreach (var consultant in consultants)
            {
                var dealerSchedule = new ConsultantSchedule();
                dealerSchedule.Name = $"{consultant.Firstname} {consultant.Surname}";
                dealerSchedule.WeekendWorkTimeFrom  = consultant.WeekendWorkTimeFrom.Value.ToString("hh\\:mm");
                dealerSchedule.WeekendWorkTimeTo    = consultant.WeekendWorkTimeTo.Value.ToString("hh\\:mm");
                dealerSchedule.WorkweekWorkTimeFrom = consultant.WorkweekWorkTimeFrom.Value.ToString("hh\\:mm");
                dealerSchedule.WorkweekWorkTimeTo   = consultant.WorkweekWorkTimeTo.Value.ToString("hh\\:mm");
                dealerSchedule.Image = !string.IsNullOrWhiteSpace(consultant.ImageName) ? _baseUrl + _dealerConsultantImgPath + consultant.ImageName
                    : _baseUrl + "/Content/Images/profile_user_flat.png";
                dealerSchedule.IsTimetableHidden = consultant.IsTimetableHidden;

                for (var date = DateTime.Today; date < DateTime.Today + 31.Days(); date += 1.Days())
                {
                    var values = schedule.Any(x => x.DealerConsultantId == consultant.Id)
                        ? schedule.Where(x => x.DealerConsultantId == consultant.Id && x.Date >= date && x.Date < date + 1.Days())
                        : new List <DealerConsultantSchedule>();

                    values = values.Where(x => x.Date > DateTime.Now.Date || x.Date == DateTime.Now.Date && x.TimeFrom >= DateTime.Now.TimeOfDay);


                    dealerSchedule.ScheduleByDate.Add(
                        date.ToString("dd.MM.yyyy"),
                        values
                        .Select(x => new ViewModels.FZ.Home.DealerSchedule
                    {
                        IntervalFrom     = x.TimeFrom.ToString("hh\\:mm"),
                        IntervalAsString = string.Format("{0:hh\\:mm} - {1:hh\\:mm}", x.TimeFrom, x.TimeTo),
                        //dont use Resharper here please
                        //dont use Resharper here please
                        //IsFree = inspectionOrders.Any()
                        //&& inspectionOrders.Any(y => y.DealerId == dealerId && y.DealerConsultantCode == consultant.Code && y.OrderDateTime == (x.Date + x.TimeFrom)) ? false : x.IsFree,
                        IsFree         = x.IsFree,
                        IsSpecialPrice = false,
                        Comment        = ""
                    })
                        .ToList()
                        );
                }

                result.Add(consultant.Id.ToString(), dealerSchedule);
            }

            return(result);
        }
Пример #2
0
        public IDictionary <string, ConsultantSchedule> GetConsultantSchedule(int dealerId, string clientDateTime)
        {
            var consultants = _dealerConsultantsRepository.Value.GetQuery()
                              .Where(x => x.DealerId == dealerId).ToList();

            var schedule = _dealerConsultantSchedulesRepository.Value.GetQuery()
                           .Where(x => x.DealerConsultant.DealerId == dealerId)
                           //.OrderBy(x => x.TimeFrom)
                           .ToList();

            if (!schedule.Any())
            {
                return(new Dictionary <string, ConsultantSchedule>());
            }

            string convertetUserDateTime;
            var    userDateTime = DateTime.Now;

            if (clientDateTime != null)
            {
                convertetUserDateTime = clientDateTime.Substring(0, clientDateTime.IndexOf("G")).Trim();
                userDateTime          = DateTime.ParseExact(convertetUserDateTime,
                                                            "ddd MMM dd yyyy HH:mm:ss",
                                                            CultureInfo.InvariantCulture);
            }

            var dateNow = userDateTime.Date;

            var inspectionOrders =
                _inspectionOrdersRepository.Value.GetQuery()
                .Where(x =>
                       x.DealerId == dealerId && x.ToType == OrderToTypes.Consultant &&
                       x.OrderDateTime >= dateNow)
                .ToList();

            var result = new Dictionary <string, ConsultantSchedule>();

            foreach (var consultant in consultants)
            {
                var dealerSchedule = new ConsultantSchedule();
                dealerSchedule.Name = $"{consultant.Firstname} {consultant.Surname}";
                dealerSchedule.WeekendWorkTimeFrom  = consultant.WeekendWorkTimeFrom.Value.ToString("hh\\:mm");
                dealerSchedule.WeekendWorkTimeTo    = consultant.WeekendWorkTimeTo.Value.ToString("hh\\:mm");
                dealerSchedule.WorkweekWorkTimeFrom = consultant.WorkweekWorkTimeFrom.Value.ToString("hh\\:mm");
                dealerSchedule.WorkweekWorkTimeTo   = consultant.WorkweekWorkTimeTo.Value.ToString("hh\\:mm");
                dealerSchedule.IsTimetableHidden    = consultant.IsTimetableHidden;
                dealerSchedule.Image = !string.IsNullOrWhiteSpace(consultant.ImageName) ? _dealerConsultantImgPath + consultant.ImageName
                    : ("/Content/Images/profile_user_flat.svg");

                for (var date = userDateTime.Date; date < userDateTime.Date + 31.Days(); date += 1.Days())
                {
                    var values = schedule.Any(x => x.DealerConsultantId == consultant.Id)
                        ? schedule.Where(x => x.DealerConsultantId == consultant.Id && x.Date >= date && x.Date < date + 1.Days())
                        : new List <DealerConsultantSchedule>();

                    values = values.Where(x => x.Date > userDateTime.Date || x.Date == userDateTime.Date && x.TimeFrom >= userDateTime.TimeOfDay);

                    var dealerOfConsultantShedule = _dealerSchedulesRepository.Value.Where(s => s.DealerId == consultant.DealerId).ToList();

                    dealerSchedule.ScheduleByDate.Add(
                        date.ToString("dd.MM.yyyy"),
                        values
                        .Select(x => new ViewModels.FZ.Home.DealerSchedule
                    {
                        IntervalFrom     = x.TimeFrom.ToString("hh\\:mm"),
                        IntervalAsString = string.Format("{0:hh\\:mm} - {1:hh\\:mm}", x.TimeFrom, x.TimeTo),
                        IsFree           = x.IsFree,
                        IsSpecialPrice   = GetSpecPriceIdent(dealerOfConsultantShedule, date, x.TimeFrom, x.TimeTo).IsSpecPrice,
                        Comment          = GetSpecPriceIdent(dealerOfConsultantShedule, date, x.TimeFrom, x.TimeTo).Comment
                    })
                        .ToList()
                        );
                }

                result.Add(consultant.Id.ToString(), dealerSchedule);
            }

            return(result);
        }