Exemplo n.º 1
0
        public async Task<bool> QuickCheckIn(BeerItem beer)
        {
            var checkin = new CheckInItem
            {
                Beer = beer,
                BeerId = beer.Id,
                CheckedInBy = Client.Instance.BeerDrinkinClient.GetUserId
            };

            var locator = CrossGeolocator.Current;
            var position = await locator.GetPositionAsync();

            //Track the location of where the user consumed the beer
            if (position != null)
            {
                checkin.Longitude = position.Longitude;
                checkin.Latitude = position.Latitude;
            }

            var checkInResult = await Client.Instance.BeerDrinkinClient.CheckInBeerAsync(checkin);
            if (!checkInResult.HasError)
                return checkInResult.Result;

            UserDialogs.Instance.ShowError(checkInResult.ErrorMessage);
            return false;
        }
        void AddCheckIn()
        {
            if (!EnableCheckIn)
                return; 
            
            var checkInCellIdentifier = new NSString("checkInCell");
            var checkInCell = TableView.DequeueReusableCell(checkInCellIdentifier) as CheckInTableViewCell ?? new CheckInTableViewCell(checkInCellIdentifier);

            byte[] imageByteArray = null;

            var cameraView = Storyboard.InstantiateViewController("customCameraView") as CameraViewController;
            cameraView.PhotoTaken += (image) => { imageByteArray = image; };

            checkInCell.DidCheckIn += async () =>
            {
                var checkIn = new CheckInItem();
                checkIn.Beer = beer;
                checkIn.BeerId = beer.Id;
                checkIn.CheckedInBy = Client.Instance.BeerDrinkinClient.CurrenMobileServicetUser.UserId;
                checkIn.Rating = checkInCell.Rating;
                if(imageByteArray != null)
                    await Client.Instance.BeerDrinkinClient.UploadBinaryAsync(beer.Id, BeerDrinkin.Models.BinaryTypes.CheckIn, imageByteArray);

                await Client.Instance.BeerDrinkinClient.CheckInBeerAsync(checkIn);
                Acr.UserDialogs.UserDialogs.Instance.ShowSuccess(string.Format("Checked in {0}", beer.Name));
            };

            checkInCell.SnapPhoto += async () =>
            {
                    if(UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) == true)
                    {
                        await PresentViewControllerAsync(cameraView, false);
                        return;
                    }

                    Acr.UserDialogs.UserDialogs.Instance.ShowError("No camera found on this device");
            };

            cells.Add(checkInCell);
        }