Пример #1
0
        public async Task <List <ExMeeting> > GetMeetingsForDate([FromBody] ExGetMeetingsForDateRequest request)
        {
            if (!request.LocationId.HasValue)
            {
                return(new List <ExMeeting>());
            }

            var res = MeetingSlots.GetSlots(request.LocationId.Value, request.Date);

            if (!request.ShowTakenSlots)
            {
                // Nur freie Termine
                res = res.Where(x => x.Id < 0).ToList();
            }

            return(res.OrderBy(x => x.Start).ToList());
        }
Пример #2
0
        public async Task <ExShop> GetShopInfo(int locationId)
        {
            var sw = new Stopwatch();

            sw.Start();

            using (var db = new Db())
            {
                Logging.Log.LogWarning("create db context " + sw.Elapsed);
                sw.Reset();
                sw.Start();

                var location = db.TblLocations
                               .Include(x => x.Store)
                               .Include(x => x.Store).ThenInclude(x => x.TblStoreCategories)
                               .Include(x => x.Store).ThenInclude(x => x.TblStoreCategories).ThenInclude(x => x.TblProductCategory)
                               .Include(x => x.Store).ThenInclude(x => x.TblStoreDelivery)
                               .Include(x => x.Store).ThenInclude(x => x.TblStoreDelivery).ThenInclude(x => x.TblDeliveryOption)
                               .Include(x => x.Store).ThenInclude(x => x.TblStorePayments)
                               .Include(x => x.Store).ThenInclude(x => x.TblStorePayments).ThenInclude(x => x.TblPaymentOption)
                               .Include(x => x.Store).ThenInclude(x => x.OpeningHours)
                               .Include(x => x.Store).ThenInclude(x => x.SpecialDays)
                               .Include(x => x.Store).ThenInclude(x => x.Absences)
                               .Include(x => x.TblLocationEmployee)
                               .Include(x => x.TblLocationEmployee).ThenInclude(x => x.TblEmployee)
                               .Include(x => x.TblLocationEmployee).ThenInclude(x => x.TblEmployee).ThenInclude(x => x.TblVirtualWorkTimes)
                               .AsNoTracking()
                               .FirstOrDefault(x => x.Id == locationId);

                if (location == null)
                {
                    return(null);
                }

                Logging.Log.LogWarning("linq " + sw.Elapsed);
                sw.Reset();
                sw.Start();

                var res = new ExShop
                {
                    Id           = location.Id,
                    Name         = location.Store.CompanyName,
                    Position     = new BissPosition(location.Latitude, location.Longitude),
                    MainCategory = location.Store.TblStoreCategories.FirstOrDefault(x => x.IsMainStoreCategory) != null
                                  ? new ExCategory
                    {
                        Id    = location.Store.TblStoreCategories.FirstOrDefault(x => x.IsMainStoreCategory).TblProductCategory.Id,
                        Name  = location.Store.TblStoreCategories.FirstOrDefault(x => x.IsMainStoreCategory).TblProductCategory.Description,
                        Glyph = location.Store.TblStoreCategories.FirstOrDefault(x => x.IsMainStoreCategory).TblProductCategory.Icon,
                    }
                                  : location.Store.TblStoreCategories?.FirstOrDefault() != null
                                      ? new ExCategory
                    {
                        Id    = location.Store.TblStoreCategories.FirstOrDefault().TblProductCategory.Id,
                        Name  = location.Store.TblStoreCategories.FirstOrDefault().TblProductCategory.Description,
                        Glyph = location.Store.TblStoreCategories.FirstOrDefault().TblProductCategory.Icon,
                    }
                                      : null,
                    Categories = location.Store.TblStoreCategories != null
                                  ? location.Store.TblStoreCategories.Select(x => new ExCategory
                    {
                        Id    = x.TblProductCategory.Id,
                        Name  = x.TblProductCategory.Description,
                        Glyph = x.TblProductCategory.Icon,
                    }).ToList()
                                  : new List <ExCategory>(),
                    DeliveryMethods = location.Store.TblStoreDelivery != null
                                  ? location.Store.TblStoreDelivery.Select(x => new ExDeliveryMethod
                    {
                        Id    = x.TblDeliveryOption.Id,
                        Name  = x.TblDeliveryOption.Description,
                        Glyph = x.TblDeliveryOption.Icon,
                    }).ToList()
                                  : new List <ExDeliveryMethod>(),
                    PaymentMethods = location.Store.TblStorePayments != null
                                  ? location.Store.TblStorePayments.Select(x => new ExPaymentMethod
                    {
                        Id    = x.TblPaymentOption.Id,
                        Name  = x.TblPaymentOption.Description,
                        Glyph = x.TblPaymentOption.Icon,
                    }).ToList()
                                  : new List <ExPaymentMethod>(),

                    PhoneNumber  = location.Telephonenumber,
                    WebLink      = location.Store.Website,
                    LocationName = location.Name,
                    Address      = location.Address,
                    PostCode     = location.PostCode,
                    City         = location.City,
                    FederalState = location.FederalState,
                    Country      = location.Country,
                    Employees    = location.TblLocationEmployee != null
                                  ? location.TblLocationEmployee.Select(x => Staff.GetExStaff(x.TblEmployee)).ToList()
                                  : new List <ExStaff>(),
                    Description = location.Store.Description,
                    ImageUrl    = Constants.ServiceClientEndPointWithApiPrefix + nameof(GetStoreImage) + "/" + location.StoreId,
                };

                Logging.Log.LogWarning("stammdaten " + sw.Elapsed);

                #region Öffnungszeiten

                var openingHours = new List <ExOpeningHour>();

                for (var i = 0; i < 7; i++)
                {
                    var checkDate = DateTime.UtcNow.Date.AddDays(i);

                    var opening = location.Store.OpeningHours.FirstOrDefault(x => x.Weekday == checkDate.DayOfWeek);

                    var specialDay = location.Store.SpecialDays.FirstOrDefault(x => x.Date == checkDate);

                    var abscence = location.Store.Absences.FirstOrDefault(x => x.Date == checkDate);

                    openingHours.Add(new ExOpeningHour
                    {
                        Day           = checkDate,
                        TimeFrom      = abscence != null || opening?.TimeFrom == null ? (DateTime?)null : DateTime.SpecifyKind(opening.TimeFrom.Value, DateTimeKind.Utc),
                        TimeTo        = abscence != null || opening?.TimeTo == null ? (DateTime?)null : DateTime.SpecifyKind(opening.TimeTo.Value, DateTimeKind.Utc),
                        IsAbscenceDay = abscence != null,
                        IsSpecialDay  = specialDay != null,
                    });
                }

                res.OpeningHours = openingHours;

                #endregion

                Logging.Log.LogWarning("+Öffnungszeiten " + sw.Elapsed);

                #region Mitarbeiterslots heute

                var slots = MeetingSlots.GetSlots(db, location.Id, DateTime.UtcNow);

                res.FreeSlots = slots.Where(x => x.Id < 0).ToList();

                #endregion

                Logging.Log.LogWarning("+Slots " + sw.Elapsed);

                #region Ist geöffnet

                if (openingHours.FirstOrDefault().IsAbscenceDay)
                {
                    res.IsOpen = false;
                }
                else if (openingHours.FirstOrDefault().IsSpecialDay)
                {
                    res.IsOpen = true;
                }
                else if (openingHours.FirstOrDefault().TimeFrom == null)
                {
                    res.IsOpen = false;
                }
                else
                {
                    var openeningHours = openingHours.FirstOrDefault();

                    var currentTime = new DateTime(1, 1, 2, DateTime.UtcNow.Hour, DateTime.UtcNow.Minute, DateTime.UtcNow.Second);

                    var timeFrom = new DateTime(1, 1, (openeningHours.TimeFrom?.Date < openeningHours.TimeTo?.Date ? 1 : 2), openeningHours?.TimeFrom?.Hour ?? 0, openeningHours?.TimeFrom?.Minute ?? 0, openeningHours?.TimeFrom?.Second ?? 0);
                    var timeTo   = new DateTime(1, 1, 2, openeningHours?.TimeTo?.Hour ?? 23, openeningHours?.TimeTo?.Minute ?? 59, openeningHours?.TimeTo?.Second ?? 59);

                    var shopIsOpenNow = openeningHours == null || (currentTime >= timeFrom && currentTime <= timeTo);

                    res.IsOpen = shopIsOpenNow;

                    // Shop ist generell offen - verfügbarkeit checken
                    if (res.IsOpen)
                    {
                        foreach (var locationEmployee in location.TblLocationEmployee)
                        {
                            var workTimeToday = locationEmployee.TblEmployee.TblVirtualWorkTimes.FirstOrDefault(x => x.Weekday == DateTime.UtcNow.Date.DayOfWeek);

                            if (workTimeToday == null)
                            {
                                continue;
                            }

                            var meetings = db.TblAppointments.AsNoTracking()
                                           .Where(x => x.EmployeeId == locationEmployee.Id && x.ValidTo >= currentTime && x.ValidFrom <= currentTime && !x.Canceled);

                            var meeting = meetings.FirstOrDefault();

                            if (meeting == null)
                            {
                                res.IsFree = true;
                                break;
                            }
                        }
                    }
                }

                #endregion

                Logging.Log.LogWarning("+isOpen " + sw.Elapsed);

                // TODO nexten Timeslot suchen und angeben ob frei oder besetzt
                res.NextSlot       = DateTime.SpecifyKind(res.FreeSlots.FirstOrDefault()?.Start ?? DateTime.UtcNow.AddYears(1), DateTimeKind.Utc);
                res.WhatsappNumber = res.FreeSlots.FirstOrDefault()?.Staff?.WhatsappContact ??
                                     location.TblLocationEmployee?.FirstOrDefault()?.TblEmployee?.TelephoneNumber;

                Logging.Log.LogWarning("Finished " + sw.Elapsed);
                sw.Stop();

                return(res);
            }
        }