Exemplo n.º 1
0
        protected internal virtual Account With(string displayName, Email email)
        {
            if (context.Query <Accounts>().CountBy(email) > 0)
            {
                throw new SecurityException.DuplicateEmailFound(email);
            }
            var dName = displayName.Trim();

            if (dName.IndexOf(" ", StringComparison.Ordinal) != -1 || dName.Length > MAX_DISPLAY_NAME_LENGHT || dName.Length < MIN_DISPLAY_NAME_LENGHT)
            {
                throw new SharedDataException.InvalidData("displayName", displayName);
            }

            if (context.Query <Accounts>().CountBy(displayName) > 0)
            {
                throw new SecurityException.DuplicateNameFound(displayName);
            }

            DisplayName = displayName;
            Email       = email;
            Password    = string.Empty;
            Status      = AccountStatus.Passive;

            repository.Insert(this);

            return(this);
        }
Exemplo n.º 2
0
        protected internal virtual Language With(string code, string name)
        {
            if (context.Query <Languages>().SingleByLanguageCode(code) != null)
            {
                throw new SharedDataException.RecordAlreadyExists(code);
            }

            LanguageCode = code;
            LanguageName = name;
            IsActive     = true;

            repository.Insert(this);

            return(this);
        }
Exemplo n.º 3
0
        protected internal virtual LocalizationText With(string textKey, string value, string languageCode)
        {
            if (string.IsNullOrEmpty(textKey))
            {
                throw new SharedDataException.RequiredParameterIsMissing("textKey");
            }
            if (string.IsNullOrEmpty(value))
            {
                throw new SharedDataException.RequiredParameterIsMissing("value");
            }

            var language = context.Query <Languages>().SingleByLanguageCode(languageCode);

            if (language == null)
            {
                throw new SharedDataException.RecordNotFound("languageCode");
            }

            Language  = language;
            TextKey   = textKey;
            Value     = value;
            IsDeleted = false;

            repository.Insert(this);

            return(this);
        }
Exemplo n.º 4
0
        public AccountToken Login(Email email, string password)
        {
            if (email.IsDefault())
            {
                throw new SecurityException.EmailCannotBeEmpty();
            }
            if (password.IsNullOrEmpty())
            {
                throw new SecurityException.PasswordCannotBeEmpty();
            }

            var account = context.Query <Accounts>().SingleBy(email, password);

            if (account == null)
            {
                throw new SecurityException.AccountNotFound();
            }

            return(account.CreateToken());
        }
Exemplo n.º 5
0
 public Language GetLanguage(string languageCode)
 {
     return(context.Query <Languages>().SingleByLanguageCode(languageCode));
 }