예제 #1
0
        public async Task <T> Update <T>(T content) where T : IContent
        {
            content.UpdatedAt = DateTime.UtcNow;

            var dbContent = await GetContent(content.Id);

            var c = _mapper.Map <Content>(content);

            if (!_context.Exists(c))
            {
                _context.Attach(c);
            }

            _context.Update(c);

            await _context.SaveChangesAsync();

            if (dbContent.ParentId != content.ParentId || dbContent.UrlSlug != content.UrlSlug)
            {
                _routeDataCache.Clear();
            }

            return(content);
        }
예제 #2
0
        public async Task <T> Update <T>(T content) where T : IContent
        {
            var c = _mapper.Map <ContentVersion>(content);

            c.UpdatedAt = DateTime.UtcNow;

            var currentVersion = _context.ContentVersions.AsNoTracking().First(w => w.Id == c.Id);

            currentVersion = _mapper.Map(c, currentVersion);

            if (_context.Entry(currentVersion).State == EntityState.Detached)
            {
                _context.Attach(currentVersion);
            }

            _context.Update(currentVersion);

            await _context.SaveChangesAsync();

            return(content);
        }