/// <summary>
        ///     Wird aufgerufen sobald die View initialisiert wurde
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public override async Task OnActivated(object args = null)
        {
            if (args is object[] argsArr)
            {
                if (argsArr[0] is UiMeeting appointment && argsArr[1] is ExShop shop)
                {
                    Appointment = appointment;
                    _shop       = shop;
                    PageTitle   = shop.Name;
                    var response = await Sa.GetDefaultText(appointment.Meeting.Staff.Id);

                    if (response.Ok && response.Result != null && !string.IsNullOrWhiteSpace(response.Result.PlaceholderText))
                    {
                        Placeholder = response.Result.PlaceholderText;
                    }
                    else
                    {
                        Placeholder = ResViewAppointmentInfo.LblShopAdditionalInfo;
                    }
                }
            }
            else
            {
                await Nav.Back();
            }
        }
Example #2
0
        public UiExShopData(ExShop shop)
        {
            Shop = shop;

            try
            {
                if (string.IsNullOrWhiteSpace(Shop.ImageUrl))
                {
                    ImageSource = ImageSource.FromStream(() => Images.ReadImageAsStream(EmbeddedImages.Logo_png));
                }
                else
                {
                    //if (Device.RuntimePlatform == Device.iOS)
                    //{
                    //    var client = new WebClient();
                    //    var bytes = client.DownloadData(_shop.ImageUrl);
                    //    ImageSource = ImageSource.FromStream(() => new MemoryStream(bytes));
                    //    client.Dispose();
                    //}
                    //else
                    ImageSource = ImageSource.FromUri(new Uri(Shop.ImageUrl));
                }
            }
            catch (Exception e)
            {
                ImageSource = ImageSource.FromStream(() => Images.ReadImageAsStream(EmbeddedImages.Logo_png));
            }

            try
            {
                var sorted = Shop.OpeningHours.OrderByDescending(s => s.Day.DayOfWeek).Reverse().ToList();
                var sunday = sorted.FirstOrDefault();
                sorted.Remove(sunday);
                sorted.Add(sunday);
                Shop.OpeningHours = sorted;
            }
            catch (Exception e)
            {
                Logging.Log.LogError(e.Message);
            }
        }
        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);
            }
        }