public async Task <ActionResult> Create(PhotoAlbumViewModel model)
        {
            string access_token = Session["access_token"]?.ToString();

            if (string.IsNullOrEmpty(access_token))
            {
                return(RedirectToAction("Login", "Account", null));
            }

            if (ModelState.IsValid)
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://localhost:24260/");
                    client.DefaultRequestHeaders.Accept.Clear();

                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", $"(access_token");

                    var response = await client.PostAsJsonAsync("/api/PhotoAlbums", model);

                    if (response.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index", "PhotoAlbum"));
                    }
                    else
                    {
                        return(View("Error"));
                    }
                }
            }

            return(View());
        }
        public ActionResult Delete(int id, PhotoAlbumViewModel model)
        {
            string access_token = Session["access_token"]?.ToString();

            if (string.IsNullOrEmpty(access_token))
            {
                return(RedirectToAction("Login", "Account", null));
            }

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:24260/");

                var deleteTask = client.DeleteAsync("/api/PhotoAlbums/" + id.ToString());
                deleteTask.Wait();

                var result = deleteTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("Error"));
                }
            }
        }
        // GET: PhotoAlbum/Details/5
        public ActionResult Details(int id)
        {
            PhotoAlbumViewModel album = null;
            string access_token       = Session["access_token"]?.ToString();

            if (!string.IsNullOrEmpty(access_token))
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://localhost:24260");
                    client.DefaultRequestHeaders.Accept.Clear();

                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", $"(access_token");

                    var responseTask = client.GetAsync("/api/PhotoAlbums/" + id);
                    responseTask.Wait();

                    var result = responseTask.Result;

                    if (result.IsSuccessStatusCode)
                    {
                        var readTask = result.Content.ReadAsAsync <PhotoAlbumViewModel>();
                        readTask.Wait();
                        album = readTask.Result;

                        return(View(album));
                    }

                    return(View("Error"));
                }
            }

            return(RedirectToAction("Login", "Account", null));
        }
        public ActionResult Edit(int id, PhotoAlbumViewModel model)
        {
            string access_token = Session["access_token"]?.ToString();

            if (string.IsNullOrEmpty(access_token))
            {
                return(RedirectToAction("Login", "Account", null));
            }

            PhotoAlbumViewModel album = new PhotoAlbumViewModel()
            {
                PhotoAlbumId = id,
                AlbumName    = model.AlbumName,
                Description  = model.Description
            };

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:24260");

                var putTask = client.PutAsJsonAsync <PhotoAlbumViewModel>($"api/PhotoAlbums/{id}", album);
                putTask.Wait();

                var result = putTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("Error"));
                }
            }
        }
        /*********Photo Album**************/

        public PhotoAlbumViewModel Get_PhotoAlbum_Images(int?page, Controller ctrl)
        {
            PhotoAlbumViewModel vm = new PhotoAlbumViewModel();

            int current_page = page.HasValue ? page.Value : 1;

            ctrl.TempData["page"] = current_page;

            List <string> str_images = DataLayer.get_photoAlbum_images();

            for (int i = 0; i < str_images.Count; i++)
            {
                str_images[i] = ("PhotoAlbum/" + str_images[i]);
            }

            IPagedList <string> paged_list_images = null;

            if (str_images != null)
            {
                paged_list_images = str_images.ToPagedList(current_page, pagesize_image);
            }

            vm.photos = paged_list_images;
            vm.page   = current_page;

            return(vm);
        }
Beispiel #6
0
        // GET: PhotoAlbum
        public ActionResult Index()
        {
            PhotoAlbumViewModel photoAlbumViewModel = new PhotoAlbumViewModel();

            photoAlbumViewModel.Albums = _apiClient.GetAlbums();
            return(View(photoAlbumViewModel));
        }
        public async Task <ActionResult> Create(PhotoAlbumViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var files = Request.Files;

            if (files == null || files.Count <= 0)
            {
                ModelState.AddModelError("", "Chưa cung cấp hình ảnh cho album");
                return(View(model));
            }
            var existed = await _db.PhotoAlbums.AnyAsync(x => x.AlbumName.Equals(model.AlbumName));

            if (existed)
            {
                ModelState.AddModelError("", "Tên album đã có, hãy đặt tên khác");
                return(View(model));
            }
            var id    = Guid.NewGuid();
            var album = new PhotoAlbum
            {
                Id          = id,
                AlbumName   = model.AlbumName,
                Activated   = model.Activated,
                CreatedTime = DateTime.Now
            };

            _db.PhotoAlbums.Add(album);
            await _db.SaveChangesAsync();

            var uploadPath = Server.MapPath($"{Folder}/{id}");

            if (!Directory.Exists(uploadPath))
            {
                Directory.CreateDirectory(uploadPath);
            }
            for (var i = 0; i < files.Count; i++)
            {
                var fileInfo = new FileInfo(files[i].FileName);
                if (fileInfo.Extension.ToLower().Equals(".jpeg") ||
                    fileInfo.Extension.ToLower().Equals(".jpg") ||
                    fileInfo.Extension.ToLower().Equals(".png") ||
                    fileInfo.Extension.ToLower().Equals(".bmp") ||
                    fileInfo.Extension.ToLower().Equals("gif"))
                {
                    var name     = $"{DateTime.Now:yyyyMMddHHmmssfff}";
                    var fileName = $"{name}{fileInfo.Extension}";
                    files[i].SaveAs($"{uploadPath}/{fileName}");
                }
            }
            return(RedirectToAction("Index"));
        }
        // GET: Admin/PhotoGaller
        public ActionResult Index(int?page)
        {
            PhotoAlbumViewModel vm = NegahenoService.Get_PhotoAlbum_Images(page, this);

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_PartialAlbumList", vm.photos));
            }
            else
            {
                return(View(vm));
            }
        }
        public async Task <IActionResult> List(int id, string returnUrl)
        {
            var repo   = new JsonplaceholderRepository();
            var photos = await _service.GetPhotosByAlbumIdAsync(id);

            var album = await _service.GetAlbumByIdAsync(id);

            var result = new PhotoAlbumViewModel()
            {
                Photos = photos.Select(t => new PhotoViewModel()
                {
                    ThumbnailUrl = t.ThumbnailUrl,
                    Title        = t.Title
                }),
                AlbumTitle = album?.Title,
                ReturnUrl  = returnUrl
            };

            return(View(result));
        }
Beispiel #10
0
        public ActionResult Images(string userId)
        {
            if (userId.IsNullOrWhiteSpace())
            {
                return(View("Error"));
            }

            var userService   = new UserService(DbContext);
            var profilePhotos = userService.GetAllProfilePhotosFromUser(userId);
            var coverPhotos   = userService.GetAllCoverPhotosFromUser(userId);

            // Filling the view model
            var model = new PhotoAlbumViewModel
            {
                ProfilePhotos = new List <PhotoViewModel>(),
                CoverPhotos   = new List <PhotoViewModel>(),
                UserId        = userId
            };

            foreach (var item in profilePhotos)
            {
                model.ProfilePhotos.Add(new PhotoViewModel()
                {
                    PhotoPath = item.PhotoPath,
                    PhotoId   = item.PhotoId
                });
            }

            foreach (var item in coverPhotos)
            {
                model.CoverPhotos.Add(new PhotoViewModel()
                {
                    PhotoPath = item.PhotoPath,
                    PhotoId   = item.PhotoId
                });
            }

            return(View(model));
        }
Beispiel #11
0
        protected override void HandleOnNavigatedTo(NavigationEventArgs e)
        {
            base.HandleOnNavigatedTo(e);
            PhotosToMoveInfo photosToMove         = ParametersRepository.GetParameterForIdAndReset("PhotosToMove") as PhotosToMoveInfo;
            bool             needRefreshAfterMove = false;

            if (!this._isInitialized)
            {
                PhotoAlbumViewModel.PhotoAlbumViewModelInput inputData = new PhotoAlbumViewModel.PhotoAlbumViewModelInput();
                inputData.AlbumId       = base.NavigationContext.QueryString["albumId"];
                inputData.UserOrGroupId = (long)int.Parse(base.NavigationContext.QueryString["userOrGroupId"]);
                inputData.IsGroup       = bool.Parse(base.NavigationContext.QueryString["isGroup"]);
                if (base.NavigationContext.QueryString.ContainsKey("albumName"))
                {
                    inputData.AlbumName        = base.NavigationContext.QueryString["albumName"];
                    inputData.AlbumType        = (AlbumType)Enum.Parse(typeof(AlbumType), base.NavigationContext.QueryString["albumType"], true);
                    inputData.PageTitle        = base.NavigationContext.QueryString["pageTitle"];
                    inputData.AlbumDescription = base.NavigationContext.QueryString["albumDesc"];
                    inputData.PhotosCount      = int.Parse(base.NavigationContext.QueryString["photosCount"]);
                    this._pickMode             = bool.Parse(base.NavigationContext.QueryString["PickMode"]);
                    inputData.AdminLevel       = int.Parse(base.NavigationContext.QueryString["AdminLevel"]);
                    inputData.ForceCanUpload   = bool.Parse(base.NavigationContext.QueryString["ForceCanUpload"]);
                }
                PhotoAlbumViewModel photoAlbumViewModel = new PhotoAlbumViewModel(inputData);
                photoAlbumViewModel.PropertyChanged += (PropertyChangedEventHandler)((sender, args) =>
                {
                    bool flag = this.PhotoAlbumVM.PhotosCount > 0;
                    if (this._appBarIconButtonEdit.IsEnabled == flag)
                    {
                        return;
                    }
                    this._appBarIconButtonEdit.IsEnabled = (flag);
                });
                this.UpdateHeaderOpacity();
                base.DataContext = (photoAlbumViewModel);
                if (photosToMove == null)
                {
                    photoAlbumViewModel.RefreshPhotos();
                }
                else
                {
                    needRefreshAfterMove = true;
                }
                this.UpdateAppBar();
                this._inputData     = inputData;
                this._isInitialized = true;
            }
            if (photosToMove != null)
            {
                this.PhotoAlbumVM.MovePhotos(photosToMove.albumId, photosToMove.photos, (Action <bool>)(result => Execute.ExecuteOnUIThread((Action)(() =>
                {
                    if (needRefreshAfterMove)
                    {
                        this.PhotoAlbumVM.RefreshPhotos();
                    }
                    if (this.PhotoAlbumVM.PhotosCount == 0)
                    {
                        this.IsInEditMode = false;
                    }
                    if (!result)
                    {
                        ExtendedMessageBox.ShowSafe(CommonResources.GenericErrorText);
                    }
                    else if (MessageBox.Show(UIStringFormatterHelper.FormatNumberOfSomething(photosToMove.photos.Count, PhotoResources.PhotoAlbumPageOnePhotoMovedFrm, PhotoResources.PhotoAlbumPageTwoFourPhotosMovedFrm, PhotoResources.PhotoAlbumPageFivePhotosMovedFrm, true, photosToMove.albumName, false), PhotoResources.PhotoAlbumPage_PhotoMove, (MessageBoxButton)1) == MessageBoxResult.OK)
                    {
                        Navigator.Current.NavigateToPhotoAlbum(photosToMove.TargetAlbumInputData.UserOrGroupId, photosToMove.TargetAlbumInputData.IsGroup, photosToMove.TargetAlbumInputData.AlbumType.ToString(), photosToMove.TargetAlbumInputData.AlbumId, photosToMove.TargetAlbumInputData.AlbumName, photosToMove.TargetAlbumInputData.PhotosCount + photosToMove.photos.Count, photosToMove.TargetAlbumInputData.PageTitle, photosToMove.TargetAlbumInputData.AlbumDescription, false, 0, false);
                    }
                    this.PhotoAlbumVM.UpdateThumbAfterPhotosMoving();
                }))));
            }
            if (this._choosenPhotoPending != null)
            {
                this.PhotoAlbumVM.UploadPhoto(this._choosenPhotoPending, (Action <BackendResult <Photo, ResultCode> >)(res => {}));
                this._choosenPhotoPending = null;
            }
            this.HandleInputParameters();
        }
Beispiel #12
0
 public void SetPhotosResponse(List <Photo> photos)
 {
     photoAlbum = new PhotoAlbumViewModel("", "Varios", null);
     FillViewModelPhotos(photos);
 }
Beispiel #13
0
 public void SetPhotosForAlbumResponse(Album album, List <Photo> albumPhotos)
 {
     photoAlbum = new PhotoAlbumViewModel(album.Name, album.Author, album.CreationDate);
     FillViewModelPhotos(albumPhotos);
 }
        public virtual ActionResult Album(string albumName)
        {
            PhotoAlbumViewModel x = this.photoMetaDataStorage.GetAllbum(albumName);

            return(this.View(x));
        }