public async Task <IActionResult> Edit(int id, AlbumEntity albumEntity) { if (id != albumEntity.Id) { return(NotFound()); } if (ModelState.IsValid) { try { await _albumService.UpdateAsync(albumEntity); } catch (EntityValidationException e) { ModelState.AddModelError(e.PropertyName, e.Message); return(View(new AlbumViewModel(albumEntity))); } catch (DbUpdateConcurrencyException) { if (await _albumService.GetByIdAsync(id) == null) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(new AlbumViewModel(albumEntity))); }
public ArtistEntity FromBusinessEntity(Artist businessEntity, ArtistConvertOptions options) { if (businessEntity == null) { return(null); } ArtistEntity dataEntity = new ArtistEntity() { ID = businessEntity.ID, Name = businessEntity.Name, PrivateMarks = businessEntity.PrivateMarks, Biography = businessEntity.Biography, IsWaste = businessEntity.IsWaste }; if (options == ArtistConvertOptions.Full) { foreach (Tag tagBusinessEntity in businessEntity.Tags) { TagEntity tagDataEntity = FromBusinessEntity(tagBusinessEntity); dataEntity.Tags.Add(tagDataEntity); } foreach (Album albumBusinessEntity in businessEntity.Albums) { AlbumEntity albumDataEntity = FromBusinessEntity(albumBusinessEntity); dataEntity.Albums.Add(albumDataEntity); } } return(dataEntity); }
public async Task Adding_Song_With_Album_Should_Persiste() { using (var factory = new MusicStoreContextFactory()) { using (var context = factory.CreateMusicStoreContext()) { var unitOfWork = new UnitOfWork(context, _mapper); var album = new AlbumEntity(); context.Albums.Add(album); context.SaveChanges(); var song = new SongForCreatingDto { Name = "First Song", AlbumId = album.Id }; await unitOfWork.Songs.AddAsync(song); await unitOfWork.SaveAsync(); } using (var context = factory.CreateMusicStoreContext()) { var song = context.Songs.Include(a => a.Album).First(); Assert.NotNull(song.Album); } } }
private void ProvidePlaceExistence(AlbumEntity album) { PlaceEntity place = _context.Places.FirstOrDefault(p => p.Id == album.PlaceId); if (place != null && PlaceEqualityComparer.AreEqual(album.Place, place)) { return; } place = _context.Places.AsEnumerable() .Where(p => PlaceEqualityComparer.AreEqual(p, album.Place)) .FirstOrDefault(); if (place != null) { album.PlaceId = place.Id; album.Place = place; return; } PlaceEntity newPlace = new PlaceEntity { Name = album.Place.Name, City = album.Place.City, Country = album.Place.Country }; newPlace = _context.Places.Add(newPlace); _context.SaveChanges(); album.PlaceId = newPlace.Id; album.Place = null; }
public async Task Delete_Album_Should_Persiste() { using (var factory = new MusicStoreContextFactory()) { var albumId = 0; using (var context = factory.CreateMusicStoreContext()) { var album = new AlbumEntity { Name = "Name", Description = "Description" }; context.Albums.Add(album); context.SaveChanges(); albumId = album.Id; } using (var context = factory.CreateMusicStoreContext()) { var unitOfWork = new UnitOfWork(context, _mapper); await unitOfWork.Albums.DeleteAsync(albumId); await unitOfWork.SaveAsync(); } using (var context = factory.CreateMusicStoreContext()) { var album = context.Albums.FirstOrDefault(); Assert.Null(album); } } }
/// <summary> /// Method to create a list of pictures from a list of file names. /// </summary> /// <param name="fileNames"></param> /// <param name="album"></param> /// <returns></returns> public static PictureEntity[] FromFileNames(string[] fileNames, ref AlbumEntity album) { // Initialize the list of pictures to add. IList <PictureEntity> newItems = new List <PictureEntity>(); PictureEntity[] pictAdded = null; // Create the array of new Picture entities to add in the database. foreach (string s in fileNames) { // Check if storage information is not null // Add a new picture to the album. PictureEntity item = (new StorageInfoModel(new FileInfo(s))).ToPicture(); if (item != null && !newItems.Contains(item)) { // Add Picture to the list for Pictures. newItems.Add(item); } } // Insert Pictures into the database. log.Warn($"{typeof(PictureEntityCollection).Name}.{MethodBase.GetCurrentMethod().Name} : {newItems?.Count() ?? 0} Pictures ready to insert into database."); pictAdded = DbInsert(newItems, ref album).ToArray(); return(pictAdded); }
public async Task <IActionResult> PutAlbumEntity(int id, AlbumEntity albumEntity) { if (id != albumEntity.Id) { return(BadRequest()); } try { await _albumService.UpdateAsync(albumEntity); return(Ok()); } catch (EntityValidationException e) { ModelState.AddModelError(e.PropertyName, e.Message); return(BadRequest(ModelState)); } catch (RepositoryException e) { ModelState.AddModelError(string.Empty, e.Message); return(BadRequest(ModelState)); } return(NoContent()); }
private async Task <bool> GetApiToDatabase() { if (CrossConnectivity.Current.IsConnected) { var albums = await albumApi.Get(); foreach (var album in albums) { var albumDb = albumDatabase.Get(i => i.Id == album.Id); if (albumDb.Any()) { continue; } var photo = (await photoApi.Get("albumId", album.Id.ToString())).FirstOrDefault(); var user = await userApi.Get(album.UserId); var albumToInsert = new AlbumEntity() { Id = album.Id, Title = album?.Title, Photo = photo?.ThumbnailUrl, User = user?.Name }; albumDatabase.Insert(albumToInsert); } return(await Task.FromResult(true)); } return(await Task.FromResult(false)); }
/// <summary> /// Method to add new <see cref="AlbumEntity"/>. /// </summary> /// <param name="entity">An <see cref="AlbumEntity"/> to add.</param> /// <param name="sectionId"></param> /// <param name="save"></param> /// <returns>The added album entity.</returns> public AlbumEntity Add(AlbumEntity entity, int sectionId = 0, bool save = true) { // Check if Section id is present. if (sectionId > 0) { // Check if Album contains associated Sections /*if (entity.AlbumsInSections == null) * { * // Add new dependency. * entity.AlbumsInSections = new ObservableAlbumsInSections<AlbumEntity, SectionEntity> * { * new AlbumsInSections { SectionId = sectionId } * }; * * } * else if(entity.AlbumsInSections.SingleOrDefault(x => x.SectionId == sectionId).SectionId == 0) * { * entity.AlbumsInSections.Add(new AlbumsInSections { SectionId = sectionId }); * }*/ entity.SectionsPKs.Add(sectionId); } entity = Connector.Albums.Add(entity).Entity; if (save) { Save(); } return(entity); }
public async Task <IdResponse> CreateAlbum(Album album) { try { // Todo: need to lookup actual admin id here var albumEntity = new AlbumEntity(album.Name, _customerService.GetCustomerIdByName(album.CustomerName)); albumEntity.AccessKey = "generate access key"; var insertAlbumOperation = TableOperation.InsertOrMerge(albumEntity); var result = await _albumTable.ExecuteAsync(insertAlbumOperation); var blobServiceClient = new BlobServiceClient(storageconn); var containerClient = await blobServiceClient.CreateBlobContainerAsync(albumEntity.AlbumId); return(new IdResponse { Id = albumEntity.AlbumId }); } catch (Exception e) { return(new IdResponse { ErrorsOccurred = true }); } }
/// <summary> /// 得到地址 /// </summary> /// <returns></returns> protected virtual IList <string> GetUrls(long siteId, AlbumEntity album) { var domain = Configuration.ConfigurationManager.GetSetting <string>("CloudSiteAdminUrl"); var result = new List <string>(); result.Add(string.Format("{0}/Book/CreateFrontCover?albumId={1}", domain, album.Id)); result.Add(string.Format("{0}/Book/CreateAbout?albumId={1}", domain, album.Id)); var catalogs = GetCatalogs(siteId); if (catalogs != null) { foreach (var catalog in catalogs) { var pageIndex = 0; while (true) { var comdities = GetCommodities(catalog.Id, album.PageSize, pageIndex); if (comdities == null || comdities.Count == 0) { break; } var url = string.Format("{0}/Book/CreateCommodity?albumId={1}&catalogId={2}&ids={3}", domain, album.Id, pageIndex == 0?catalog.Id:0, string.Join(",", comdities.Select(it => it.Id).ToArray())); result.Add(url); pageIndex++; } } } result.Add(string.Format("{0}/Book/CreateBackCover?albumId={1}", domain, album.Id)); return(result); }
public Album CreateAlbum(string name, string description, bool isPublic, IEnumerable <Tag> tags, int categoryId) { var oldAlbum = UnitOfWork.Albums.Get(album => album.Name.Equals(name)); if (oldAlbum != null) { throw new DataException("Album name already exists."); } if (tags == null) { tags = new Tag[] { }; } var newAlbum = new AlbumEntity { CategoryId = categoryId, CreatedOn = DateTime.UtcNow, Description = description, IsPublic = isPublic, Name = name, Tags = tags.Select(tag => new TagEntity { Id = tag.Id }).ToList(), }; newAlbum = UnitOfWork.Albums.Add(newAlbum); UnitOfWork.Commit(); return(newAlbum.ToModel()); }
/// <summary> /// Method to initialize page content asynchronously. /// </summary> public override async void InitializeModel() { Model = new PageAlbumModel(this); AlbumEntity album = null; if (ItemId > 0) { AlbumOptionsSelect options = new AlbumOptionsSelect { Dependencies = { EnumEntitiesDependencies.All }, PrimaryKey = ItemId }; album = await PageAlbumModel.Db.Albums.SingleOrNullAsync(options); } Model.AlbumEntity = album ?? new AlbumEntity(); /*UcDataGridSections.OnAdd += SectionsDataGrid_OnAdd; * UcDataGridSections.OnChange += SectionsDataGrid_OnChange; * UcDataGridSections.OnCancel += SectionsDataGrid_OnCancel;*/ // Add picture add handler. PicturesCollection.Added -= PicturesCollection_Added; PicturesCollection.Added += PicturesCollection_Added; // Add picture delete handler. PicturesCollection.Deleted -= PicturesCollection_Deleted; PicturesCollection.Deleted += PicturesCollection_Deleted; }
public async Task Get_Album_Should_Not_Be_Null() { using (var factory = new MusicStoreContextFactory()) { var albumId = 0; using (var context = factory.CreateMusicStoreContext()) { var album = new AlbumEntity { Name = "Name", Description = "Description" }; context.Albums.Add(album); context.SaveChanges(); albumId = album.Id; } using (var context = factory.CreateMusicStoreContext()) { var unitOfWork = new UnitOfWork(context, _mapper); var album = await unitOfWork.Albums.GetAsync(albumId); Assert.NotNull(album); } } }
public Album GetAlbum(int albumID) { Album result = null; ISession session = SessionFactory.GetSession(); try { AlbumEntity dataEntity = session.CreateCriteria <AlbumEntity>(). Add(Restrictions.Eq("ID", albumID)).UniqueResult <AlbumEntity>(); EntityConverter entityConverter = new EntityConverter(); result = entityConverter.FromDataEntity(dataEntity, AlbumConvertOptions.Full); } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }
public bool RemoveAlbum(Album album) { bool result = false; ISession session = SessionFactory.GetSession(); ITransaction tx = session.BeginTransaction(); try { AlbumEntity dataEntity = session.CreateCriteria <AlbumEntity>(). Add(Restrictions.Eq("ID", album.ID)).UniqueResult <AlbumEntity>(); if (dataEntity != null) { session.Delete(dataEntity); tx.Commit(); } result = true; } catch (Exception ex) { Logger.Write(ex); tx.Rollback(); } finally { session.Close(); tx.Dispose(); } return(result); }
public void TestEditPost_Given_EditViewModelWithChanges_Should_UpdateRelatedAlbum() { int albumId = 1; TestContext testContext = new TestContextBuilder().AddDefaultAlbum(albumId, 1, 5).Build(); var albumController = new AlbumController(testContext.AlbumRepository, testContext.PhotoRepository, null); string newTitle = "NewTitle1", newDescription = "NewDescription1", newPlace = "NewPlace1", newCity = "NewCity1", newCountry = "newCountry1"; DateTime newFrom = new DateTime(2016, 1, 1), newTo = new DateTime(2016, 1, 2); var editAlbumViewModel = new EditAlbumViewModel { Id = 1, Title = newTitle, Description = newDescription, From = newFrom, To = newTo, Place = newPlace, City = newCity, Country = newCountry, }; var result = albumController.Edit(editAlbumViewModel) as RedirectToRouteResult; Assert.IsNotNull(result); Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["controller"], "Admin"); AlbumEntity album = testContext.Context.Albums.First(a => a.Id == albumId); Assert.AreEqual(album.Title, newTitle); Assert.AreEqual(album.Description, newDescription); Assert.AreEqual(album.Place.Name, newPlace); Assert.AreEqual(album.Place.City, newCity); Assert.AreEqual(album.Place.Country, newCountry); Assert.AreEqual(album.Period.From, newFrom); Assert.AreEqual(album.Period.To, newTo); }
public async Task <IActionResult> Edit(int id, AlbumEntity albumEntity) { if (id != albumEntity.Id) { return(NotFound()); } if (ModelState.IsValid) { try { await _albumService.UpdateAsync(albumEntity); } catch (DbUpdateConcurrencyException) { if (!AlbumEntityExists(albumEntity.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(albumEntity)); }
public bool SaveAlbum(Album album) { bool result = false; ISession session = SessionFactory.GetSession(); ITransaction tx = session.BeginTransaction(); try { EntityConverter converter = new EntityConverter(); AlbumEntity dataEntity = converter.FromBusinessEntity(album); session.Merge(dataEntity); tx.Commit(); album.ID = dataEntity.ID; result = true; } catch (Exception ex) { Logger.Write(ex); tx.Rollback(); } finally { session.Close(); tx.Dispose(); } return(result); }
public async Task Add_Existing_Song_ToExisting_Album_Should_Persisite() { using (var factory = new MusicStoreContextFactory()) { int songId = 0; int albumId = 0; using (var context = factory.CreateMusicStoreContext()) { var song = new SongEntity(); var album = new AlbumEntity(); context.Songs.Add(song); context.Albums.Add(album); context.SaveChanges(); songId = song.Id; albumId = album.Id; } using (var context = factory.CreateMusicStoreContext()) { var unitOfWork = new UnitOfWork(context, _mapper); await unitOfWork.Songs.AddSongToAlbum(songId, albumId); await unitOfWork.SaveAsync(); } using (var context = factory.CreateMusicStoreContext()) { var song = context.Songs.Include(s => s.Album).First(); Assert.NotNull(song.Album); } } }
public TestContextBuilder AddDefaultAlbum(int id, int minPhotoId = 0, int maxPhotoId = 1) { var albumEntity = new AlbumEntity { Id = id, Title = $"Album{id}", Description = $"Description{id}", Period = new DateTimePeriod { From = DateTime.Now, To = DateTime.Now.AddDays(1) }, PlaceId = id, Place = new PlaceEntity { Id = id, Name = $"Place{id}", City = $"City{id}", Country = $"Country{id}" }, Photos = Enumerable.Range(minPhotoId, maxPhotoId - minPhotoId) .Select(photoId => new PhotoEntity { Id = photoId, Title = $"Title{photoId}", Image = new byte[0], ImageType = Core.ImageType.Jpeg, CreationDate = DateTime.Now.AddHours(1) }) .ToList() }; return(AddAlbum(albumEntity)); }
public IPagedList <Album> GetAlbums(ILoadOptions options) { IPagedList <Album> result = new PagedList <Album>(); if (options == null) { return(result); } if (options.MaxResults <= 0) { return(result); } ISession session = SessionFactory.GetSession(); try { DetachedCriteria countCriteria = GetAlbumsImpl(options); DetachedCriteria listCriteria = GetAlbumsImpl(options); countCriteria.SetProjection(Projections.RowCount()); countCriteria.ClearOrders(); listCriteria. SetFirstResult(options.FirstResult). SetMaxResults(options.MaxResults); IMultiCriteria multiCriteria = session.CreateMultiCriteria(); multiCriteria.Add(countCriteria); multiCriteria.Add(listCriteria); IList queryResult = multiCriteria.List(); result.TotalItems = (int)((IList)queryResult[0])[0]; IList recordsList = (IList)queryResult[1]; EntityConverter entityConverter = new EntityConverter(); foreach (var e in recordsList) { AlbumEntity dataEntity = e as AlbumEntity; Album businessEntity = entityConverter.FromDataEntity(dataEntity, AlbumConvertOptions.Small); result.Add(businessEntity); } } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }
public AlbumListModel MapToListModel(AlbumEntity entity) { return(new AlbumListModel { Id = entity.Id, Name = entity.Name }); }
public AlbumsListModel MapAlbumEntityToAlbumListModel(AlbumEntity entity) { return(new AlbumsListModel() { Id = entity.Id, Name = entity.Name }); }
/// <summary> /// Class XtrmAddons Fotootof Server Libraries Common Albums Collection Constructor. /// </summary> /// <param name="fileNames"></param> /// <param name="album"></param> public PictureEntityCollection(string[] fileNames, ref AlbumEntity album) : base() { PictureEntity[] items = FromFileNames(fileNames, ref album); foreach (PictureEntity entity in items) { Add(entity); } }
public void MapAlbumToAlbumEntity_WithoutAlbumItem() { Album album = new Album(_user, "TestAlbum"); AlbumEntity entity = AutoMapper.Mapper.Map <AlbumEntity>(album); Assert.AreEqual(entity.UserEntity.Name, album.User.Name); Assert.AreEqual(entity.Title, album.Title); }
public AlbumViewModel(AlbumEntity albumEntity) { Title = albumEntity.Title; RecordCompany = albumEntity.RecordCompany; DataLancamento = albumEntity.DataLancamento; Remasterizado = albumEntity.Remasterizado; GroupEntityId = albumEntity.GroupEntityId; Group = albumEntity.Group; }
public AlbumDetailModel MapAlbumEntityToAlbumDetailModel(AlbumEntity entity) { return(new AlbumDetailModel() { Id = entity.Id, Name = entity.Name, Photos = entity.Photos }); }
public void Create(AlbumEntity album) { albumRepository.Create(new DalAlbum() { Name = album.Name, UserId = album.UserId, CreationDate = album.CreationDate }); uow.Commit(); }
public AlbumDetailModel MapToDetail(AlbumEntity entity) { return(new AlbumDetailModel { Id = entity.Id, Description = entity.Description, Name = entity.Name, PictureCollection = entity.PictureCollection.Select(_picMapper.MapToDetail).ToList() }); }