public void TestUpdate() { Guid id; using (var context = new MyPhotoDbContext()) { id = context.Persons.Add(new PersonEntity { Description = "Skvela osoba", FirstName = "Joe", LastName = "NeSekac" }).Id; context.SaveChanges(); var founded = _repository.GetById(id); Assert.Equal(founded.Id, id); Assert.Equal("Skvela osoba", founded.Description); Assert.Equal("Joe", founded.FirstName); Assert.Equal("NeSekac", founded.LastName); } var person = _repository.GetById(id); person.LastName = "Sekac"; _repository.Update(person); var founded_person = _repository.GetById(id); Assert.Equal(founded_person.Id, id); Assert.Equal("Skvela osoba", founded_person.Description); Assert.Equal("Joe", founded_person.FirstName); Assert.Equal("Sekac", founded_person.LastName); }
public void TestRemove() { Guid id; using (var context = new MyPhotoDbContext()) { id = context.PositionsInPicture.Add(new PositionInPictureEntity { Height = 10, Width = 10, X = 10, Y = 10, PictureObject = new ObjectEntity { Description = "test object", Name = "test obj" } } ).Id; context.SaveChanges(); } _repository.Remove(id); using (var context = new MyPhotoDbContext()) { Assert.Null(context.Albums.Find(id)); } }
public void TestGetById() { Guid id; using (var context = new MyPhotoDbContext()) { id = context.PositionsInPicture.Add(new PositionInPictureEntity { Height = 10, Width = 10, X = 10, Y = 10, PictureObject = new ObjectEntity { Description = "test object", Name = "test obj" } } ).Id; context.SaveChanges(); } var founded = _repository.GetById(id); Assert.Equal(founded.Id, id); Assert.Equal(10, founded.Height); Assert.Equal(10, founded.Width); Assert.Equal(10, founded.X); Assert.Equal("test object", founded.PictureObject.Description); Assert.True(founded.PictureObject is ObjectDetailModel); }
public IEnumerable <AlbumListModel> GetAlbumListModels() { using (var context = new MyPhotoDbContext()) { return(context.Albums.AsEnumerable().Select(_mapper.MapToListModel).ToList()); } }
public void TestGetObjectListModels() { List <ObjectEntity> entities; using (var context = new MyPhotoDbContext()) { if (!context.Objects.Any()) { context.Objects.Add(new ObjectEntity { Description = "Starodavna drevena zidle", Name = "zidle" }); context.SaveChanges(); } entities = context.Objects.ToList(); } var _objects = _repository.GetObjectListModels().ToList(); foreach (var entity in entities) { var _object = _objects.FirstOrDefault(a => a.Id == entity.Id); Assert.NotNull(_object); Assert.Equal(entity.Name, _object.Name); } }
public void TestGetAlbumListModels() { List <AlbumEntity> entities; using (var context = new MyPhotoDbContext()) { if (!context.Albums.Any()) { context.Albums.Add(new AlbumEntity { Name = "album test", Description = "album test desc" } ); context.SaveChanges(); } entities = context.Albums.ToList(); } var albums = _repository.GetAlbumListModels().ToList(); foreach (var entity in entities) { var album = albums.FirstOrDefault(a => a.Id == entity.Id); Assert.NotNull(album); Assert.Equal(entity.Name, album.Name); } }
public IEnumerable <PictureDetailModel> GetAllPictureModels() { using (var context = new MyPhotoDbContext()) { return(context.Pictures.AsEnumerable().Select(_mapper.MapToDetail).ToList()); } }
public void TestUpdate() { Guid id; using (var context = new MyPhotoDbContext()) { id = context.Objects.Add(new ObjectEntity { Description = "Starodavna drevena zidle", Name = "zidle" }).Id; context.SaveChanges(); var founded = _repository.GetById(id); Assert.Equal(founded.Id, id); Assert.Equal("Starodavna drevena zidle", founded.Description); Assert.Equal("zidle", founded.Name); } var _object = _repository.GetById(id); _object.Name = "stul"; _repository.Update(_object); var founded_object = _repository.GetById(id); Assert.Equal(founded_object.Id, id); Assert.Equal("Starodavna drevena zidle", founded_object.Description); Assert.Equal("stul", founded_object.Name); }
public void TestGetPersonListModels() { List <PersonEntity> entities; using (var context = new MyPhotoDbContext()) { if (!context.Persons.Any()) { context.Persons.Add(new PersonEntity() { Description = "Skvela osoba", FirstName = "Joe", LastName = "Sekac" } ); context.SaveChanges(); } entities = context.Persons.ToList(); } var persons = _repository.GetAllPersonListModels().ToList(); foreach (var entity in entities) { var person = persons.FirstOrDefault(a => a.Id == entity.Id); Assert.NotNull(person); Assert.Equal($"{entity.FirstName} {entity.LastName}", person.Name); } }
public ObjectDetailModel GetById(Guid id) { using (var context = new MyPhotoDbContext()) { return(_mapper.MapToDetail(context.Objects.Find(id))); } }
public void Update(ObjectDetailModel item) { using (var context = new MyPhotoDbContext()) { var entity = context.Objects.First(obj => obj.Id == item.Id); entity.Name = item.Name; entity.Description = item.Description; context.SaveChanges(); } }
public IEnumerable <PictureDetailModel> GetAllPictureModelsByPersonId(Guid id) { using (var context = new MyPhotoDbContext()) { return(context.Pictures .Where(a => a.PictureObjectCollection.Any(b => (b.PictureObject is PersonEntity) && b.PictureObject.Id == id)) .AsEnumerable() .Select(_mapper.MapToDetail).ToList());; } }
public AlbumDetailModel Insert(AlbumDetailModel item) { using (var context = new MyPhotoDbContext()) { var entity = _mapper.MapToEntity(item); entity.Id = Guid.NewGuid(); context.Albums.Add(entity); context.SaveChanges(); return(_mapper.MapToDetail(entity)); } }
public PositionInPictureModel Insert(PositionInPictureModel item) { using (var context = new MyPhotoDbContext()) { var entity = _mapper.MapToEntity(item); entity.Id = Guid.NewGuid(); context.PositionsInPicture.Add(entity); context.SaveChanges(); return(_mapper.MapToModel(entity)); } }
public void Update(PersonDetailModel item) { using (var context = new MyPhotoDbContext()) { var entity = context.Persons.First(person => person.Id == item.Id); entity.FirstName = item.FirstName; entity.Description = item.Description; entity.LastName = item.LastName; context.SaveChanges(); } }
public AlbumDetailModel GetById(Guid id) { using (var context = new MyPhotoDbContext()) { return(_mapper.MapToDetail( context.Albums .Where(a => a.Id == id) .Include(a => a.PictureCollection) .FirstOrDefault() )); } }
public void Remove(Guid id) { using (var context = new MyPhotoDbContext()) { var entity = context.Pictures.Include(x => x.PictureObjectCollection).FirstOrDefault(x => x.Id == id); if (entity != null) { context.Pictures.Remove(entity); } context.SaveChanges(); } }
public IEnumerable <PositionInPictureModel> GetPositionsInPictureById(Guid pictureId) { using (var context = new MyPhotoDbContext()) { return(context.Pictures .Include(pic => pic.PictureObjectCollection.Select(pos => pos.PictureObject)) .First(pic => pic.Id == pictureId) .PictureObjectCollection .Select(_mapper.MapToModel) .ToList()); } }
public PositionInPictureModel GetById(Guid id) { using (var context = new MyPhotoDbContext()) { return(_mapper.MapToModel( context.PositionsInPicture .Where(p => p.Id == id) .Include(p => p.PictureObject) .FirstOrDefault() )); } }
public void Remove(Guid id) { using (var context = new MyPhotoDbContext()) { var entity = new AlbumEntity() { Id = id }; context.Albums.Attach(entity); context.Albums.Remove(entity); context.SaveChanges(); } }
public void Remove(Guid id) { using (var context = new MyPhotoDbContext()) { var entity = new PositionInPictureEntity() { Id = id }; context.PositionsInPicture.Attach(entity); context.PositionsInPicture.Remove(entity); context.SaveChanges(); } }
public void Remove(Guid id) { using (var context = new MyPhotoDbContext()) { var entity = new ObjectEntity() { Id = id }; context.Pictures.Include(r => r.PictureObjectCollection).Where(x => x.PictureObjectCollection.Any(y => y.PictureObject.Id == id)).ToList(); context.Objects.Attach(entity); context.Objects.Remove(entity); context.SaveChanges(); } }
public void Update(PositionInPictureModel item) { using (var context = new MyPhotoDbContext()) { var entity = context.PositionsInPicture .Include(p => p.PictureObject).First(p => p.Id == item.Id); entity.Id = item.Id; entity.Height = item.Height; entity.Width = item.Width; entity.X = item.X; entity.Y = item.Y; if (item.PictureObject != null && (entity.PictureObject != null && entity.PictureObject.Id == item.PictureObject.Id)) { switch (item.PictureObject) { case PersonDetailModel person: _personRepository.Update(person); break; case ObjectDetailModel obj: _objRepository.Update(obj); break; } context.SaveChanges(); } else { var todel = entity.PictureObject; switch (item.PictureObject) { case PersonDetailModel person: entity.PictureObject = context.Persons.Find(_personRepository.Insert(person).Id); break; case ObjectDetailModel obj: entity.PictureObject = context.Objects.Find(_objRepository.Insert(obj).Id); break; } context.SaveChanges(); if (todel == null) { return; } switch (todel) { case PersonEntity person: _personRepository.Remove(person.Id); break; case ObjectEntity obj: _objRepository.Remove(obj.Id); break; } } } }
public void TestGetPositionsInPictureById() { Guid id; using (var context = new MyPhotoDbContext()) { id = context.Pictures.Add(new PictureEntity { Description = "testpic", PictureObjectCollection = new List <PositionInPictureEntity> { new PositionInPictureEntity { Height = 10, Width = 10, X = 10, Y = 10, PictureObject = new ObjectEntity { Description = "test object", Name = "test obj" } }, new PositionInPictureEntity { Height = 10, Width = 10, X = 50, Y = 50, PictureObject = new PersonEntity { Description = "test object", FirstName = "honza", LastName = "tester" } } } } ).Id; context.SaveChanges(); } var positions = _repository.GetPositionsInPictureById(id).OrderBy(p => p.X).ToList(); Assert.Equal(2, positions.Count()); Assert.True(positions[0].PictureObject is ObjectDetailModel); Assert.True(positions[1].PictureObject is PersonDetailModel); }
public PictureDetailModel GetById(Guid id) { using (var context = new MyPhotoDbContext()) { var entity = context.Pictures.Include(x => x.PictureObjectCollection).FirstOrDefault(x => x.Id == id); IList <PositionInPictureEntity> positions = new List <PositionInPictureEntity>(); foreach (var positionInPictureEntity in entity.PictureObjectCollection) { positions.Add(context.PositionsInPicture.Include(x => x.PictureObject) .FirstOrDefault(x => x.Id == positionInPictureEntity.Id)); } entity.PictureObjectCollection = positions; return(_mapper.MapToDetail(entity)); } }
public void TestRemove() { Guid id; using (var context = new MyPhotoDbContext()) { id = context.Objects.Add(new ObjectEntity { Description = "Starodavna zidle", Name = "zidle", }).Id; context.SaveChanges(); Assert.NotNull(context.Objects.Find(id)); } _repository.Remove(id); using (var context = new MyPhotoDbContext()) { Assert.Null(context.Objects.Find(id)); } }
public void TestRemove() { Guid id; using (var context = new MyPhotoDbContext()) { id = context.Albums.Add(new AlbumEntity { Name = "album test", Description = "album test desc" } ).Id; context.SaveChanges(); } _repository.Remove(id); using (var context = new MyPhotoDbContext()) { Assert.Null(context.Albums.Find(id)); } }
public void TestGetById() { Guid id; using (var context = new MyPhotoDbContext()) { id = context.Albums.Add(new AlbumEntity { Name = "album test", Description = "album test desc" } ).Id; context.SaveChanges(); } var founded = _repository.GetById(id); Assert.Equal(founded.Id, id); Assert.Equal("album test", founded.Name); Assert.Equal("album test desc", founded.Description); }
public void TestRemove() { Guid id; using (var context = new MyPhotoDbContext()) { id = context.Persons.Add(new PersonEntity { Description = "Skvela osoba", FirstName = "Joe", LastName = "Sekac" }).Id; context.SaveChanges(); Assert.NotNull(context.Persons.Find(id)); } _repository.Remove(id); using (var context = new MyPhotoDbContext()) { Assert.Null(context.Persons.Find(id)); } }
public void Update(AlbumDetailModel item) { using (var context = new MyPhotoDbContext()) { var entity = context.Albums.Include(a => a.PictureCollection).First(album => album.Id == item.Id); entity.Name = item.Name; entity.Description = item.Description; entity.PictureCollection = item.PictureCollection .Select(detailModel => { var pictureEntity = _picMapper.MapToEntity(detailModel); if (context.Pictures.Any(p => p.Id == pictureEntity.Id)) { pictureEntity = context.Pictures.Find(pictureEntity.Id); } return(pictureEntity); } ).ToList(); context.SaveChanges(); } }