Ejemplo n.º 1
0
        public bool AddRefreshToken(ProtoOAuthRefreshToken refreshToken)
        {
            var existingToken =
                _dbContext.ProtoOAuthRefreshTokens.SingleOrDefault(
                    r => r.Subject == refreshToken.Subject && r.ClientId == refreshToken.ClientId);

            if (existingToken != null)
            {
                RemoveRefreshToken(existingToken);
            }

            _dbContext.ProtoOAuthRefreshTokens.Add(refreshToken);

            return(_dbContext.ThisDbContext().SaveChanges() > 0);
        }
Ejemplo n.º 2
0
        public void PerformModification(IDictionary <string, ContentModifierForm> modifierForm, string contentId,
                                        out ProtoContent modifiedContent, string operationName)
        {
            var operation = FindModifyOperation(operationName);
            var db        = _dbContext.ThisDbContext();

            using (var dbTrx = db.Database.BeginTransaction()) {
                try {
                    modifiedContent = FindProtoContent(contentId, operationName);
                    foreach (var h in Handlers)
                    {
                        h.PerformModification(modifierForm, modifiedContent, operation, ContentType);
                    }
                    dbTrx.Commit();
                } catch (Exception) {
                    dbTrx.Rollback();
                    throw;
                }
            }
        }
Ejemplo n.º 3
0
        public void PerformModification(ContentModifierForm modifierForm, ContentField field,
                                        ContentModifyOperation operation,
                                        ProtoContent content, ContentFieldDefinition fieldDefinition)
        {
            if (operation.Is(CommonFieldModifyOperationsProvider.CREATE_OPERATION_NAME))
            {
                content.CreatedUtc = DateTime.UtcNow;
                content.UpdatedUtc = content.CreatedUtc;
                _dbContext.ProtoContents.Add(content);
            }
            else if (operation.Is(CommonFieldModifyOperationsProvider.DELETE_OPERATION_NAME))
            {
                content.UpdatedUtc = DateTime.UtcNow;
                _dbContext.ProtoContents.Remove(content);
            }
            else
            {
                content.UpdatedUtc = DateTime.UtcNow;
            }
            if (string.IsNullOrWhiteSpace(content.CreatedByUserId))
            {
                var rctx = ProtoCmsRuntimeContext.Current;
                if (rctx.CurrentUser != null)
                {
                    content.CreatedByUserId = rctx.CurrentUser.Id;
                }
            }
            var creator = _userMgr.ProtoUsers.FirstOrDefault(x => x.Id == content.CreatedByUserId);

            if (creator != null)
            {
                content.CreatedByUserName        = creator.UserName;
                content.CreatedByUserDisplayName = creator.DisplayName;
            }
            _dbContext.ThisDbContext().SaveChanges();
        }