コード例 #1
0
        public async Task <IActionResult> Create(ApplicationUserDto model)
        {
            try
            {
                var user = await _userService.Create(model);

                if (user == null)
                {
                    return(Ok(new ResultModel
                    {
                        Success = false,
                        Message = Constants.Users.CreateAccountFail
                    }));
                }

                return(Ok(new ResultModel
                {
                    Success = true,
                    Message = Constants.Users.CreateAccountSuccess
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new ResultModel
                {
                    Success = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #2
0
        // [ValidateAntiForgeryToken]
        public async Task Register(RegisterModelDto model)
        {
            var result = await _applicationUserService.Create(model);

            await Response.WriteAsync(JsonConvert.SerializeObject(result,
                                                                  new JsonSerializerSettings {
                Formatting = Formatting.Indented
            }
                                                                  ));
        }
コード例 #3
0
        public async Task <IActionResult> PostUser([FromBody] RegisterDto entity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ApplicationUser user = await _userService.Create(entity);

            return(Ok(user));
        }
コード例 #4
0
        public async Task <IActionResult> Create(CreateApplicationUserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Roles = _userService.GetRoles();
                return(View(model));
            }

            await _userService.Create(model);

            return(RedirectToAction("Index", "Home"));
        }
コード例 #5
0
        public async Task <IActionResult> Register(UserDTO userBody)
        {
            Console.WriteLine("trying");

            var result = await service.Create(userBody);

            if (result.Succedeed)
            {
                return(new OkObjectResult(result.Object));
            }

            Console.WriteLine($"result {result.Message}");

            return(BadRequest(result.Message));
        }
コード例 #6
0
        public IActionResult Register(UserRegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var emailControl = _userService.CheckEmail(model.Email);

                if (!emailControl)
                {
                    _userService.Create(new ApplicationUser
                    {
                        Email    = model.Email,
                        Name     = model.Name,
                        Password = model.Password,
                        RoleId   = 2,
                        Surname  = model.Surname
                    });

                    return(RedirectToAction("Login", "Account"));
                }
                ModelState.AddModelError("", "Email adresi zaten sistemde kayıtlı");
            }
            return(View(model));
        }
コード例 #7
0
        public async Task <IActionResult> CreateAsync([FromBody] UserViewModel userViewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var user = new CustomIdentityUser
                    {
                        FirstName = userViewModel.UserDto.FirstName,
                        LastName  = userViewModel.UserDto.LastName,
                        UserName  = userViewModel.UserDto.Email,
                        Email     = userViewModel.UserDto.Email,
                        AccountId = Guid.NewGuid(),
                        IsEnabled = true
                    };
                    var result = await userManager.CreateAsync(user, userViewModel.Password).ConfigureAwait(false);

                    if (result.Succeeded)
                    {
                        var selectedRoles = userViewModel.UserRoles.Where(p => p.Selected).Select(p => p.RoleName).ToList();
                        await userManager.AddToRolesAsync(user, selectedRoles);

                        await userManager.AddClaimAsync(user, new System.Security.Claims.Claim("FullName", string.Format("{0} {1}", userViewModel.UserDto.FirstName, userViewModel.UserDto.LastName)));

                        await userManager.AddClaimAsync(user, new System.Security.Claims.Claim("AccountId", user.AccountId.ToString()));

                        var currentUser = await userManager.GetUserAsync(HttpContext.User);

                        var userDto = new Helpdesk.Service.Dto.ApplicationUserDto()
                        {
                            CreatedUser      = currentUser.FirstName + " " + currentUser.LastName,
                            ModifiedUser     = currentUser.FirstName + " " + currentUser.LastName,
                            CreateDate       = DateTime.Now,
                            ModifyDate       = DateTime.Now,
                            FirstName        = userViewModel.UserDto.FirstName,
                            LastName         = userViewModel.UserDto.LastName,
                            TrIdentityNumber = userViewModel.UserDto.TrIdentityNumber,
                            Title            = userViewModel.UserDto.Title,
                            Email            = userViewModel.UserDto.Email,
                            MobileNumber     = userViewModel.UserDto.MobileNumber,
                            AccountId        = user.AccountId,
                            Address          = new Helpdesk.Model.Entities.Address(),
                            RecordStatus     = Helpdesk.Model.Enums.RecordStatus.A
                        };

                        var userId = applicationUserService.Create(userDto);

                        if (userViewModel.Companies == null)
                        {
                            return(Ok());
                        }
                        if (userViewModel.Companies.Count > 0)
                        {
                            companyAgentMappingService.Create(userViewModel.Companies, userId);
                        }

                        return(Ok());
                    }
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }

                    return(BadRequest(ModelState));
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                return(BadRequest());
            }
        }