public int Add(TagModel item, PhotoDetailModel photo) { var itemEntity = _dataContext.Items.FirstOrDefault(x => x.Name == item.Name) ?? _dataContext.Items.Add(new ItemEntity() { Name = item.Name }); _dataContext.SaveChanges(); var photoEntity = _dataContext.Photos.SingleOrDefault(x => x.Id == photo.Id); if (photoEntity == null) { return(-1); } var newItemTag = new ItemTagEntity() { Item = itemEntity, ItemId = itemEntity.Id, XPosition = item.XPosition, YPosition = item.YPosition, }; photoEntity.Tags.Add(newItemTag); _dataContext.SaveChanges(); return(newItemTag.Id); }
public static ItemTagModel ItemTagEntityToItemTagModel(ItemTagEntity itemTagEntity) { return(new ItemTagModel { Id = itemTagEntity.Id, Name = itemTagEntity.Item.Name, ItemId = itemTagEntity.ItemId, YPosition = itemTagEntity.YPosition, XPosition = itemTagEntity.XPosition }); }
protected override void Seed(DataContext context) { var person1 = new PersonEntity() { Id = 1, FirstName = "Jozko", LastName = "Mrkvièka", }; var item1 = new ItemEntity() { Id = 1, Name = "Okno" }; var resolution1 = new ResolutionEntity() { Id = 1, Height = 836, Width = 1254, }; var itemTag1 = new ItemTagEntity() { Id = 1, ItemId = 1, Item = item1, XPosition = 200, YPosition = 350, }; var personTag1 = new PersonTagEntity() { Id = 2, PersonId = 1, Person = person1, XPosition = 500, YPosition = 700, }; var photo1 = new PhotoEntity() { Id = 1, Name = "Auto", Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "fotky\\07a077c43bd4972c0d5ca06fe593_base_optimal.jpg"), CreatedTime = DateTime.Now, Note = "AutoooooooooooooooooooWooho", Location = "Brno", Format = Format.Jpg, ResolutionId = 1, Resolution = resolution1, Tags = new List <TagEntity>() { itemTag1, personTag1 }, AlbumId = 1, }; var album1 = new AlbumEntity() { Id = 1, Title = "Autá", CoverPhotoId = 1, }; photo1.Tags.Add(personTag1); photo1.Tags.Add(itemTag1); context.Persons.AddOrUpdate(x => x.Id, person1); context.Resolutions.AddOrUpdate(x => x.Id, resolution1); context.ItemTags.AddOrUpdate(x => x.Id, itemTag1); context.PersonTags.AddOrUpdate(x => x.Id, personTag1); context.Photos.AddOrUpdate(x => x.Id, photo1); context.Albums.AddOrUpdate(x => x.Id, album1); }