public void RemoveVideoCampaign(ApplicationDbContext context, ApplicationVideo video, string campaignId) { var user = context.UserApplicationVideoSourceCampaigns.FirstOrDefault(x => x.CampaignId == campaignId); // Do Nothing in the case that there is no tag if (user != null) { if (user.VideoId == video.Id) { if (!user.Suppress) { user.Suppress = true; } } } else { var newConstraint = new UserApplicationVideoSourceCampaign() { CampaignId = campaignId, VideoId = video.Id, Suppress = true, UpdateDate = DateTime.UtcNow }; context.Add(newConstraint); } context.SaveChanges(); }
public void RemoveVideoSourceVideo(ApplicationDbContext context, ApplicationVideo video, string sourceVideoId) { var user = context.UserApplicationVideoSourceVideos.FirstOrDefault(x => x.SourceVideoId == sourceVideoId); // Do Nothing in the case that there is no tag if (user != null) { if (user.ApplicationVideoId == video.Id) { if (!user.Suppress) { user.Suppress = true; } } } else { var suppress = new UserApplicationVideoSourceVideo() { SourceVideoId = sourceVideoId, ApplicationVideoId = video.Id, Suppress = true, UpdateDate = DateTime.UtcNow }; context.Add(suppress); } context.SaveChanges(); }
public void AddGenericTag(ApplicationDbContext context, ApplicationVideo video, string genericTagId) { var refTag = context.ApplicationGenericTags.FirstOrDefault(x => x.Tag == genericTagId); if (refTag == null) { refTag = new ApplicationGenericTag() { Tag = genericTagId }; context.Add(refTag); context.SaveChanges(); } var tag = context.ApplicationVideoApplicationGenericTags.FirstOrDefault(x => x.VideoId == video.Id && x.Tag.Tag == genericTagId); // Do nothing in the case where the tag already exist // Generic tags can't be updated if (tag == null) { var newTag = new ApplicationVideoApplicationGenericTag() { VideoId = video.Id, TagId = refTag.Id }; context.Add(newTag); } }
public void EditVideoMetaTags(ApplicationDbContext context, ApplicationVideo video, KeyValuePair <string, string> metaTagId) { if (metaTagId.Value != null) { var refTag = context.ApplicationMetaTags.First(x => x.Tag == metaTagId.Value && x.Type.Type == metaTagId.Key); var currentTag = context.ApplicationVideoApplicationMetaTags.FirstOrDefault(x => x.VideoId == video.Id && x.Type.Type == metaTagId.Key); if (currentTag == null) { var newTag = new ApplicationVideoApplicationMetaTag() { VideoId = video.Id, TagId = refTag.Id, TypeId = refTag.TypeId }; context.ApplicationVideoApplicationMetaTags.Add(newTag); } else { currentTag.TagId = refTag.Id; currentTag.TypeId = refTag.TypeId; currentTag.Tag = refTag; } } else { var tag = context.ApplicationVideoApplicationMetaTags.First(x => x.VideoId == video.Id && x.Type.Type == metaTagId.Key); // Do Nothing in the case that there is no tag if (tag != null) { context.ApplicationVideoApplicationMetaTags.Remove(tag); } } }
public void RemoveGenericTag(ApplicationDbContext context, ApplicationVideo video, string genericTagId) { var tag = context.ApplicationVideoApplicationGenericTags.FirstOrDefault(x => x.VideoId == video.Id && x.Tag.Tag == genericTagId); // Do Nothing in the case that there is no tag if (tag != null) { context.ApplicationVideoApplicationGenericTags.Remove(tag); } }
public void EditVideoRelation(ApplicationDbContext context, ApplicationVideo video, VideoEdit edit) { if (edit.MetaTags != null) { foreach (var etag in edit.MetaTags) { EditVideoMetaTags(context, video, etag); } } if (edit.AddedGenericTags != null) { foreach (var etag in edit.AddedGenericTags) { AddGenericTag(context, video, etag); } } if (edit.RemovedGenericTags != null) { foreach (var etag in edit.RemovedGenericTags) { RemoveGenericTag(context, video, etag); } } if (edit.AddedCampaigns != null) { foreach (var id in edit.AddedCampaigns) { AddVideoCampaign(context, video, id); } } if (edit.RemovedCampaigns != null) { foreach (var id in edit.RemovedCampaigns) { RemoveVideoCampaign(context, video, id); } } if (edit.AddedVideos != null) { foreach (var id in edit.AddedVideos) { AddVideoSourceVideo(context, video, id); } } if (edit.RemovedVideos != null) { foreach (var id in edit.RemovedVideos) { RemoveVideoSourceVideo(context, video, id); } } }
public void EditVideoAction(ApplicationVideo video, VideoEdit edit) { if (edit.Archive.HasValue) { video.Archived = edit.Archive.Value; } if (edit.Title != null) { video.Title = edit.Title; } video.UpdateDate = DateTime.UtcNow; }
public void AddVideoSourceVideo(ApplicationDbContext context, ApplicationVideo video, string sourceVideoId) { var existing = context.UserApplicationVideoSourceVideos.FirstOrDefault(x => x.SourceVideoId == sourceVideoId); var updated = existing ?? new UserApplicationVideoSourceVideo(); updated.SourceVideoId = sourceVideoId; updated.ApplicationVideoId = video.Id; updated.Suppress = false; updated.UpdateDate = DateTime.UtcNow; if (existing == null) { context.Add(updated); } context.SaveChanges(); }
public bool EditVideo(ApplicationDbContext context, string id, VideoEdit edit) { switch (edit.Flag) { case EditType.New: { if (edit.AddedVideos == null || !edit.AddedVideos.Any()) { return(false); } var newVideo = new ApplicationVideo(); EditVideoAction(newVideo, edit); context.Add(newVideo); context.SaveChanges(); EditVideoRelation(context, newVideo, edit); } break; case EditType.Update: { int intId = int.Parse(id); var existingVideo = context.ApplicationVideos.First(x => x.Id == intId); if (edit.UpdateDate == existingVideo.UpdateDate) { EditVideoAction(existingVideo, edit); EditVideoRelation(context, existingVideo, edit); } else { return(false); } } break; case EditType.Delete: { int intId = int.Parse(id); var existingVideo = context.ApplicationVideos.First(x => x.Id == intId); context.ApplicationVideos.Remove(existingVideo); } break; default: throw new Exception("No edit flag passed"); } return(true); }