How to use Data Annotations?

Interesting snippet from C#, ASP.NET and MVC, that uses the ValidationAttribute

Ever wanted to add validation to your MVC view, well look further for more details.

The ValidationAttribute will help you validate your model and server-side properties. As a programmer, you will need to add certain rules or attributes to the properties, such as required, string length, range and change the display property name. The example has a special attribute that limits the amount of words the user can type into a field.

You are required to inherit from ValidationAttribute, in order to use the error message and IsValid method of the attribute. Once you have those, you can set in the constructor, the message and max value. Then override the IsValid method and check the property for the amount of words. I used split and length methods to check against the max words.

If all is fine, return success, otherwise give the user the error message you set in the constructor.

The programmer will need a lot of flexibility in validating their model and view, this snippet can help you avoid writing a lot of extra client side code.

A lot of the credit goes to Scott Allen course on Building Applications with ASP.NET MVC4.

public class MaxWordsAttribute : ValidationAttribute
        public MaxWordsAttribute(int maxWords)
            : base("{0} has too many words.")
            _maxWords = maxWords;

        protected override ValidationResult IsValid(
            object value, ValidationContext validationContext)
            if (value != null)
                var valueAsString = value.ToString();
                if (valueAsString.Split(' ').Length > _maxWords)
                    var errorMessage = FormatErrorMessage(validationContext.DisplayName);
                    return  new ValidationResult(errorMessage);
            return ValidationResult.Success;

        private readonly int _maxWords;

    public class Reviews : IValidatableObject
        public int Rating { get; set; }

        public string Desc { get; set; }

        [Display(Name = "User Name")]
        [DisplayFormat(NullDisplayText = "anonymous")]

        public string UserName{ get; set; }

        public IEnumerable Validate(ValidationContext validationContext)
            if (Rating < 2 && UserName.ToLower().StartsWith("cookies"))
                yield return new ValidationResult("Sorry, cookies, you can't do this");

Summer Season – The season of flip-flops

Summer Season

“nature poems about summer”

Summer season is starting, I found an interesting poem to start your season.

Summer is the stuff of dreams. When adults sit at their desks, and children sit in school, they dream of summer. Summer is the time of infinite fun. The day seems to last forever, and the fun never stops. It is a time of romance, excitement and an enhanced enjoyment of life. Somehow summer never seems to last long enough. It is always over before we get a chance to fully experience its power. This is true of all things wonderful. They always seem too short.

Read more at this Source.

Come over to the beach and take in a wave and enjoy the beautiful sun rays.

April and Spring with poetry

April welcome Spring.

April Poetry.

Spring is a miraculous experience. The whole world comes alive after the winter in which it seemed that everything was dead. The world comes filled with color and the scent of delicious greenery. The world that seemed so dull and cold has come alive once again. Little did we know that beneath the cold hard ground the plants and trees were preparing for rebirth. Spring gives us hope for rejuvenation in our own lives as well. Spring is a time to renew the excitement and zest for life that lives inside.

The original poem is found at this Source.

This month brings flowers and bloom. Here are some holidays missing from the month of April:

  • National Humor Month
  • International Guitar Month
  • Keep America Beautiful Month
  • Lawn and Garden Month
  • National Poetry Month
  • National Pecan Month
  • National Welding Month
  • Records and Information Management Month
  • Stress Awareness Month

You can find more holidays here.

Ruins Magic Growing with members

[spb_column width=”1/4″ el_position=”first”] [/spb_column] [spb_column width=”1/2″] [spb_raw_js width=”1/1″ el_position=”first last”] JTNDc2NyaXB0JTIwYXN5bmMlMjBzcmMlM0QlMjIlMkYlMkZwYWdlYWQyLmdvb2dsZXN5bmRpY2F0aW9uLmNvbSUyRnBhZ2VhZCUyRmpzJTJGYWRzYnlnb29nbGUuanMlMjIlM0UlM0MlMkZzY3JpcHQlM0UlMEElM0MlMjEtLSUyMExlYWRlciUyMC0tJTNFJTBBJTNDaW5zJTIwY2xhc3MlM0QlMjJhZHNieWdvb2dsZSUyMiUwQSUyMCUyMCUyMCUyMCUyMHN0eWxlJTNEJTIyZGlzcGxheSUzQWlubGluZS1ibG9jayUzQndpZHRoJTNBNzI4cHglM0JoZWlnaHQlM0E5MHB4JTIyJTBBJTIwJTIwJTIwJTIwJTIwZGF0YS1hZC1jbGllbnQlM0QlMjJjYS1wdWItNjYyMjUxMjE3NzA2Nzg5NiUyMiUwQSUyMCUyMCUyMCUyMCUyMGRhdGEtYWQtc2xvdCUzRCUyMjcwMDM4MTE4NzAlMjIlM0UlM0MlMkZpbnMlM0UlMEElM0NzY3JpcHQlM0UlMEElMjhhZHNieWdvb2dsZSUyMCUzRCUyMHdpbmRvdy5hZHNieWdvb2dsZSUyMCU3QyU3QyUyMCU1QiU1RCUyOS5wdXNoJTI4JTdCJTdEJTI5JTNCJTBBJTNDJTJGc2NyaXB0JTNF [/spb_raw_js] [/spb_column] [spb_column width=”1/4″ el_position=”last”] [/spb_column] [blank_spacer height=”12px” width=”1/1″ el_position=”first last”] [spb_text_block title=”Note” icon=”fa fa-bell” pb_margin_bottom=”no” pb_border_bottom=”no” width=”3/4″ el_position=”first”]

Ruins Magic and members runes of magic

Friend leaving Maintains
Running instances
Why should somebody come here?
Keeping people happy
Accept the fact of people leaving

[/spb_text_block] [spb_text_block title=”Game” icon=”fa fa-gamepad” pb_margin_bottom=”no” pb_border_bottom=”no” width=”1/4″ el_position=”last”]

Play Runes of Magic

[/spb_text_block] [blank_spacer height=”27px” width=”1/1″ el_position=”first last”] [spb_text_block title=”SoundCloud” icon=”fa fa-bell” pb_margin_bottom=”no” pb_border_bottom=”no” width=”1/1″ el_position=”first last”]

Ruins Magic

Back in the day when I was playing Ruins of Magic, I would imagine a routine that would become common out most MMO ( A massively multiplayer online game) life. The items I mentioned above are things you would be responsible for while being in a small guild. I would point to reputation because it’s something that branches off to recruiting and members. Guild mates must keep it professional and be polite. Many of my friends were older folks who had long stressful days, who worked and then came on to play the game. Nobody is looking for drama and hate.

The key was not to think about these items as a task or job, but to tie in a fun factor and have some sort of reward system. Running instances (bosses areas and quests) for people who are doing well with their ranks. Giving out equipment and money to guild mates. Pointing out helpful hints and solutions to issues.  Ruins of Magic had many guilds that were able to maintain this, but if you were a smaller guild, then your resources were strained and it was hard to maintain this effort. Ultimately, a lot of people found themselves moving to other growing games.

A guild master has to be able to answer the question about why this guild and not some other one. Bigger guilds mostly state facts clearly about the environment and the community.

An example of a recruiting message in Runes of Magic:

Our guild FreeDestiny is Recruiting players lvls 30-77.(If your lvl 1-29 we will inv if your active in the game)

We have siege war every night and run dungeons everyday.
We have Vent. nice people they will answer any questions you might have
Run Goblin Games Every Day.

If your Interested Msg “karinol”,”korilyn”,”Dorial”,”Ulamog” if all else fails msg “Ruskie” he’s on all night.
he on from 10 am – 10 pm EST
If you’re wondering if were a Nooby guild,
Majority of our guild are/is lvl 50-77 and we have over 120 members
I wouldn’t recommend staying to long in games like Runes of Magic and I would try not to get too attached to any guild. However, I understand that it is hard to play against friends and not helping them.

Good luck on your adventure and your guild!

[/spb_text_block] [blank_spacer height=”9px” width=”1/1″ el_position=”first last”] [spb_video title=”See Also” link=”” full_width=”no” width=”1/1″ el_position=”first last”] [blank_spacer height=”30px” width=”1/1″ el_position=”first last”]