public AlbumViewModel()
        {
            albumDatabase = App.Container.Resolve <AlbumDatabase>();
            albumApi      = App.Container.Resolve <AlbumApi>();
            photoApi      = App.Container.Resolve <PhotoApi>();
            userApi       = App.Container.Resolve <UserApi>();

            GetDatabase();
        }
        public async Task ExecuteSearch()
        {
            await ShowLoadingGrid()
            .ConfigureAwait(true);

            try
            {
                var result = await PhotoApi
                             .GetLibraryPhotos()
                             .ConfigureAwait(true);

                if (result.IsError ||
                    result.Data == null)
                {
                    return;
                }

                ImagesWrapPanel.Children.Clear();

                foreach (var photo in result.Data)
                {
                    if (string.IsNullOrEmpty(photo.MediumUrl))
                    {
                        continue;
                    }
                    if (string.IsNullOrEmpty(photo.SmallUrl))
                    {
                        photo.SmallUrl = photo.MediumUrl;
                    }

                    var imageButton = new ImagePreviewButton
                    {
                        ButtonSize       = 200,
                        SmallImageSource = photo.SmallUrl,
                        ImageSource      = photo.MediumUrl,
                        Margin           = new Thickness(5)
                    };
                    imageButton.Click += ImagePreviewButton_Click;

                    ImagesWrapPanel.Children.Add(
                        imageButton);
                }

                await Task.Delay(
                    TimeSpan.FromSeconds(1))
                .ConfigureAwait(true);
            }
            finally
            {
                await HideLoadingGrid()
                .ConfigureAwait(true);
            }
        }
        public async Task ExecuteSearch()
        {
            await ShowLoadingGrid(true)
            .ConfigureAwait(true);

            var result = await PhotoApi.GetLibraryPhotos()
                         .ConfigureAwait(true);

            if (result.IsError ||
                result.Data == null)
            {
                return;
            }

            lstImages.Children.Clear();

            foreach (var photo in result.Data)
            {
                if (string.IsNullOrEmpty(photo.MediumUrl))
                {
                    continue;
                }
                if (string.IsNullOrEmpty(photo.SmallUrl))
                {
                    continue;
                }

                ImagePreviewButton previewButton = new ImagePreviewButton()
                {
                    ButtonSize        = 200,
                    ButtonPressAction = arg =>
                    {
                        Dispatcher.Invoke(() =>
                        {
                            lstImages.Children.Clear();
                        });

                        return(ViewModel.OnPicSelect(arg));
                    },
                    SmallImageSource = photo.SmallUrl,
                    ImageSource      = photo.MediumUrl
                };

                lstImages.Children.Add(previewButton);
            }

            await Task.Delay(TimeSpan.FromSeconds(1))
            .ConfigureAwait(true);

            await ShowLoadingGrid(false)
            .ConfigureAwait(true);
        }
Exemple #4
0
        public async Task <IActionResult> SaveEmployeePhoto(string id, [FromForm] PhotoApi file)
        {
            var employee = await _UnitOfWork.EmployeeRepository.GetEmployeeWithDepartmentsByIdAsync(id);

            if (employee == null)
            {
                return(BadRequest(new { message = "employee not found" }));
            }

            if (file.Photo == null)
            {
                return(BadRequest(new { message = "photo must not be null" }));
            }

            //employee already have a foto
            if (employee.PhotoFileName != null)
            {
                var existingFotoFile = Path.Combine(_Environment.WebRootPath, "images", employee.PhotoFileName);
                if (System.IO.File.Exists(existingFotoFile))
                {
                    System.IO.File.Delete(existingFotoFile);
                }
            }

            var fileName = Guid.NewGuid() + "_" + file.Photo.FileName;

            var filePath = Path.Combine(_Environment.WebRootPath, "images", fileName);

            using var stream = System.IO.File.Create(filePath);
            await file.Photo.CopyToAsync(stream);

            employee.PhotoFileName = fileName;

            _UnitOfWork.EmployeeRepository.UpdateEmployee(employee);

            await _UnitOfWork.SaveChangesAsync();

            return(Ok(employee));
        }