예제 #1
0
        private async void OnVisitAdded(Visit visit)
        {
            await dispatcherService.InvokeUI(() =>
            {
                bool isNext = NextVisit == null || visit.VisitDateTime < NextVisit.VisitDate;

                bool isToday         = visit.VisitDateTime.ToLocalTime().Date == DateTime.Now.Date;
                var list             = isToday ? TodayVisits : OtherVisits;
                var maxNumberOfItems = isToday ? ITEMS_TO_RETRIEVE_TODAY : ITEMS_TO_RETRIEVE_OTHER;
                int visitGroup       = isToday ? TODAY_GROUP_ID : OTHER_GROUP_ID;
                var visitItem        = new VisitItem(visit, visitGroup);

                var previousVisit = list.LastOrDefault(v =>
                {
                    return(v.VisitDate < visitItem.VisitDate);
                });

                int visitIndex = previousVisit == null ? 0 : list.IndexOf(previousVisit) + 1;

                bool hasToBeAdded     = visitIndex <= list.Count;
                bool needToRemoveLast = list.Count() == maxNumberOfItems;

                if (isNext)
                {
                    NextVisit = visitItem;
                }

                if (hasToBeAdded)
                {
                    list.Insert(visitIndex, visitItem);
                }

                if (needToRemoveLast)
                {
                    list.Remove(list.Last());
                }

                if (isToday)
                {
                    ShowTodayVisits = true;
                    TodayVisitsCount++;
                }
                else
                {
                    ShowOtherVisits = true;
                    OtherVisitsCount++;
                }

                this.RaisePropertyChanged(() => ShowNextVisit);
            });
        }
        private async void AddPicture(PictureType pictureType)
        {
            VisitorPicture picture = null;

            // If picture type is big, creates a new Visitor Picture using the image to crop attribute.
            if ((pictureType == PictureType.Big) && (this.imageToCrop != null))
            {
                this.visitorPictures = new Collection <VisitorPicture>()
                {
                };

                picture = new VisitorPicture
                {
                    Content     = await storageService.FileToByte(this.imageToCrop),
                    PictureType = pictureType
                };

                this.visitorPictures.Add(picture);
            }


            // If picture type is small, creates a new Visitor Picture using the image croppped attribute.
            else if ((pictureType == PictureType.Small) && ((this.imageCropped != null)))
            {
                await dispatcherService.InvokeUI(async() =>
                {
                    picture = new VisitorPicture
                    {
                        Content     = await storageService.FileToByte(this.imageCropped),
                        PictureType = pictureType
                    };
                    this.visitorPictures.Add(picture);
                    IsBusy = true;


                    var newVisitorPictures = this.visitorPictures.ToList();

                    foreach (var visitorPicture in newVisitorPictures)
                    {
                        visitorPicture.VisitorId = visitItem.VisitorId;
                    }

                    await this.clientService.VisitorPictureService.AddOrUpdatePictures(visitorPictures);

                    var message = new VisitorPicturesChanged(this.visitorPictures);
                    this.MessengerInstance.Send <VisitorPicturesChanged>(message);

                    this.Visit.ChangePhotos(this.visitorPictures);
                    base.RaisePropertyChanged(() => Visit);
                    IsBusy = false;
                });
            }
        }