public async Task <IActionResult> DeleteActivityByName(DeleteActivitiesByNameInputModel model) { if (this.ModelState.IsValid) { string activityText = model.ActivityName; string activityName = string.Join(string.Empty, activityText.Split(" ")); UserActionsType actionValue = (UserActionsType)Enum.Parse(typeof(UserActionsType), activityName); bool isRemoved = await this.dbUsageService.RemoveActivitiesByName(actionValue); if (isRemoved) { this.TempData["Success"] = string.Format(SuccessMessages.SuccessfullyRemoveActionByName, activityText); } else { this.TempData["Error"] = string.Format(ErrorMessages.NoActionsByGivenName, activityText); } } else { this.TempData["Error"] = ErrorMessages.InvalidInputModel; } return(this.RedirectToAction("DeleteUsersActivities", "DbUsage")); }
public void AddUserAction(ApplicationUser user, UserActionsType action, ApplicationUser userPost) { if (this.db.UserActions .Any(x => x.Action == action && x.ApplicationUserId == userPost.Id && x.PersonUsername == userPost.UserName && x.FollowerUsername == user.UserName)) { var targetAction = this.db.UserActions .FirstOrDefault(x => x.Action == action && x.ApplicationUserId == userPost.Id && x.PersonUsername == userPost.UserName && x.FollowerUsername == user.UserName); targetAction.ActionDate = DateTime.UtcNow; targetAction.ActionStatus = UserActionsStatus.Unread; } else { this.db.UserActions.Add(new UserAction { Action = action, ActionDate = DateTime.UtcNow, ApplicationUserId = userPost.Id, PersonUsername = userPost.UserName, FollowerUsername = user.UserName, ProfileImageUrl = user.ImageUrl, ActionStatus = UserActionsStatus.Unread, }); } }
public void AddLikeUnlikeActivity(ApplicationUser user, Post post, UserActionsType action, ApplicationUser postUser) { if (this.db.UserActions .Any(x => x.PostId == post.Id && x.ApplicationUserId == user.Id && x.PersonUsername == user.UserName && x.FollowerUsername == postUser.UserName && x.Action == action)) { var targetAction = this.db.UserActions .FirstOrDefault(x => x.PostId == post.Id && x.ApplicationUserId == user.Id && x.PersonUsername == user.UserName && x.FollowerUsername == postUser.UserName && x.Action == action); targetAction.ActionDate = DateTime.UtcNow; targetAction.ActionStatus = UserActionsStatus.Unread; } else { this.db.UserActions.Add(new UserAction { Action = action, ActionDate = DateTime.UtcNow, ApplicationUserId = user.Id, PersonUsername = user.UserName, FollowerUsername = postUser.UserName, ProfileImageUrl = postUser.ImageUrl, PostId = post.Id, PostTitle = post.Title, PostContent = post.ShortContent, ActionStatus = UserActionsStatus.Unread, }); } }
public async Task <bool> RemoveActivitiesByName(UserActionsType actionValue) { var allActions = this.db.UserActions.Where(x => x.Action == actionValue).ToList(); if (allActions.Count() == 0) { return(false); } this.db.UserActions.RemoveRange(allActions); await this.db.SaveChangesAsync(); return(true); }
public void AddUserAction(ApplicationUser user, Post post, UserActionsType action, ApplicationUser postUser) { this.db.UserActions.Add(new UserAction { Action = action, ActionDate = DateTime.UtcNow, ApplicationUserId = user.Id, PersonUsername = user.UserName, FollowerUsername = postUser.UserName, ProfileImageUrl = postUser.ImageUrl, PostId = post.Id, PostTitle = post.Title, PostContent = post.ShortContent, }); }