Beispiel #1
0
        public bool SaveJwt(string token, Guid uId)
        {
            var claimJwt = new ClaimJwt
            {
                Jwt    = token,
                UserId = uId
            };

            try
            {
                var claimJwtExists = _ctx.ClaimJwts.FirstOrDefault(x => x.UserId == uId);
                if (claimJwtExists == null)
                {
                    _ctx.Add(claimJwt);
                }
                else
                {
                    claimJwtExists.UserId = uId;
                    claimJwtExists.Jwt    = token;

                    _ctx.Entry(claimJwtExists).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                }
                _ctx.SaveChanges();
            }
            catch (Exception e)
            {
                var error = e;
                throw;
            }


            return(true);
        }
        public ActionResult register(LoginDto newUser)
        {
            User user = null;

            if (!String.IsNullOrWhiteSpace(newUser.NationalCode) &&
                !String.IsNullOrWhiteSpace(newUser.Password) &&
                UserUniqe(newUser.NationalCode))
            {
                byte[] passwordHash, passwordSalt;
                AuthHelper.CreatePasswordHash(newUser.Password, out passwordHash, out passwordSalt);
                user = new User
                {
                    NationalCode = newUser.NationalCode,
                    PasswordHash = passwordHash,
                    PasswordSalt = passwordSalt
                };

                _ctx.Add(user);
                _ctx.SaveChanges();
                return(Ok(user));
            }

            return(BadRequest("email is already taken"));
        }
Beispiel #3
0
 public void Create(Role role)
 {
     _prContext.Entry(role).State = Microsoft.EntityFrameworkCore.EntityState.Added;
     _prContext.SaveChanges();
 }
Beispiel #4
0
 public User Update(User user)
 {
     _ctx.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     _ctx.SaveChanges();
     return(user);
 }