public void Create(DalPhoto photo) { if (ReferenceEquals(photo, null)) { throw new ArgumentNullException(nameof(photo)); } var tags = photo.Tags.ToList(); photo.Tags.Clear(); var ormPhoto = photo.ToPhoto(); foreach (var tag in tags) { var dbtag = context.Context.Set <Tags>().FirstOrDefault(t => t.Name == tag.Name); if (ReferenceEquals(dbtag, null)) { context.Context.Set <Tags>().Add(tag.ToTag()); context.Commit(); dbtag = context.Context.Set <Tags>().FirstOrDefault(t => t.Name == tag.Name); } context.Context.Set <Tags>().Attach(dbtag); dbtag.Photos = new List <Photos>(); dbtag.Photos.Add(ormPhoto); } }
public void Update(DalPhoto photo) { foreach (var r in photo.Ratings) { context.Context.Set <Ratings>().AddOrUpdate(r.ToRating()); } context.Context.Set <Photos>().AddOrUpdate(photo.ToPhoto()); context.Commit(); }
public void Create(DalPhoto dalPhoto) { var photo = dalPhoto.ToPhoto(); foreach (var profileId in dalPhoto.ProfileId) { var profile = Profiles.FirstOrDefault(p => p.Id == profileId); photo.Profile.Add(profile); } Photos.Add(photo); }