예제 #1
0
        public ActionResult AddReward(RewardViewModel reward, HttpPostedFileBase file)
        {
            try
            {
                //Если введены поля Title и Description, то создаётся новая награда
                if ((ModelState.IsValidField("Title")) && (ModelState.IsValidField("Description")))
                {
                    RewardDTO RBLL = new RewardDTO();
                    RBLL.Title = reward.Title;
                    RBLL.Description = reward.Description;
                    if (file != null)
                    {
                        Stream stream = file.InputStream;
                        byte[] image = new byte[stream.Length];
                        stream.Read(image, 0, (int)stream.Length);
                        RBLL.Image = image;
                    }
                    else RBLL.Image = reward.Image;
                    Data.AddReward(RBLL);

                    return RedirectToAction("RList");
                }
                else return View(reward);
            }
            catch (ValidationException ex)
            {
                return Content(ex.Message);
            }
        }
예제 #2
0
 public ActionResult AddReward()
 {
     try
     {
         RewardViewModel Reward = new RewardViewModel();
         return View(Reward);
     }
     catch (ValidationException ex)
     {
         return Content(ex.Message);
     }
 }
예제 #3
0
 public ActionResult EditReward(int id)
 {
     try
     {
         var RBLL = Data.RewardsList().Find(r => r.RewardID == id);
         RewardViewModel reward = new RewardViewModel();
         reward.RewardID = RBLL.RewardID;
         reward.Title = RBLL.Title;
         reward.Description = RBLL.Description;
         reward.Image = RBLL.Image;
         return View(reward);
     }
     catch (ValidationException ex)
     {
         return Content(ex.Message);
     }
 }
예제 #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);
            }
        }
예제 #5
0
 public ActionResult RewardDetails(int RewardID)
 {
     var d = Data.RewardsList().Find(r => r.RewardID == RewardID);
     RewardViewModel detail = new RewardViewModel();
     detail.RewardID = d.RewardID;
     detail.Title = d.Title;
     detail.Description = d.Description;
     detail.Image = d.Image;
     return PartialView("RewardDetails", detail);
 }
예제 #6
0
        // GET: Reward
        /// <summary>
        /// список наград
        /// </summary>
        /// <returns></returns>
        public ActionResult RList()
        {
            try
            {
                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;
                    list.Description = r.Description;
                    list.Image = r.Image;
                    RList.Add(list);
                }

                return View(RList);
            }
            catch (ValidationException ex)
            {
                return Content(ex.Message);
            }
        }