public void TestHomeAddReward() { UserRewardsViewModel ur = new UserRewardsViewModel(); ur.RewardID = 1; ur.UserID = 7; var result = home.AddRewardToUser(ur); Assert.AreEqual(true, result is RedirectToRouteResult); }
public ActionResult AddRewardToUser() { try { UserRewardsViewModel Reward = new UserRewardsViewModel(); return View("Add",Reward); } catch (ValidationException ex) { return Content(ex.Message); } }
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"); } }
/// <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); } }