Dotnet
Update User

Solution - Exception Classes

PRO
Outline

Solution: Create Exception Classes

In the Conduit.Models Project

Create the following custom exceptions in the Exception namespace:
  • DuplicateEmailException
  • DuplicateUserNameException
Create the a class called UpdateUser.cs in the Requests namespace with the following Properties:
 Visibility  |   Type     | Name     | Rules
=============================================================================================
   Public    |  String    | Email    | Valid Email, Max Length 50
   Public    |  String    | Password | Regex to Enforce: 1-Upper Case, 1-Lower Case, 1-Number
   Public    |  String    | UserName | Max Length 50
   Public    |  String    | Bio      | Max Length 200
   Public    |  String    | Image    | Max Length 200

Here's the code to the DuplicateEmailException.cs file:

using System;

namespace Conduit.Models.Exceptions
{
    public class DuplicateEmailException : Exception
    {
        public DuplicateEmailException(string message) : base(message)
        {

        }
    }
}

Here's the code to the DuplicateUserNameException.cs file:

using System;

namespace Conduit.Models.Exceptions
{
    public class DuplicateUserNameException : Exception
    {
        public DuplicateUserNameException(string message) : base(message)
        {

        }
    }
}

Here's the code to the UpdateUser.cs file:

using System.ComponentModel.DataAnnotations;

namespace Conduit.Models.Requests
{
    public class UpdateUser
    {
        [MaxLength(50, ErrorMessage = "User name max length is 50 characters.")]
        public string UserName { get; set; }

        [EmailAddress(ErrorMessage = "Email address must be valid.")]
        [MaxLength(50, ErrorMessage = "Email max length is 50 characters.")]
        public string Email { get; set; }

        [RegularExpression(@"^((?=.*[a-z])(?=.*[A-Z])(?=.*\d)).+$", ErrorMessage = "Password must contain 1 Lower-case, 1 Upper-case and 1 Numeric character.")]
        public string Password { get; set; }

        [MaxLength(200, ErrorMessage = "Bio max length is 200 characters.")]
        public string Bio { get; set; }

        [MaxLength(200, ErrorMessage = "Image max length is 200 characters.")]
        public string Image { get; set; }
    }
}
 

I finished! On to the next chapter