Esempio n. 1
0
		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();
			}
		}
Esempio n. 2
0
		public CommentsPolicy GetCommentsPolicy(string courseId)
		{
			var policy = db.CommentsPolicies.FirstOrDefault(x => x.CourseId == courseId);
			if (policy == null)
				policy = new CommentsPolicy
				{
					CourseId = courseId,
				};
			return policy;
		}