Example #1
0
        public async Task <IActionResult> AddNewUserAsync([FromBody] AddUserAc newUserAc)
        {
            ApplicationUser existingUserWithEmail = await _userManager.FindByEmailAsync(newUserAc.Email);

            if (existingUserWithEmail != null)
            {
                return(Ok(new { Message = "User already exist with this email", HasError = true }));
            }

            if (ModelState.IsValid)
            {
                ApplicationUser currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

                await _userManagementRepository.AddNewUserAsync(newUserAc, currentUser);

                return(Ok(new { Message = "User has been created successfully" }));
            }
            else
            {
                if (string.IsNullOrEmpty(newUserAc.Name))
                {
                    return(Ok(new { Message = "User's Name can't be null or empty", HasError = true }));
                }
                else if (string.IsNullOrEmpty(newUserAc.Password))
                {
                    return(Ok(new { Message = "User's Password can't be null or empty", HasError = true }));
                }
                else if (newUserAc.UserGroupIdList.Count == 0)
                {
                    return(Ok(new { Message = "Please select user role", HasError = true }));
                }
                else
                {
                    return(Ok(new { Message = "User's Institute can't be null or empty", HasError = true }));
                }
            }
        }