コード例 #1
0
ファイル: CustomerDAL.cs プロジェクト: vinitasingh305/AMS
        public async Task <bool> AddCustomer(Customer customer)
        {
            try
            {
                if (customer != null)
                {
                    customer.CreatedDate = DateTime.Now;
                    await _assetDBContext.Customers.AddRangeAsync(customer);

                    await _assetDBContext.SaveChangesAsync();

                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
ファイル: AssetDAL.cs プロジェクト: vinitasingh305/AMS
        public async Task <bool> AddAsset(Asset asset)
        {
            try
            {
                if (asset != null)
                {
                    asset.CreatedDate = DateTime.Now;
                    await _assetDBContext.Assets.AddRangeAsync(asset);

                    await _assetDBContext.SaveChangesAsync();

                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
        public async Task <ActionResult <UserDTO> > Register(RegisterDTO registerDto)
        {
            if (await userExists(registerDto.Username))
            {
                return(BadRequest("This username is already registered!"));
            }

            using var hmac = new HMACSHA512();
            var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(registerDto.Password));
            var salt = hmac.Key;

            var user = new User
            {
                Username     = registerDto.Username.ToLower(),
                FirstName    = registerDto.Firstname,
                LastName     = registerDto.Lastname,
                Email        = registerDto.Email,
                Phone        = registerDto.Phone,
                Role         = registerDto.Role,
                PasswordHash = Convert.ToBase64String(hash),
                PasswordSalt = Convert.ToBase64String(salt)
            };

            _context.User.Add(user);
            await _context.SaveChangesAsync();

            return(new UserDTO
            {
                Username = user.Username,
                Firstname = user.FirstName,
                Lastname = user.LastName,
                Email = user.Email,
                Phone = user.Phone,
                Role = user.Role,
                Token = _tokenService.CreateToken(user)
            });
        }