Exemple #1
0
        public async Task <bool> LikePost(int userId, int id, float rate, CancellationToken cancellationToken)
        {
            if (rate < 0 || rate > 5)
            {
                throw new DataException("مقدار امتیاز نامعتبر است");
            }

            var isLike = await TableNoTracking
                         .AnyAsync(a => !a.VersionStatus.Equals(2) && a.UserId.Equals(userId) && a.PostId.Equals(id), cancellationToken);

            if (isLike)
            {
                throw new DataException("این مطلب قبلا امتیاز دهی شده است");
            }

            await AddAsync(new Like
            {
                PostId = id,
                Rate   = rate,
                UserId = userId,
                Time   = DateTimeOffset.Now
            }, cancellationToken);

            return(true);
        }
Exemple #2
0
        public async Task AddAsync(User user, string password, CancellationToken cancellationToken)
        {
            var exist = await TableNoTracking.AnyAsync(a => a.UserName == user.UserName);

            if (exist)
            {
                throw new BadRequestException("نام کاربری تکراری است");
            }
            var passwordHash = SecurityHelper.GetSha256Hash(password);

            user.PasswordHash = passwordHash;
            await base.AddAsync(user, cancellationToken);
        }
Exemple #3
0
        public async Task AddAsync(User user, string password, CancellationToken cancellationToken)
        {
            var exists = await TableNoTracking.AnyAsync(p => p.UserName == user.UserName);

            if (exists)
            {
                throw new BadRequestException("Username is duplicate");
            }

            var passwordHash = SecurityHelper.GetSha256Hash(password);

            user.PasswordHash = passwordHash;
            await base.AddAsync(user, cancellationToken);
        }
Exemple #4
0
        public async Task AddAsync(User user, string password, CancellationToken cancellationToken)
        {
            if (await TableNoTracking.AnyAsync(u => u.UserName == user.UserName, cancellationToken: cancellationToken))
            {
                throw new BadRequestException("نام کاربری تکراری است");
            }

            if (await TableNoTracking.AnyAsync(u => u.Email == user.Email, cancellationToken: cancellationToken))
            {
                throw new BadRequestException("ایمیل تکراری است");
            }

            var passwordHash = SecurityHelper.GetSha256Hash(password);

            user.PasswordHash  = passwordHash;
            user.SecurityStamp = Guid.NewGuid();
            await base.AddAsync(user, cancellationToken);
        }
 public async Task <bool> IsExist(int packageId, int productId)
 => await TableNoTracking.AnyAsync(a => a.ProductId == productId && a.PackageId == packageId);
Exemple #6
0
 public async Task <bool> IsExistAsync(string tokenKey)
 {
     return(await TableNoTracking.AnyAsync(t => string.Equals(tokenKey, t.TokenKey)));
 }
Exemple #7
0
 public async Task <bool> IsExistAsync(string nameId)
 {
     return(await TableNoTracking.AnyAsync(u => string.Equals(nameId, u.NameId)));
 }
Exemple #8
0
 /// <summary>
 /// Check isExist by name async
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public async Task <bool> IsExistAsync(string name)
 {
     return(await TableNoTracking.AnyAsync(s => string.Equals(s.Name, name)));
 }
Exemple #9
0
 /// <summary>
 /// Is exist check by name async
 /// </summary>
 /// <param name="appName"></param>
 /// <returns></returns>
 public async Task <bool> IsExistByNameAsync(string appName)
 {
     return(await TableNoTracking.AnyAsync(a => a.Name.Equals(appName)));
 }