Esempio n. 1
0
 /// <summary>
 /// добавление юзера
 /// </summary>
 /// <param name="newU">новый юзер</param>
 /// <returns></returns>
 public bool AddUser(UserDTO newU)
 {
     try
     {
         User UserDAL = new User();
         UserDAL.Name = newU.Name;
         UserDAL.Birthdate = newU.Birthdate;
         int age = 0;
         age = DateTime.Now.Year - newU.Birthdate.Year;
         if ((DateTime.Now.Month <= newU.Birthdate.Month)
             && (DateTime.Now.Day < newU.Birthdate.Day))
         {
             age--;
         }
         UserDAL.Age = age;
         UserDAL.Photo = newU.Photo;
         if (Data.AddUser(UserDAL) == true)
             return true;
         else throw new ValidationException("Ваш запрос не был обработан", "");
     }
     catch (ArgumentException ex)
     {
         throw new ValidationException(ex.Message, ex.ParamName);
     }
 }
Esempio n. 2
0
 public ActionResult AddUser(UserViewModel user, HttpPostedFileBase file)
 {
     try
     {
         //Если введены поля Name и Birthdate, то создаётся новая награда
         if ((ModelState.IsValidField("Name")) && (ModelState.IsValidField("Birthdate")))
         {
             UserDTO UBLL = new UserDTO();
             UBLL.Name = user.Name;
             UBLL.Birthdate = user.Birthdate;
             if (file != null)
             {
                 Stream stream = file.InputStream;
                 byte[] image = new byte[stream.Length];
                 stream.Read(image, 0, (int)stream.Length);
                 UBLL.Photo = image;
             }
             else UBLL.Photo = user.Photo;
             Data.AddUser(UBLL);
             return RedirectToAction("UList");
         }
         else return View(user);
     }
     catch (ValidationException ex)
     {
         return Content(ex.Message);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// добавление юзера
 /// </summary>
 /// <param name="newU">новый юзер</param>
 /// <returns></returns>
 public bool AddUser(UserDTO newU)
 {
     try
     {
         User UserDAL = new User();
         UserDAL.Name = newU.Name;
         UserDAL.Birthdate = newU.Birthdate;
         int age = 0;
         age = DateTime.Now.Year - newU.Birthdate.Year;
         if ((DateTime.Now.Month <= newU.Birthdate.Month)
             && (DateTime.Now.Day < newU.Birthdate.Day))
         {
             age--;
         }
         UserDAL.Age = age;
         if (age > 0 && age <= 150)
         {
             UserDAL.Photo = newU.Photo;
             if (Data.AddUser(UserDAL) == true)
                 return true;
             else throw new ValidationException("Ваш запрос не был обработан", "");
         }
         else throw new ValidationException("Вы ввели некорректную дату. Возраст не может быть отрицательным или больше 150.", "");
     }
     catch (ArgumentException ex)
     {
         throw new ValidationException(ex.Message, ex.ParamName);
     }
 }
Esempio n. 4
0
 public ActionResult AddUser(UserViewModel user)
 {
     try
     {
         DateTime d = new DateTime(DateTime.Now.Year - 150, DateTime.Now.Month, DateTime.Now.Day);
         //Если введены поля Name и Birthdate, то создаётся новый юзер
         if ((ModelState.IsValidField("Name")) && (ModelState.IsValidField("Birthdate"))
             && ((user.Birthdate <= DateTime.Now) && (user.Birthdate > d)))
         {
             UserDTO UBLL = new UserDTO();
             UBLL.Name = user.Name;
             UBLL.Birthdate = user.Birthdate;
             if (user.File != null)
             {
                 Stream stream = user.File.InputStream;
                 byte[] image = new byte[stream.Length];
                 stream.Read(image, 0, (int)stream.Length);
                 UBLL.Photo = image;
             }
             else UBLL.Photo = user.Photo;
             Data.AddUser(UBLL);
             return RedirectToAction("UList");
         }
         else
         {
             if ((user.Birthdate > DateTime.Now) || (user.Birthdate < d))
             {
                 ModelState.AddModelError("Birthdate",
                     "Дата должна быть больше " + d.ToShortDateString()
                     + " и меньше " + DateTime.Now.ToShortDateString());
             }
             return View(user);
         }
     }
     catch (ValidationException ex)
     {
         return Content(ex.Message);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// список юзеров
        /// </summary>
        /// <returns></returns>
        public List<UserDTO> UsersList()
        {
            try
            {
                List<UserDTO> Users = new List<UserDTO>();
                var UsersDAL = Data.UsersList();

                foreach (var u in UsersDAL)
                {
                    UserDTO user = new UserDTO();
                    user.UserID = u.UserID;
                    user.Name = u.Name;
                    user.Birthdate = u.Birthdate;
                    user.Age = u.Age;
                    user.Photo = u.Photo;
                    Users.Add(user);
                }
                return Users;
            }
            catch (ArgumentException ex)
            {
                throw new ValidationException(ex.Message, ex.ParamName);
            }
        }
Esempio n. 6
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);
            }
        }