/// <summary>Initializes the awaiter.</summary> /// <param name="value">The value to be awaited.</param> /// <param name="continueOnCapturedContext">The value to pass to ConfigureAwait.</param> internal ConfiguredTaskLikeAwaiter( TaskLike <TResult> value, bool continueOnCapturedContext) { _value = value; _continueOnCapturedContext = continueOnCapturedContext; }
static async Task NotAnAwait(string[] args) { var getValue1Task = GetValueTask(1); var getValue2Task = GetValueTask(2); await TaskLike.WhenAll(getValue1Task, getValue2Task); await TaskLike.When(getValue1Task, getValue2Task); var result1 = getValue1Task.Result; // Noncompliant // ^^^^^^^^^^^^^^^^^^^^ var result2 = getValue2Task.Result; // Noncompliant // ^^^^^^^^^^^^^^^^^^^^ }
static async Task BranchingWhenAll(string[] args, int intValue) { var getValue1Task = GetValueTask(1); var getValue2Task = GetValueTask(2); if (intValue == 41) { await TaskLike.WhenAll(getValue1Task, getValue2Task); } else { var result1 = getValue1Task.Result; // Noncompliant // ^^^^^^^^^^^^^^^^^^^^ var result2 = getValue2Task.Result; // Noncompliant // ^^^^^^^^^^^^^^^^^^^^ } }
public static void LikeTask(User user, int taskid) { if (ctx.TaskLikes.Any(l => l.UserId == user.Id && l.TaskId == taskid)) { List <TaskLike> likes = ctx.TaskLikes.Where(l => l.UserId == user.Id && l.TaskId == taskid).ToList(); ctx.TaskLikes.RemoveRange(likes); } else { TaskLike like = new TaskLike(); like.Task = ctx.Tasks.First(p => p.Id == taskid); like.TaskId = like.Task.Id; like.User = user; like.UserId = user.Id; ctx.TaskLikes.Add(like); if (like.Task.User.Id != user.Id) { Notification notification = new Notification(); notification.Date = DateTime.Now; notification.Type = NotificationType.TaskLike; notification.User = like.Task.User; notification.UserId = like.Task.User.Id; notification.Link = "/Home/Tasks"; notification.Message = "User " + user.Username + " liked your task"; ctx.Notifications.Add(notification); } } ctx.SaveChanges(); }
public LikeResult LikeTask(UserModel userModel, int taskId) { User user = ctx.Users.First(u => u.Id == userModel.Id); if (ctx.TaskLikes.Any(l => l.LikerId == user.Id && l.TaskId == taskId)) { List <TaskLike> likes = ctx.TaskLikes.Where(l => l.LikerId == user.Id && l.TaskId == taskId).ToList(); ctx.TaskLikes.RemoveRange(likes); ctx.SaveChanges(); return(LikeResult.Unliked); } else { TaskLike like = new TaskLike(); like.Task = ctx.Tasks.First(p => p.Id == taskId); like.TaskId = like.Task.Id; like.Liker = user; like.LikerId = user.Id; ctx.TaskLikes.Add(like); if (like.Task.Creator.Id != user.Id) { Notification notification = Notification.From(DateTime.Now, NotificationType.TaskLike, like.Task.Creator, user, "/Tasks/Id/" + taskId, "@" + user.Username + " оцінив ваше завдання"); ctx.Notifications.Add(notification); } ctx.SaveChanges(); return(LikeResult.Liked); } }
/// <summary>Initializes the awaiter.</summary> /// <param name="value">The value to be awaited.</param> internal TaskLikeAwaiter(TaskLike <TResult> value) { _value = value; }