예제 #1
0
        public async Task <bool> Update(Post value, CancellationToken cancellationToken = default)
        {
            var to = RawPost.From(value);

            var item = await Data.Posts.FindAsync(new object[] { to.Id }, cancellationToken).ConfigureAwait(false);

            if (item is null)
            {
                return(false);
            }

            item.Keywords         = to.Keywords;
            item.Category         = to.Category;
            item.AuthorId         = to.AuthorId;
            item.Content          = to.Content;
            item.CreationTime     = to.CreationTime;
            item.ModificationTime = to.ModificationTime;
            item.Title            = to.Title;
            item.Type             = to.Type;

            Data.Posts.Update(item);
            await Data.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

            return(true);
        }
예제 #2
0
        public async Task <string> Create(Post value, CancellationToken cancellationToken = default)
        {
            if (string.IsNullOrWhiteSpace(value.Id))
            {
                value.Id = Guid.NewGuid().ToString();
            }
            Data.Posts.Add(RawPost.From(value));
            await Data.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

            return(value.Id);
        }