private void Insert(IImage image, EntityFrameworkPhotos entityFrameworkPhoto) { if (image.HumanoidTags == null) { return; } foreach (var humanoidTagName in image.HumanoidTags) { var itag = this.allHumanoidTags.SingleOrDefault(x => x.Name == humanoidTagName); if (itag == null) { throw new InvalidOperationException("ITag must exists in DB"); } var rel = new EntityFrameworkPhotoItagRel { HumanoidTag = itag, EntityFrameworkPhoto = entityFrameworkPhoto }; entityFrameworkPhoto.PhotoItagRel.Add(rel); } this.Db.Photos.Add(entityFrameworkPhoto); this.Save(); }
public void InsertOrUpdate(IImage image) { var photo = EntityFrameworkPhotos.FromImage(image); if (this.TryUpdate(photo)) { return; } this.Insert(image, photo); }
private bool TryUpdate(EntityFrameworkPhotos entityFrameworkPhoto) { var existingPhoto = this.Db.Photos.FirstOrDefault(x => x.Shortcode == entityFrameworkPhoto.Shortcode); if (existingPhoto == null) { return(false); } existingPhoto.Likes = entityFrameworkPhoto.Likes; existingPhoto.Comments = entityFrameworkPhoto.Comments; existingPhoto.Following = entityFrameworkPhoto.Following; existingPhoto.Posts = entityFrameworkPhoto.Posts; this.Save(); return(true); }
public static EntityFrameworkPhotos FromImage(IImage image) { var photo = new EntityFrameworkPhotos { LargeUrl = image.LargeUrl, ThumbUrl = image.ThumbUrl, Shortcode = image.Shortcode, Likes = image.Likes, Comments = image.Comments, User = image.User, Follower = image.Follower, Following = image.Following, Posts = image.Posts, Uploaded = image.Uploaded }; return(photo); }