Ejemplo n.º 1
0
        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 });
            }
        }
Ejemplo n.º 2
0
 public ActionResult ManageUserPoints(Guid id)
 {
     using (UnitOfWorkManager.NewUnitOfWork())
     {
         var user = MembershipService.GetUser(id);
         var viewModel = new ManageUsersPointsViewModel
         {
             AllPoints = _membershipUserPointsService.GetByUser(user).OrderByDescending(x => x.DateAdded).ToList(),
             User = user
         };
         return View(viewModel);
     }
 }