示例#1
0
        public new int?Create(SecurityUser securityUser)
        {
            int?id = null;

            if (securityUser != null)
            {
                if (ValidatePasswordsBeforeHash(securityUser))
                {
                    _log.Info("Creating securityUser");
                    securityUser.PasswordHash = PasswordStorage.CreateHash(securityUser.PasswordPlaintext);
                    base.Add(securityUser);
                    int unit = _UnitOfWork.SaveChanges();
                    if (unit < 1 || securityUser.Id < 1)
                    {
                        _log.Warn("Failed to Create securityUser", new ArgumentNullException());
                    }
                    else
                    {
                        _log.Info("Created Security User with ID " + securityUser.Id);
                        id = securityUser.Id;
                    }
                }
                else
                {
                    _log.Info("Passwords are invalid, Security User not created");
                }
            }
            return(id);
        }
示例#2
0
        public int?Create(T entity)
        {
            int?id = null;

            if (entity != null)
            {
                var entityType = typeof(T).Name;
                _log.Info(string.Format("Creating {0}", entityType));
                Add(entity);
                int unit = _UnitOfWork.SaveChanges();
                if (unit < 1 || entity.Id <= 0)
                {
                    _log.Error(string.Format("Failed to Create {0}", entityType, new InvalidOperationException()));
                }
                else
                {
                    _log.Info(string.Format("Created {0} with ID:{1}", entityType, entity.Id));
                    id = entity.Id;
                }
            }
            return(id);
        }