Esempio n. 1
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. 2
0
 public ActionResult AddUser()
 {
     try
     {
         UserViewModel User = new UserViewModel();
         return View(User);
     }
     catch (ValidationException ex)
     {
         return Content(ex.Message);
     }
 }
Esempio n. 3
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. 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);
            }
        }
Esempio n. 5
0
        // GET: User
        /// <summary>
        /// список юзеров
        /// </summary>
        /// <returns></returns>
        public ActionResult UList()
        {
            try
            {
                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;
                    list.Birthdate = u.Birthdate;
                    list.Age = u.Age;
                    list.Photo = u.Photo;
                    UList.Add(list);
                }
                return View(UList);
            }
            catch (ValidationException ex)
            {
                return Content(ex.Message);
            }
        }
Esempio n. 6
0
 public ActionResult EditUser(int id)
 {
     try
     {
         var UBLL = Data.UsersList().Find(u => u.UserID == id);
         UserViewModel user = new UserViewModel();
         user.UserID = UBLL.UserID;
         user.Name = UBLL.Name;
         user.Birthdate = UBLL.Birthdate;
         user.Photo = UBLL.Photo;
         return View(user);
     }
     catch (ValidationException ex)
     {
         return Content(ex.Message);
     }
 }