public void ApplyEditMetaTag(ApplicationMetaTag tag, TagEdit edit)
 {
     if (edit.Name != null)
     {
         tag.Tag = SanitizeTags(edit.Name, false);
     }
     tag.UpdateDate = DateTime.UtcNow;
 }
        public bool EditMetaTag(ApplicationDbContext context, string type, string key, TagEdit edit)
        {
            switch (edit.Flag)
            {
            case EditType.New: {
                var newType  = context.ApplicationMetaTagsTypes.FirstOrDefault(x => x.Type == type);
                var newVideo = new ApplicationMetaTag()
                {
                    Type = newType,
                };
                ApplyEditMetaTag(newVideo, edit);
                context.Add(newVideo);
                context.SaveChanges();
            }
            break;

            case EditType.Update: {
                var existingTag = context.ApplicationMetaTags.First(x => x.Type.Type == type && x.Tag == key);
                if (edit.UpdateDate == existingTag.UpdateDate)
                {
                    ApplyEditMetaTag(existingTag, edit);
                }
                else
                {
                    return(false);
                }
            }
            break;

            case EditType.Delete: {
                var existingTag = context.ApplicationMetaTags.First(x => x.Type.Type == type && x.Tag == key);
                context.Remove(existingTag);
            }
            break;

            default:
                throw new Exception("No edit flag passed");
            }

            return(true);
        }