FluentValidation – build strongly-typed validation rules in .NET


Install the FluentValidation .NET library for validation.

Below is our sample Contact class and its corresponding validator class.

The validator class needs to inherit AbstractValidator<Contact> and define the validation rules in the constructor using the RuleFor method.

Instantiate the validator class, and pass the object to be validated.

Here we have passed incorrect values for all the properties of the contact.

The ValidationResult holds all the validation error details.

Give it a try – https://docs.fluentvalidation.net/en/latest/index.html

Hope it helps..

using FluentValidation;
using FluentValidation.Results;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FluentValidator
{
    class Program
    {
        static void Main(string[] args)
        {
            var myContact = new Contact();
            var contactValidator = new ContactValidator();

            myContact.FirstName = "";
            myContact.LastName = "Lei";
            myContact.Email = "aa.gcom";
            myContact.Age = 10;
            myContact.FamilyStatusCode = (FamilyStatusCode)Enum.Parse(typeof(FamilyStatusCode),"5");

            ValidationResult result = contactValidator.Validate(myContact);
        }
    }

    class Contact
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }
        public int Age { get; set; }
        public FamilyStatusCode FamilyStatusCode { get; set; }
    }

    enum FamilyStatusCode
    {
        Single = 1,
        Married = 2,
        Divorced = 3,
        Widowed = 4
    }

    class ContactValidator : AbstractValidator<Contact>
    {
       public ContactValidator()
        {
            // First Name should not be null
            RuleFor(contact => contact.FirstName).NotEmpty();
            // Last Name should not be null and minimum length should be 4
            RuleFor(contact => contact.LastName).NotNull().MinimumLength(4);
            // Email Address Validation
            RuleFor(contact => contact.Email).EmailAddress();
            // Age should be between 18 to 60
            RuleFor(contact => contact.Age).ExclusiveBetween(18, 60);
            // Family Status Code Enum should be a valid value
            RuleFor(contact => contact.FamilyStatusCode).IsInEnum();

        }
    }
}
Advertisements
Advertisement

How to – Change the display name of user in Microsoft 365


Recently we had to update the display name of one of the users.

Below are the steps to achieve the same –

Login to Microsoft 365 admin center with System Administrator account.

Navigate to Active Users

Select the user, click on ellipsis () and select Manage Contact Information

Edit the details and click on Save changes.

After successful update.

We can see the display name changed for the user and the same reflected at other places immediately.

Hope it helps..

Advertisements

Fixed – Trusted Platform Module has malfunctioned, with Error Code 80090030 in Microsoft Teams


Recently while trying to login into Microsoft Teams we got the below error –


  • As suggested in the different articles – we didn’t find any Teams Account Credentials to be removed.


  • Windows update also didn’t fix the issue.
  • Neither updating the driver from Devic Manager.


 

 

 

 

 

 

 

  • Creating EnableADAL key with Value data 0 also didn’t work.

Navigate to HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Common

Expand the Common key and select the Identity subkey. Right-click on the space on the right side and go to “New > DWORD (32-bit) Value.”

Right-click on the newly created value and select Rename. Type EnableADAL.

By default, the Value Data of EnableADAL should be 0. If not, double-click on it and enter 0 in its Value Data. Click OK to save the changes.


  • tpm.msc è Prepare the TMP and Clear TPM also didn’t work.

Cryptographic Services were also running properly.

In our case, we were getting below additional error.

Eventually disconnecting the work account worked in our case.

https://nishantrana.me/2022/04/18/fixed-sign-in-required-your-device-is-having-problems-with-your-work-or-school-account-sign-in-again-to-access-your-organizations-resources/

The other solution that worked temporarily for us was to uninstall and reinstall the Microsoft Teams.

https://www.microsoft.com/en-ww/microsoft-teams/download-app

Hope it helps..

Advertisements

Fixed – Sign in required. Your device is having problems with your work or school account. Sign in again to access your organizations resources


Recently we were getting the below pop up in Windows every time after restart.

The fix was to Disconnect the work / school account.

Navigate to Accounts è Access work or school

Click on Disconnect the work or school acount.

That fixed the issue for us.

Hope it helps..

 

Advertisements

Fixed- Noisy Fan in Windows 10 / 11


Recently my laptop started making lot of noise continuously, for no obvious reason (it was not getting heated).

One solution that helped a lot was to set

Fan Always On = Disabled in System Configuration setting in the BIOS Setup.

Also came to know about this wonderful utility –

https://www.almico.com/speedfan.php

Advanced Fan Control

And lastly cleaning the dust

Hope it helps ..

Advertisements

How to – Quickly generate sample data


At times we need to quickly generate sample data for some of our development, testing, reports needs.

Through https://generatedata.com/ we can do it in matter of seconds.

Just select the data / types and the format and click on Generate

For e.g. we have selected Name, Phone, Email, Country type and CSV as the data format.

We can further edit the selection, preview the data, and save and generate the data.

Clicking on Generate, allows us to specify the number of rows.

We can than download the file.


Generated Sample Data –

Also check – https://nishantrana.me/2020/05/26/using-data-spawner-component-ssis-to-generate-sample-data-in-dynamics-365/

Hope it helps..

Advertisements
%d bloggers like this: