public static void GetAlbumPhotos(AlbumType albumType, string albumId, long userOrGroupId, bool isGroup, int offset, int count, Action <BackendResult <PhotosListWithCount, ResultCode> > callback) { PhotosService current = PhotosService.Current; switch (albumType) { case AlbumType.AllPhotos: current.GetAllPhotos(userOrGroupId, isGroup, offset, count, callback); break; case AlbumType.ProfilePhotos: current.GetProfilePhotos(userOrGroupId, offset, count, callback); break; case AlbumType.PhotosWithUser: current.GetUserPhotos(userOrGroupId, offset, count, callback); break; case AlbumType.WallPhotos: current.GetWallPhotos(userOrGroupId, isGroup, offset, count, callback); break; case AlbumType.SavedPhotos: current.GetSavedPhotos(userOrGroupId, isGroup, offset, count, callback); break; case AlbumType.NormalAlbum: current.GetAlbumPhotos(userOrGroupId, isGroup, albumId, offset, count, callback); break; } }
public async Task GetAllShouldReturnCount2() { var photos = new List <Photo>(); var mockPhoto = new Mock <IDeletableEntityRepository <Photo> >(); mockPhoto.Setup(x => x.All()).Returns(photos.AsQueryable()); mockPhoto.Setup(x => x.AddAsync(It.IsAny <Photo>())).Callback((Photo ph) => photos.Add(ph)); var service = new PhotosService(mockPhoto.Object, null); var photo = new Photo { Id = "1", UserId = "1", }; var secondPhoto = new Photo { Id = "2", UserId = "1", }; photos.Add(photo); photos.Add(secondPhoto); var photosCount = service.GetAll <PhotoViewModel>("1"); var expectedResult = 2; Assert.Equal(expectedResult, photosCount.Count()); }
public ActionResult DeleteConfirmed(int id) { var photoService = new PhotosService(); photoService.DeletePhotoById(id); return(RedirectToAction("Index")); }
public async Task <ActionResult> UploadAsync() { HttpPostedFileBase file = Request.Files[0]; Int32 length = file.ContentLength; User currentUser = _unitOfWork.Users.GetOne(user => user.Name.Equals(User.Identity.Name), u => u.Photo.Select(p => p.PhotoImage)); if (PhotosService.TooManyPhoto(currentUser)) { ModelState.AddModelError("", "You can't upload more than 30 photos because you are a free user"); return(View("ManagePhotos", currentUser)); } if (length == 0) { ModelState.AddModelError("", "No image was chosen"); return(View("ManagePhotos", currentUser)); } if (length > 500 * 1024) { ModelState.AddModelError("", "The image size is more than 500K. Please choose smaller image"); return(View("ManagePhotos", currentUser)); } if (!file.ContentType.Equals("image/jpeg")) { ModelState.AddModelError("", "Image must be JPEG"); return(View("ManagePhotos", currentUser)); } Photo photo = await PhotosService.UploadAsync(file.InputStream, length, _unitOfWork, currentUser.ID); return(View("ManagePhotos", _unitOfWork.Users.GetOne(user => user.Name.Equals(User.Identity.Name), u => u.Photo.Select(p => p.PhotoImage)))); }
public ActionResult Download(int id) { var photoService = new PhotosService(); var res = photoService.DownloadPhotoById(id); return(File(res.FileContent, res.MimeType, res.FileName)); }
public AlbumsController( AlbumsService albumPreviewService, PhotosService photosService ) { this._albumPreviewService = albumPreviewService; this._photosService = photosService; }
// GET: About public ActionResult Index() { //个人信息 User user = AboutService.getUser(); //6张照片 List <Photos> photos = PhotosService.GetPhotos(); ViewBag.A = user; ViewBag.B = photos; return(View()); }
public List <int> GetLoadingPhotos(int blockNumber, string albumName, int blockSize) { List <Photo> photos = PhotosService.GetBlockOfPhotos(_unitOfWork.Albums.GetOne(album => album.Name.Equals(albumName), a => a.Photo).Photo.ToList(), blockNumber, blockSize); List <int> list = new List <int>(); foreach (Photo item in photos) { list.Add(item.ID); } return(list); }
public MainPage() { InitializeComponent(); var apiService = new ApiService(PlaceholderConfApiUrl); var service = new PhotosService(apiService); _viewModel = new MainViewModel(service); this.BindingContext = _viewModel; _viewModel.GetDataCommand.Execute(null); }
public ActionResult AddAlbum() { User currentUser = _unitOfWork.Users.GetOne(user => user.Name.Equals(User.Identity.Name)); if (PhotosService.TooManyAlbums(currentUser)) { ModelState.AddModelError("", "You can't create more than 5 albums because you are a free user"); return(View("ManageAlbums", currentUser)); } return(View("AddAlbum")); }
public HttpResponseMessage UploadGalleryPhoto() { HttpResponseMessage result = null; HttpRequest httpRequest = HttpContext.Current.Request; TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(ConfigService.AwsAccessKeyId , ConfigService.AwsSecretAccessKey , Amazon.RegionEndpoint.USWest2)); if (httpRequest.Files.Count > 0) { foreach (string file in httpRequest.Files) { HttpPostedFile postedFile = httpRequest.Files[file]; string guid = Guid.NewGuid().ToString(); string remoteFilePath = ConfigService.RemoteFilePath + guid + "_" + postedFile.FileName; TransferUtilityUploadRequest fileTransferUtilityRequest = new TransferUtilityUploadRequest { BucketName = ConfigService.BucketName, InputStream = postedFile.InputStream, Key = remoteFilePath, }; fileTransferUtility.Upload(fileTransferUtilityRequest); string paraRemoteFilePath = "/" + remoteFilePath; ItemResponse <string> response = new ItemResponse <string>(); PhotosAdd model = new PhotosAdd(); //model binding by hand. creating a new instance of the model w/ file uploads model.userId = UserService.GetCurrentUserId(); model.URL = paraRemoteFilePath; PhotosService.PhotosInsert(model); response.Item = remoteFilePath; return(Request.CreateResponse(HttpStatusCode.Created, response.Item)); } } else { result = Request.CreateResponse(HttpStatusCode.BadRequest); } return(result); }
public ActionResult Create(PhotoCreateViewModel photo) { if (ModelState.IsValid) { var photoService = new PhotosService(); photoService.Add(new PhotoRechercheViewModel { Photos = photo.ImageFiles }); return(RedirectToAction("Index")); } return(View(photo)); }
public void Save() { if (this._isBusy) { return; } this._isBusy = true; this.SetInProgressMain(true, ""); Album album = this._album.Copy(); album.title = this.Name; album.description = UIStringFormatterHelper.CorrectNewLineCharacters(this.Description); album.privacy_view = this.PrivacyViewVM.GetAsPrivacyInfo().ToStringList(); album.comment_privacy = this.AccessTypeComments != null ? this.AccessTypeComments.Id : 0; PhotosService photosService = new PhotosService(); if (this._isNewMode) { photosService.CreateAlbum(album, (Action <BackendResult <Album, ResultCode> >)(res => { this._isBusy = false; this.SetInProgressMain(false, ""); if (res.ResultCode == ResultCode.Succeeded) { this._notifyOnCompletion(res.ResultData); } else { ExtendedMessageBox.ShowSafe(CommonResources.Error); } }), this._gid); } else { photosService.EditAlbum(album, (Action <BackendResult <ResponseWithId, ResultCode> >)(res => { this._isBusy = false; this.SetInProgressMain(false, ""); if (res.ResultCode == ResultCode.Succeeded) { this._notifyOnCompletion(album); } else { ExtendedMessageBox.ShowSafe(CommonResources.Error); } }), this._gid); } }
public void GetFirstNameByIdShouldReturnTrue() { var photos = new List <Photo>(); var appUsers = new List <ApplicationUser>(); var userChars = new List <UserCharacteristic>(); var mockPhoto = new Mock <IDeletableEntityRepository <Photo> >(); mockPhoto.Setup(x => x.All()).Returns(photos.AsQueryable()); mockPhoto.Setup(x => x.AddAsync(It.IsAny <Photo>())).Callback((Photo ph) => photos.Add(ph)); var mockAppUser = new Mock <IDeletableEntityRepository <ApplicationUser> >(); mockAppUser.Setup(x => x.All()).Returns(appUsers.AsQueryable()); mockAppUser.Setup(x => x.AddAsync(It.IsAny <ApplicationUser>())).Callback((ApplicationUser appU) => appUsers.Add(appU)); var mockUserChar = new Mock <IDeletableEntityRepository <UserCharacteristic> >(); mockUserChar.Setup(x => x.All()).Returns(userChars.AsQueryable()); mockUserChar.Setup(x => x.AddAsync(It.IsAny <UserCharacteristic>())).Callback((UserCharacteristic uc) => userChars.Add(uc)); var service = new PhotosService(mockPhoto.Object, mockAppUser.Object); var photo = new Photo { Id = "1", UserId = "1", }; var appUser = new ApplicationUser { Id = "1", UserCharacteristics = new UserCharacteristic { Id = "1", FirstName = "Pesho", }, }; var secondAppUser = new ApplicationUser { Id = "2", }; photos.Add(photo); appUsers.Add(appUser); var result = service.GetFirstNameById("1"); Assert.Equal(true, result); }
public async Task <string> GetPhotos(string query) { try { PhotosService _photosService = new PhotosService(); PhotoList response = await _photosService.SearchPhotos(query); var photos = JsonConvert.SerializeObject(response.results); return(photos); } catch (System.Exception ex) { Debug.WriteLine(ex); return(ex.Message); } }
// GET: Home文章列表页面 public ActionResult Index(string keyboard) { //文章列表 List <UIData> list = HomeService.GetArticlesList("", keyboard); //个人信息 User user = AboutService.getUser(); //6张照片 List <Photos> photos = PhotosService.GetPhotos(); //分类和文章个数 List <Classify> classList = HomeService.GetClassifyList(); //推荐文章 List <Articles> recomList = RecomService.GetRecomList(); ViewBag.A = list; ViewBag.B = user; ViewBag.C = photos; ViewBag.D = classList; ViewBag.E = recomList; return(View(list)); }
internal void DeleteAlbums(List <AlbumHeader> list) { PhotosService arg_41_0 = PhotosService.Current; Func <AlbumHeader, string> arg_25_1 = new Func <AlbumHeader, string>((ah) => { return(ah.AlbumId); }); arg_41_0.DeleteAlbums(Enumerable.ToList <string>(Enumerable.Select <AlbumHeader, string>(list, arg_25_1)), this.IsGroup ? this.UserOrGroupId : 0L); using (List <AlbumHeader> .Enumerator enumerator = list.GetEnumerator()) { while (enumerator.MoveNext()) { AlbumHeader current = enumerator.Current; this.EditAlbumsVM.Delete(current); EventAggregator.Current.Publish(new PhotoAlbumDeleted { aid = current.AlbumId, EventSource = this.GetHashCode() }); } } this.UpdateAlbums(); }
public async Task DeletePhotoAsyncShouldWorkCorrectly() { var photos = new List <Photo>(); var mockPhoto = new Mock <IDeletableEntityRepository <Photo> >(); mockPhoto.Setup(x => x.All()).Returns(photos.AsQueryable()); mockPhoto.Setup(x => x.AddAsync(It.IsAny <Photo>())).Callback((Photo ph) => photos.Add(ph)); var service = new PhotosService(mockPhoto.Object, null); var photo = new Photo { Id = "1", UserId = "1", }; photos.Add(photo); await service.DeleteAsync("1", "1"); Assert.Equal(true, photo.IsDeleted); }
public async Task DeletePhotoAsyncShouldReturnFalse() { var photos = new List <Photo>(); var mockPhoto = new Mock <IDeletableEntityRepository <Photo> >(); mockPhoto.Setup(x => x.All()).Returns(photos.AsQueryable()); mockPhoto.Setup(x => x.AddAsync(It.IsAny <Photo>())).Callback((Photo ph) => photos.Add(ph)); var service = new PhotosService(mockPhoto.Object, null); var photo = new Photo { Id = "1", UserId = "1", }; photos.Add(photo); Task result = service.DeleteAsync("1", "2"); Assert.False(result.IsFaulted); }
public ActionResult Edit(RechercheCreateEditViewModel vm) { if (ModelState.IsValid) { var recherche = db.Recherches.Find(vm.Recherche.Id); if (recherche == null) { return(HttpNotFound()); } recherche.Active = vm.Recherche.Active; recherche.DerniereApparition = vm.Recherche.DerniereApparition; recherche.Description = vm.Recherche.Description; recherche.Localisation = vm.Recherche.Localisation; db.SaveChanges(); var photoService = new PhotosService(); var photosRecherche = photoService.UpdatePhotosRecherche(new PhotoRechercheViewModel { Photos = vm.ImageFilesRecherche, Recherche = recherche, }); var photosAnimal = photoService.UpdatePhotosAnimal(new PhotoRechercheViewModel { Photos = vm.ImageFilesAnimal, Animal = vm.Recherche.Animal, }); recherche.Photos.AddRange(photosRecherche.Select(p => db.Photos.Find(p.Id))); recherche.Animal.Photos.AddRange(photosAnimal.Select(p => db.Photos.Find(p.Id))); db.SaveChanges(); return(RedirectToAction("Details", new { id = recherche.Id })); } return(View(vm)); }
public ActionResult Create(RechercheCreateEditViewModel vm) { if (ModelState.IsValid) { vm.Recherche.Animal.Type = db.TypeAnimaux.Find(vm.TypeId); db.Animaux.Add(vm.Recherche.Animal); db.Recherches.Add(vm.Recherche); if (Authentification.EstConnecte()) { var sessionUtilisateur = Authentification.GetSessionUtilisateur(); var utilisateur = db.Utilisateurs.Find(sessionUtilisateur.Id); vm.Recherche.Animal.Maitre = utilisateur; } var photoService = new PhotosService(); var photosRecherche = photoService.Add(new PhotoRechercheViewModel { Photos = vm.ImageFilesRecherche, Recherche = vm.Recherche }); var photosAnimal = photoService.Add(new PhotoRechercheViewModel { Photos = vm.ImageFilesAnimal, Animal = vm.Recherche.Animal }); vm.Recherche.Photos = photosRecherche; vm.Recherche.Animal.Photos = photosAnimal; db.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Create")); }
public async Task GetByNameShouldWorkCorrectly() { var photos = new List <Photo>(); var mockPhoto = new Mock <IDeletableEntityRepository <Photo> >(); mockPhoto.Setup(x => x.All()).Returns(photos.AsQueryable()); mockPhoto.Setup(x => x.AddAsync(It.IsAny <Photo>())).Callback((Photo ph) => photos.Add(ph)); var service = new PhotosService(mockPhoto.Object, null); var photo = new Photo { Id = "1", UserId = "1", ImagePath = "Test", }; photos.Add(photo); var ph = service.GetByName <PhotoViewModel>("1"); Assert.Equal(photo.ImagePath, ph.ImagePath); }
public void GetUserByPhotoIdShouldWorkCorrectly() { var photos = new List <Photo>(); var mockPhoto = new Mock <IDeletableEntityRepository <Photo> >(); mockPhoto.Setup(x => x.All()).Returns(photos.AsQueryable()); mockPhoto.Setup(x => x.AddAsync(It.IsAny <Photo>())).Callback((Photo ph) => photos.Add(ph)); var service = new PhotosService(mockPhoto.Object, null); var photo = new Photo { Id = "1", UserId = "1", }; photos.Add(photo); var userId = service.GetUserByPhotoId("1"); var expectedOutput = "1"; Assert.Equal(expectedOutput, userId); }
public PhotosServiceTests() { _sut = new PhotosService(_mapperMock.Object, _unitOfWorkMock.Object); }
/// <summary> /// Retrieve current connected user's photo. /// </summary> /// <returns>A stream containing the user"s photo</returns> public async Task <IRandomAccessStream> GetPhotoAsync() { return((await PhotosService.GetPhotoAsync()) as IRandomAccessStream); }
public bool DeletePhotoAjax(int id) { var photoService = new PhotosService(); return(photoService.DeletePhotoById(id)); }
static void Main(string[] args) { IAuctionCarService auctionCarService = new AuctionCarService(); IAuctionLotService auctionLotService = new AuctionLotService(); IAuctionPhotoService auctionPhotoService = new AuctionPhotoService(); ICarService carService = new CarService(); ICarOwnerService carOwnerService = new CarOwnerService(); IPhotosService photosService = new PhotosService(); IUsersCarService usersCarService = new UsersCarService(); IUsersPhotosService usersPhotosService = new UsersPhotosService(); IOrderService orderService = new OrderService(); IUserService userService = new UserService(); try { auctionCarService.ChangeBrand(""); } catch (EmptyStringException e) { Console.WriteLine("Message : " + e.Message + "\nTime : " + DateTime.Now + "\nStacktrace : " + e.StackTrace + "\nThread : " + Thread.CurrentThread + "\nProcessId : " + Process.GetCurrentProcess().Id); } Console.WriteLine(); try { auctionCarService.ChangeCondition("nn"); } catch (ConditionException e) { Console.WriteLine("Message : " + e.Message + "\nTime : " + DateTime.Now + "\nStacktrace : " + e.StackTrace + "\nThread : " + Thread.CurrentThread + "\nProcessId : " + Process.GetCurrentProcess().Id); } Console.WriteLine(); try { auctionCarService.ChangeFuel("Gg"); } catch (FuelException e) { Console.WriteLine("Message : " + e.Message + "\nTime : " + DateTime.Now + "\nStacktrace : " + e.StackTrace + "\nThread : " + Thread.CurrentThread + "\nProcessId : " + Process.GetCurrentProcess().Id); } Console.WriteLine(); try { auctionCarService.ChangeYear(0); } catch (InvalidYearException e) { Console.WriteLine("Message : " + e.Message + "\nTime : " + DateTime.Now + "\nStacktrace : " + e.StackTrace + "\nThread : " + Thread.CurrentThread + "\nProcessId : " + Process.GetCurrentProcess().Id); } Console.WriteLine(); try { auctionCarService.ChangeHP(0); } catch (ZeroException e) { Console.WriteLine("Message : " + e.Message + "\nTime : " + DateTime.Now + "\nStacktrace : " + e.StackTrace + "\nThread : " + Thread.CurrentThread + "\nProcessId : " + Process.GetCurrentProcess().Id); } Console.WriteLine(); try { userService.ChangeEmail("fsdf"); } catch (InvalidEmailException e) { Console.WriteLine("Message : " + e.Message + "\nTime : " + DateTime.Now + "\nStacktrace : " + e.StackTrace + "\nThread : " + Thread.CurrentThread + "\nProcessId : " + Process.GetCurrentProcess().Id); } Console.WriteLine(); try { userService.ChangeLogin(""); } catch (InvalidLoginException e) { Console.WriteLine("Message : " + e.Message + "\nTime : " + DateTime.Now + "\nStacktrace : " + e.StackTrace + "\nThread : " + Thread.CurrentThread + "\nProcessId : " + Process.GetCurrentProcess().Id); } Console.WriteLine(); try { userService.ChangePassword(""); } catch (InvalidPasswordException e) { Console.WriteLine("Message : " + e.Message + "\nTime : " + DateTime.Now + "\nStacktrace : " + e.StackTrace + "\nThread : " + Thread.CurrentThread + "\nProcessId : " + Process.GetCurrentProcess().Id); } Console.WriteLine(); try { userService.ChangeRole(""); } catch (InvalidRoleException e) { Console.WriteLine("Message : " + e.Message + "\nTime : " + DateTime.Now + "\nStacktrace : " + e.StackTrace + "\nThread : " + Thread.CurrentThread + "\nProcessId : " + Process.GetCurrentProcess().Id); } Console.WriteLine(); try { usersPhotosService.ChangePhoto("fs"); } catch (InvalidPathException e) { Console.WriteLine("Message : " + e.Message + "\nTime : " + DateTime.Now + "\nStacktrace : " + e.StackTrace + "\nThread : " + Thread.CurrentThread + "\nProcessId : " + Process.GetCurrentProcess().Id); } }
public AdminController(ProductsService service, PhotosService photosService) { _productsService = service; _photosService = photosService; }
public PhotosController(PhotosService service) { this.service = service; }
/// <summary> /// Retrieve current connected user's photo. /// </summary> /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param> /// <returns>A stream containing the user"s photo</returns> public async Task <IRandomAccessStream> GetPhotoAsync(CancellationToken cancellationToken) { return((await PhotosService.GetPhotoAsync(CancellationToken.None)) as IRandomAccessStream); }