Esempio n. 1
0
        public async Task <IActionResult> KisiRegisterAsync([FromBody] KisiRegisterDto userForRegisterDto)
        {
            if (await _authRepository.IsKisiUsernameExistsAsync(userForRegisterDto.UserName))
            {
                ModelState.AddModelError("error", "Username already exists");
            }
            if (await _authRepository.IsKisiEmailExistsAsync(userForRegisterDto.Email))
            {
                ModelState.AddModelError("error", "Email already exists");
            }

            if (!ModelState.IsValid)
            {
                var HSC = HttpStatusCode.Conflict;                 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                return(StatusCode((int)HSC, new MyRestResponse(HSC, ModelState, userForRegisterDto, "userForRegisterDto")
                {
                    Description = "model state(ler) doldurulursa tatmin edici geri dönüşler ulaşabilir.",
                }));               // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            }

            var userToCreate = new Kisiler
            {
                KisiTipi = userForRegisterDto.KisiTipi,
                Email    = userForRegisterDto.Email,
                Username = userForRegisterDto.UserName
            };

            var createdUser = await _authRepository.KisiRegisterAsync(userToCreate, userForRegisterDto.Password);

            createdUser.RegisterDate   = DateTime.Now;
            createdUser.RegisterDateIP = "1.1.1.1";
            createdUser.Username       = _ControllersHelper.GetUsernameFromEmail(userToCreate.Email) + createdUser.IdE;
            int sonuc = await _authRepository.UpdateToKisiAsync(createdUser);

            if (sonuc > 0)
            {
                // evet user(kisi) yaratıldı. fakat KisiTipi ne göre ilişkili 1:1 alanları oluşturmadık.
                await this.EmailConfirmAsync(createdUser);

                // evet şimdi oluşturduk

                ModelState.AddModelError("error", "user yaratıldı.");
                var HSC = HttpStatusCode.Created;                 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                return(StatusCode((int)HSC, new MyRestResponse(HSC, ModelState, createdUser, "createdUser")
                {
                    Description = "user yaratıldı.",
                }));               // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            }
            else
            {
                ModelState.AddModelError("error", "user yaratılamadı!");
                var HSC = HttpStatusCode.NotModified;                 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                return(StatusCode((int)HSC, new MyRestResponse(HSC, ModelState, createdUser, "createdUser")
                {
                    Description = "user yaratılamadı!",
                }));               // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            }
        }
        public ActionResult KisiRegister([FromBody] KisiRegisterDto userForRegisterDto)
        {
            if (_authRepository.IsKisiUsernameExists(userForRegisterDto.UserName))
            {
                ModelState.AddModelError("error", "Username already exists");
            }
            if (_authRepository.IsKisiEmailExists(userForRegisterDto.Email))
            {
                ModelState.AddModelError("error", "Email already exists");
            }

            if (!ModelState.IsValid)
            {
                var HSC = HttpStatusCode.Conflict;                 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                return(StatusCode((int)HSC, new MyRestResponse(HSC, ModelState, userForRegisterDto, "userForRegisterDto")
                {
                    Description = "model state(ler) doldurulursa tatmin edici geri dönüşler ulaşabilir.",
                }));               // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            }

            Tuple <int, Kisiler> kisiyarat = KISIYARAT(userForRegisterDto, false);
            int sonuc       = kisiyarat.Item1;
            var createdUser = kisiyarat.Item2;

            if (sonuc > 0)
            {
                // evet user(kisi) yaratıldı. fakat KisiTipi ne göre ilişkili 1:1 alanları oluşturmadık.
                this.EmailConfirm(createdUser);
                // evet şimdi oluşturduk

                ModelState.AddModelError("error", "user yaratıldı.");
                var HSC = HttpStatusCode.Created;                 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                return(StatusCode((int)HSC, new MyRestResponse(HSC, ModelState, createdUser, "createdUser")
                {
                    Description = "user yaratıldı.",
                }));               // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            }
            else
            {
                ModelState.AddModelError("error", "user yaratılamadı!");
                var HSC = HttpStatusCode.NotModified;                 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                return(StatusCode((int)HSC, new MyRestResponse(HSC, ModelState, createdUser, "createdUser")
                {
                    Description = "user yaratılamadı!",
                }));               // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            }
        }
        private Tuple <int, Kisiler> KISIYARAT(KisiRegisterDto userForRegisterDto, bool EMconfirm)
        {
            var userToCreate = new Kisiler
            {
                KisiTipi = userForRegisterDto.KisiTipi,
                Email    = userForRegisterDto.Email,
                Username = userForRegisterDto.UserName
            };
            var createdUser = _authRepository.KisiRegister(userToCreate, userForRegisterDto.Password);

            createdUser.RegisterDate   = DateTime.Now;
            createdUser.RegisterDateIP = "1.1.1.1";
            createdUser.Username       = _ControllersHelper.GetUsernameFromEmail(userToCreate.Email);
            int sonuc = _authRepository.UpdateToKisi(createdUser);

            if (sonuc > 0 && EMconfirm)
            {
                this.EmailConfirm(createdUser);
            }

            return(new Tuple <int, Kisiler>(sonuc, createdUser));
        }