예제 #1
0
        public void MetaTagsEditing()
        {
            var controller = new TagController();
            var tags       = controller.GetMetaTags().Where(x => x.Value.Count() > 0).OrderBy(x => x.Key).ToList();
            var firstType  = tags[0];
            var firstTags  = tags[0].Value.ToList();
            var updateName = "cool   tag ";
            var newName    = " super cOOl  tag";
            var deleteName = firstTags[1].Value.Value;
            var edits      = new TagEdits()
            {
                Type  = firstType.Key,
                Edits = new Dictionary <string, TagEdit>()
                {
                    { firstTags[0].Value.Value, new TagEdit()
                      {
                          Name       = updateName,
                          Flag       = EditType.Update,
                          UpdateDate = firstTags[0].Value.UpdateDate
                      } },
                    { firstTags[1].Value.Value, new TagEdit()
                      {
                          Flag       = EditType.Delete,
                          UpdateDate = firstTags[1].Value.UpdateDate
                      } },
                    { "_new", new TagEdit()
                      {
                          Flag = EditType.New,
                          Name = newName
                      } }
                }
            };
            var failedEdits = controller.EditMetaTags(edits);

            Assert.Empty(failedEdits.Edits);
            tags      = controller.GetMetaTags().Where(x => x.Value.Count() > 0).OrderBy(x => x.Key).ToList();
            firstType = tags[0];
            Assert.DoesNotContain(firstType.Value, y => y.Value.Value == deleteName);
            Assert.Contains(firstType.Value, y => y.Value.Value == AbstractDBDataBackend.SanitizeTags(updateName, y.Key == Constants.GenericTag));
            Assert.Contains(firstType.Value, y => y.Value.Value == AbstractDBDataBackend.SanitizeTags(newName, y.Key == Constants.GenericTag));
        }
예제 #2
0
        public TagEdits EditTags(TagEdits edit)
        {
            var failed = new TagEdits()
            {
                Edits = new Dictionary <string, TagEdit>()
            };

            foreach (var etag in edit.Edits)
            {
                switch (etag.Value.Flag)
                {
                case EditType.New:
                    var newTag = new Tag()
                    {
                        Type  = edit.Type,
                        Value = etag.Value.Name
                    };
                    MetaTags[edit.Type].Add(newTag);
                    break;

                case EditType.Update:
                    var current = MetaTags[edit.Type].Find(x => x.Value == etag.Key);
                    if (current.UpdateDate == etag.Value.UpdateDate)
                    {
                        current.Value = etag.Value.Name;
                    }
                    else
                    {
                        failed.Edits.Add(etag.Key, etag.Value);
                    }
                    break;

                case EditType.Delete:
                    MetaTags[edit.Type].RemoveAll(x => x.Value == etag.Key);
                    break;
                }
            }
            return(failed);
        }
예제 #3
0
        public TagEdits EditTags(TagEdits edits)
        {
            var failed = new TagEdits()
            {
                Type = edits.Type, Edits = new Dictionary <string, TagEdit>()
            };

            using (var context = new ApplicationDbContext()) {
                using (var transaction = context.Database.BeginTransaction()) {
                    try {
                        foreach (var ed  in edits.Edits)
                        {
                            bool result;
                            if (edits.Type == Constants.GenericTag)
                            {
                                result = EditGenericTag(context, ed.Key, ed.Value);
                            }
                            else
                            {
                                result = EditMetaTag(context, edits.Type, ed.Key, ed.Value);
                            }
                            if (!result)
                            {
                                failed.Edits[ed.Key] = ed.Value;
                            }
                        }
                        context.SaveChanges();
                        transaction.Commit();
                        return(failed);
                    }catch (Exception e) {
                        Console.WriteLine(e.Message);
                        transaction.Rollback();
                        return(edits);
                    }
                }
            }
        }
예제 #4
0
 public TagEdits EditMetaTags([FromBody] TagEdits edits)
 {
     return(Backend.EditTags(edits));
 }