Example #1
0
        public async Task <IActionResult> Register([FromBody] RegisterDto registerDto)
        {
            registerDto.Username = registerDto.Username.ToLower();
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (await _authServices.MemberExists(registerDto.Username, registerDto.EmailAddress))
                {
                    return(BadRequest("Username or Email Address exists, Choose anothe name"));
                }
                var memberToCreate = new Member
                {
                    Username     = registerDto.Username,
                    EmailAddress = registerDto.EmailAddress,
                    ColorTypeID  = registerDto.ColorTypeID,
                    Gender       = registerDto.Gender,
                    Firstname    = registerDto.Firstname,
                    Middlename   = registerDto.Middlename,
                    Lastname     = registerDto.Lastname,
                    DateOfBirth  = registerDto.DateOfBirth,
                };
                var createMember = await _authServices.Register(memberToCreate, registerDto.Password);

                return(StatusCode(201, $" Hello {registerDto.Username}, Your Registration was Successful."));
            }
            catch (Exception ex)
            {
                return(BadRequest($"{ex.Message}, Error!- Member cannot be created, Contact Administrator"));
            }
        }