Beispiel #1
0
        public ActionResult Register(CreateAccountViewmodel model)
        {
            if (!ModelState.IsValid)
            {
                // om inte rätt format
                return(View(model));
            }

            postgres sql   = new postgres();
            bool     check = sql.SqlQueryExist("Select exists(SELECT users.username FROM public.users WHERE users.username = @par1);", postgres.list = new List <NpgsqlParameter>()
            {
                new NpgsqlParameter("@par1", model.User)
            });

            if (!check)
            {
                _accountService.RegisterNewUser(model.User, model.email, model.First_name, model.Last_name);
                return(RedirectToAction("Index", "Account"));
            }
            else
            {
                ModelState.AddModelError("", "Användarnamnet finns redan, Välj ett annat");
                return(View(model));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Create(CreateAccountViewmodel createAccount)
        {
            var account        = _mapper.Map <Account>(createAccount);
            var createdAccount = await _accountService.Create(account);

            var model = _mapper.Map <AccountViewmodel>(createdAccount);

            return(Created(Request.Path, model));
        }