Exemplo n.º 1
0
        public ValidationData ValidateMessage(Message message)
        {
            ValidationData result = new ValidationData()
            {
                Valid = false
            };

            if (message == null)
            {
                result.Message = "No message";
                return(result);
            }

            if (string.IsNullOrWhiteSpace(message.MessageText))
            {
                result.Message = "Message body is empty";
                return(result);
            }

            if (!message.SentDate.HasValue)
            {
                result.Message = "No message sent date";
                return(result);
            }

            if (string.IsNullOrWhiteSpace(message.SentFromIP))
            {
                result.Message = "Message IP is empty";
                return(result);
            }

            if (message.AuthorAccountId.HasValue)
            {
                string currentLogin = accountService.Login;

                if (us.Empty(currentLogin))
                {
                    result.Message = "Message account is not logged in";
                    return(result);
                }

                string messageLogin = accountService.GetLoginById(message.AuthorAccountId.Value);

                if (!us.StrsEqual(currentLogin, messageLogin))
                {
                    result.Message = "Message account is not logged in";
                    return(result);
                }
            }

            result.Valid = true;
            return(result);
        }
Exemplo n.º 2
0
        public Language GetLanguageByCode(string code)
        {
            Language result = db.Languages.AsNoTracking().FirstOrDefault(x => us.StrsEqual(code, x.Code));

            return(result);
        }