/// <summary> /// Add new point /// </summary> /// <param name="points"></param> /// <returns></returns> public MembershipUserPoints Add(MembershipUserPoints points) { if (points.Points != 0) { // Add Date points.DateAdded = DateTime.UtcNow; // Check this point has not already been awarded var canAddPoints = true; // Check to see if this has an id if (points.PointsForId != null) { var alreadyHasThisPoint = GetByUser(points.User).Any(x => x.PointsFor == points.PointsFor && x.PointsForId == points.PointsForId); canAddPoints = (alreadyHasThisPoint == false); } // If they can ad points let them if (canAddPoints) { return _context.MembershipUserPoints.Add(points); } } // If not just return the same one back return points; }
/// <summary> /// Add new point /// </summary> /// <param name="points"></param> /// <returns></returns> public MembershipUserPoints Add(MembershipUserPoints points) { if (points.Points != 0) { // Add Date points.DateAdded = DateTime.UtcNow; // Check this point has not already been awarded var canAddPoints = true; // Check to see if this has an id if (points.PointsForId != null) { var alreadyHasThisPoint = GetByUser(points.User).Any(x => x.PointsFor == points.PointsFor && x.PointsForId == points.PointsForId); canAddPoints = (alreadyHasThisPoint == false); } // If they can ad points let them if (canAddPoints) { return(_context.MembershipUserPoints.Add(points)); } } // If not just return the same one back return(points); }
/// <summary> /// Processes the user for the specified badge type /// </summary> /// <param name="badgeType"></param> /// <param name="user"></param> /// <returns>True if badge was awarded</returns> public bool ProcessBadge(BadgeType badgeType, MembershipUser user) { var databaseUpdateNeeded = false; var e = new BadgeEventArgs { User = user, BadgeType = badgeType }; EventManager.Instance.FireBeforeBadgeAwarded(this, e); if (!e.Cancel) { if (_badges.ContainsKey(badgeType)) { if (!RecentlyProcessed(badgeType, user)) { databaseUpdateNeeded = true; var badgeSet = _badges[badgeType]; foreach (var badgeMapping in badgeSet) { if (!BadgeCanBeAwarded(user, badgeMapping)) { continue; } // Instantiate the badge and execute the rule var badge = GetInstance <IBadge>(badgeMapping); // Award badge? if (badge != null && badge.Rule(user)) { // Re-fetch the badge otherwise system will try and create new badges! var dbBadge = _badgeRepository.Get(badgeMapping.DbBadge.Id); if (dbBadge.AwardsPoints != null && dbBadge.AwardsPoints > 0) { var points = new MembershipUserPoints { DateAdded = DateTime.UtcNow, Points = (int)dbBadge.AwardsPoints }; user.Points.Add(points); } user.Badges.Add(dbBadge); _activityService.BadgeAwarded(badgeMapping.DbBadge, user, DateTime.UtcNow); EventManager.Instance.FireAfterBadgeAwarded(this, new BadgeEventArgs { User = user, BadgeType = badgeType }); } } } } } return(databaseUpdateNeeded); }
public async Task <IPipelineProcess <MembershipUserPoints> > Delete(MembershipUserPoints points) { // Get the pipelines var pointsPipes = ForumConfiguration.Instance.PipelinesPointsDelete; // The model to process var piplineModel = new PipelineProcess <MembershipUserPoints>(points); // Add extended data piplineModel.ExtendedData.Add(Constants.ExtendedDataKeys.Username, HttpContext.Current.User.Identity.Name); // Get instance of the pipeline to use var pipeline = new Pipeline <IPipelineProcess <MembershipUserPoints>, MembershipUserPoints>(_context); // Register the pipes var allPointsPipes = ImplementationManager.GetInstances <IPipe <IPipelineProcess <MembershipUserPoints> > >(); // Loop through the pipes and add the ones we want foreach (var pipe in pointsPipes) { if (allPointsPipes.ContainsKey(pipe)) { pipeline.Register(allPointsPipes[pipe]); } } return(await pipeline.Process(piplineModel)); }
public void Update(MembershipUserPoints item) { // Check there's not an object with same identifier already in context if (_context.MembershipUserPoints.Local.Select(x => x.Id == item.Id).Any()) { throw new ApplicationException("Object already exists in context - you do not need to call Update. Save occurs on Commit"); } _context.Entry(item).State = EntityState.Modified; }
public ActionResult ManageUserPoints(ManageUsersPointsViewModel viewModel) { using (var uow = UnitOfWorkManager.NewUnitOfWork()) { // Repopulate viewmodel var user = MembershipService.GetUser(viewModel.Id); viewModel.AllPoints = _membershipUserPointsService.GetByUser(user).OrderByDescending(x => x.DateAdded).ToList(); viewModel.User = user; if (viewModel.Amount > 0) { // Add the new points var newPoints = new MembershipUserPoints { DateAdded = DateTime.UtcNow, Notes = viewModel.Note, Points = (int)viewModel.Amount, PointsFor = PointsFor.Manual, User = user }; _membershipUserPointsService.Add(newPoints); try { uow.Commit(); ShowMessage(new GenericMessageViewModel { Message = "Points Added", MessageType = GenericMessages.success }); } catch (Exception ex) { uow.Rollback(); LoggingService.Error(ex); ShowMessage(new GenericMessageViewModel { Message = "There was an error adding the points", MessageType = GenericMessages.danger }); } } return(RedirectToAction("ManageUserPoints", new { id = user.Id })); } }
/// <summary> /// Processes the user for the specified badge type /// </summary> /// <param name="badgeType"></param> /// <param name="user"></param> /// <returns>True if badge was awarded</returns> public bool ProcessBadge(BadgeType badgeType, MembershipUser user) { var databaseUpdateNeeded = false; var e = new BadgeEventArgs { User = user, BadgeType = badgeType }; EventManager.Instance.FireBeforeBadgeAwarded(this, e); if (!e.Cancel) { if (_badges.ContainsKey(badgeType)) { if (!RecentlyProcessed(badgeType, user)) { databaseUpdateNeeded = true; var badgeSet = _badges[badgeType]; foreach (var badgeMapping in badgeSet) { if (!BadgeCanBeAwarded(user, badgeMapping)) { continue; } // Instantiate the badge and execute the rule var badge = GetInstance <IBadge>(badgeMapping); if (badge != null) { var dbBadge = _badgeRepository.Get(badgeMapping.DbBadge.Id); // Award badge? if (badge.Rule(user)) { // Re-fetch the badge otherwise system will try and create new badges! if (dbBadge.AwardsPoints != null && dbBadge.AwardsPoints > 0) { var points = new MembershipUserPoints { Points = (int)dbBadge.AwardsPoints, PointsFor = PointsFor.Badge, PointsForId = dbBadge.Id, User = user }; _membershipUserPointsService.Add(points); } user.Badges.Add(dbBadge); _activityService.BadgeAwarded(badgeMapping.DbBadge, user, DateTime.UtcNow); EventManager.Instance.FireAfterBadgeAwarded(this, new BadgeEventArgs { User = user, BadgeType = badgeType }); } //else //{ // // If we get here the user should not have the badge // // Remove the badge if the user no longer has the criteria to be awarded it // // and also remove any points associated with it. // user.Badges.Remove(dbBadge); // _membershipUserPointsService.Delete(user, PointsFor.Badge, dbBadge.Id); //} } } } } } return(databaseUpdateNeeded); }
public void Delete(MembershipUserPoints points) { _context.MembershipUserPoints.Remove(points); }
/// <summary> /// Add new point /// </summary> /// <param name="points"></param> /// <returns></returns> public MembershipUserPoints Add(MembershipUserPoints points) { points.DateAdded = DateTime.UtcNow; return(_membershipUserPointsRepository.Add(points)); }
public void Delete(MembershipUserPoints points) { _membershipUserPointsRepository.Delete(points); }
/// <summary> /// Processes the user for the specified badge type /// </summary> /// <param name="badgeType"></param> /// <param name="user"></param> /// <returns>True if badge was awarded</returns> public async Task <bool> ProcessBadge(BadgeType badgeType, MembershipUser user) { var databaseUpdateNeeded = false; var e = new BadgeEventArgs { User = user, BadgeType = badgeType }; EventManager.Instance.FireBeforeBadgeAwarded(this, e); if (!e.Cancel) { try { if (_badges.ContainsKey(badgeType)) { if (!RecentlyProcessed(badgeType, user)) { databaseUpdateNeeded = true; var badgeSet = _badges[badgeType]; foreach (var badgeMapping in badgeSet) { if (!BadgeCanBeAwarded(user, badgeMapping)) { continue; } // Instantiate the badge and execute the rule IBadge badge; if (badgeMapping.BadgeClassInstance != null) { badge = badgeMapping.BadgeClassInstance; } else { badgeMapping.BadgeClassInstance = UnityHelper.Container.Resolve(badgeMapping.BadgeClass) as IBadge; badge = badgeMapping.BadgeClassInstance; } if (badge != null) { var dbBadge = Get(badgeMapping.DbBadge.Id); // Award badge? if (badge.Rule(user)) { // Re-fetch the badge otherwise system will try and create new badges! if (dbBadge.AwardsPoints != null && dbBadge.AwardsPoints > 0) { var points = new MembershipUserPoints { Points = (int)dbBadge.AwardsPoints, PointsFor = PointsFor.Badge, PointsForId = dbBadge.Id, User = user }; var pointsAddResult = await _membershipUserPointsService.Add(points); if (!pointsAddResult.Successful) { _loggingService.Error(pointsAddResult.ProcessLog.FirstOrDefault()); return(false); } } user.Badges.Add(dbBadge); //_activityService.BadgeAwarded(badgeMapping.DbBadge, user, DateTime.UtcNow); var badgeActivity = BadgeActivity.GenerateMappedRecord(badgeMapping.DbBadge, user, DateTime.UtcNow); _context.Activity.Add(badgeActivity); EventManager.Instance.FireAfterBadgeAwarded(this, new BadgeEventArgs { User = user, BadgeType = badgeType }); } //else //{ // // If we get here the user should not have the badge // // Remove the badge if the user no longer has the criteria to be awarded it // // and also remove any points associated with it. // user.Badges.Remove(dbBadge); // _membershipUserPointsService.Delete(user, PointsFor.Badge, dbBadge.Id); //} } } } } } catch (Exception ex) { _loggingService.Error(ex); } } return(databaseUpdateNeeded); }
public void Delete(MembershipUserPoints item) { _context.MembershipUserPoints.Remove(item); }
public MembershipUserPoints Add(MembershipUserPoints points) { _context.MembershipUserPoints.Add(points); return(points); }