Esempio n. 1
0
 public void TestHomeAddReward()
 {
     UserRewardsViewModel ur = new UserRewardsViewModel();
     ur.RewardID = 1;
     ur.UserID = 7;
     var result = home.AddRewardToUser(ur);
     Assert.AreEqual(true, result is RedirectToRouteResult);
 }
Esempio n. 2
0
 public ActionResult AddRewardToUser()
 {
     try
     {
         UserRewardsViewModel Reward = new UserRewardsViewModel();
         return View("Add",Reward);
     }
     catch (ValidationException ex)
     {
         return Content(ex.Message);
     }
 }
Esempio n. 3
0
 public ActionResult AddRewardToUser(UserRewardsViewModel UR)
 {
     try
     {
         if ((ModelState.IsValidField("UserID")) && (ModelState.IsValidField("RewardID")))
         {
             Data.AddRewardToUser(UR.UserID, UR.RewardID);
             return RedirectToAction("Index");
         }
         else return View(UR);
     }
     catch
     {
         return RedirectToAction("Index");
     }
 }
Esempio n. 4
0
        /// <summary>
        /// вывод списка юзеров и их наград
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            try
            {
                List<UserRewardsViewModel> URLIst = new List<UserRewardsViewModel>();
                var URBLL = Data.UserRewardsList();

                foreach (var ur in URBLL)
                {
                    UserRewardsViewModel list = new UserRewardsViewModel();
                    UserViewModel u = new UserViewModel();
                    List<RewardViewModel> lr = new List<RewardViewModel>();
                    u.Name = ur.User.Name;
                    u.UserID = ur.User.UserID;
                    u.Photo = ur.User.Photo;
                    list.User = u;
                    foreach (var r in ur.Reward)
                    {
                        RewardViewModel rew = new RewardViewModel();
                        rew.RewardID = r.RewardID;
                        rew.Title = r.Title;
                        rew.Description = r.Description;
                        rew.Image = r.Image;
                        lr.Add(rew);
                    }
                    list.Reward = lr;
                    URLIst.Add(list);
                }

                List<RewardViewModel> RList = new List<RewardViewModel>();
                var RBLL = Data.RewardsList();
                foreach (var r in RBLL)
                {
                    RewardViewModel list = new RewardViewModel();
                    list.RewardID = r.RewardID;
                    list.Title = r.Title;
                    RList.Add(list);
                }
                List<UserViewModel> UList = new List<UserViewModel>();
                var UBLL = Data.UsersList();
                foreach (var u in UBLL)
                {
                    UserViewModel list = new UserViewModel();
                    list.UserID = u.UserID;
                    list.Name = u.Name;
                    UList.Add(list);
                }
                ViewBag.RewardList = RList;
                ViewBag.UserList = UList;
                return View("Index", URLIst);
            }
            catch (ValidationException ex)
            {
                return Content(ex.Message);
            }
        }