예제 #1
0
        protected override IReadDocument Update(int id, IWriteDocument writeDocument, System.Net.Http.HttpResponseMessage response)
        {
            UpdateCalled = true;
            var value = Reader.Read(writeDocument);

            return(Writer.Write(value));
        }
        protected override IReadDocument Update(int id, IWriteDocument writeDocument, HttpResponseMessage response)
        {
            var friend = Reader.Read(writeDocument);

            friend.Id = id;
            repo.Update(friend);
            return(Writer.Write(friend));
        }
        public Friend Read(IWriteDocument document)
        {
            var template = document.Template;
            var friend   = new Friend();

            friend.FullName = template.Data.GetDataByName("name").Value;
            friend.Email    = template.Data.GetDataByName("email").Value;
            friend.Blog     = new Uri(template.Data.GetDataByName("blog").Value);
            friend.Avatar   = new Uri(template.Data.GetDataByName("avatar").Value);
            return(friend);
        }
        /// <summary>
        ///     With given data collected from the request, builds an instance of ProjectModel
        ///     and inserts it into the DB.
        /// </summary>
        private async Task <bool> SaveNewProject(IWriteDocument template, string projectName)
        {
            const int tagsParamIndex = 1;
            var       tags           = template.Template.Data[tagsParamIndex].Value;

            if (tags == null)
            {
                return(false);
            }
            var tagModels = new List <string>();

            if (tags.Length > 0)
            {
                tagModels = tags.Split('+').ToList();
            }
            var newProject = new ProjectModel {
                Name = projectName
            };

            Context.Projects.Add(newProject);

            //handle tags
            foreach (var tagModel in tagModels)
            {
                var found = Context.Tags.Find(tagModel);
                if (found == null)
                {
                    Context.Tags.Add(new TagModel {
                        Name = tagModel
                    });
                    AssociateProjectWithTag(newProject.Name, tagModel);
                }
                else
                {
                    AssociateProjectWithTag(newProject.Name, tagModel);
                }
            }

            await Context.SaveChangesAsync();

            return(true);
        }
예제 #5
0
 protected override int Create(IWriteDocument writeDocument, System.Net.Http.HttpResponseMessage response)
 {
     CreateCalled = true;
     return(1);
 }
 public WriteDocumentDecorator(IWriteDocument innerWriteDocument)
 {
     _innerWriteDocument = innerWriteDocument;
 }
 public WriteDocumentDecorator(IWriteDocument innerWriteDocument)
 {
     _innerWriteDocument = innerWriteDocument;
 }
        protected override int Create(IWriteDocument writeDocument, HttpResponseMessage response)
        {
            var friend = Reader.Read(writeDocument);

            return(repo.Add(friend));
        }
        /// <summary>
        ///     With given data collected from the request, builds an instance of ProjectModel
        ///     and inserts it into the DB.
        /// </summary>
        private async Task<bool> SaveNewProject(IWriteDocument template, string projectName)
        {
            const int tagsParamIndex = 1;
            var tags = template.Template.Data[tagsParamIndex].Value;
            if (tags == null)
            {
                return false;
            }
            var tagModels = new List<string>();
            if (tags.Length > 0)
            {
                tagModels = tags.Split('+').ToList();
            }
            var newProject = new ProjectModel {Name = projectName};
            Context.Projects.Add(newProject);

            //handle tags
            foreach (var tagModel in tagModels)
            {
                var found = Context.Tags.Find(tagModel);
                if (found == null)
                {
                    Context.Tags.Add(new TagModel {Name = tagModel});
                    AssociateProjectWithTag(newProject.Name, tagModel);
                }
                else
                {
                    AssociateProjectWithTag(newProject.Name, tagModel);
                }
            }

            await Context.SaveChangesAsync();
            return true;
        }