Пример #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
 /// <summary>
 /// добавление наград
 /// </summary>
 /// <param name="newR">новая награда</param>
 /// <returns></returns>
 public bool AddReward(RewardDTO newR)
 {
     try
     {
         Reward RewardDAL = new Reward();
         RewardDAL.Title = newR.Title;
         RewardDAL.Description = newR.Description;
         RewardDAL.Image = newR.Image;
         if (Data.AddReward(RewardDAL) == true)
             return true;
         else throw new ValidationException("Ваш запрос не был обработан", "");
     }
     catch (ArgumentException ex)
     {
         throw new ValidationException(ex.Message, ex.ParamName);
     }
 }
Пример #3
0
        /// <summary>
        /// список юзеров и их наград
        /// </summary>
        /// <returns></returns>
        public List<UserRewardsDTO> UserRewardsList()
        {
            try
            {
                List<UserRewardsDTO> UsersRew = new List<UserRewardsDTO>();
                var URDAL = Data.UserRewardsList();

                for (int i = 0; i < URDAL.Count; i++)
                {
                    UserRewardsDTO ur = new UserRewardsDTO();
                    UserDTO u = new UserDTO();
                    List<RewardDTO> lr= new List<RewardDTO>();
                    u.UserID = URDAL[i].User.UserID;
                    u.Name = URDAL[i].User.Name;
                    u.Photo = u.Photo;
                    foreach (var ur1 in URDAL)
                    {
                        if ((ur1.User.UserID == u.UserID)&&(UsersRew.Find(x => x.User.UserID == ur1.User.UserID) == null))
                        {
                            RewardDTO r = new RewardDTO();
                            r.Title = ur1.Reward.Title;
                            r.RewardID = ur1.Reward.RewardID;
                            r.Description = ur1.Reward.Description;
                            r.Image = ur1.Reward.Image;
                            lr.Add(r);
                        }
                    }
                    if (lr.Count > 0)
                    {
                        ur.User = u;
                        ur.Reward = lr;
                        UsersRew.Add(ur);
                    }
                }
                return UsersRew;
            }
            catch (ArgumentException ex)
            {
                throw new ValidationException(ex.Message, ex.ParamName);
            }
        }
Пример #4
0
        /// <summary>
        /// список наград
        /// </summary>
        /// <returns></returns>
        public List<RewardDTO> RewardsList()
        {
            try
            {
                List<RewardDTO> Rewards = new List<RewardDTO>();
                var RewardDAL = Data.RewardsList();

                foreach (var r in RewardDAL)
                {
                    RewardDTO reward = new RewardDTO();
                    reward.RewardID = r.RewardID;
                    reward.Title = r.Title;
                    reward.Description = r.Description;
                    reward.Image = r.Image;
                    Rewards.Add(reward);
                }
                return Rewards;
            }
            catch (ArgumentException ex)
            {
                throw new ValidationException(ex.Message, ex.ParamName);
            }
        }