public async Task SaveCommentsPolicyAsync(CommentsPolicy policy) { using (var transaction = db.Database.BeginTransaction()) { await db.CommentsPolicies.Where(x => x.CourseId == policy.CourseId).DeleteAsync().ConfigureAwait(false); db.CommentsPolicies.Add(policy); await db.SaveChangesAsync().ConfigureAwait(false); transaction.Commit(); } }
public async Task SaveCommentsPolicy(CommentsPolicy policy) { using (var transaction = db.Database.BeginTransaction()) { var query = db.CommentsPolicies.Where(x => x.CourseId == policy.CourseId); if (query.Any()) { db.CommentsPolicies.Remove(query.First()); await db.SaveChangesAsync(); } db.CommentsPolicies.Add(policy); await db.SaveChangesAsync(); transaction.Commit(); } }
private async Task <bool> CanCommentNowAsync(string userId, string courseId, CommentsPolicy commentsPolicy) { /* Instructors have unlimited comments */ if (await courseRolesRepo.HasUserAccessToCourseAsync(userId, courseId, CourseRoleType.Instructor).ConfigureAwait(false)) { return(true); } var isUserAddedMaxCommentsInLastTime = await commentsRepo.IsUserAddedMaxCommentsInLastTimeAsync( userId, commentsPolicy.MaxCommentsCountInLastTime, commentsPolicy.LastTimeForMaxCommentsLimit ).ConfigureAwait(false); return(!isUserAddedMaxCommentsInLastTime); }
private async Task <bool> CanCommentHereAsync(string userId, string courseId, bool isReply, CommentsPolicy commentsPolicy) { var isInstructor = await courseRolesRepo.HasUserAccessToCourseAsync(userId, courseId, CourseRoleType.Instructor).ConfigureAwait(false); if (!isInstructor && !commentsPolicy.IsCommentsEnabled) { return(false); } if (isReply && !isInstructor && commentsPolicy.OnlyInstructorsCanReply) { return(false); } return(true); }