Inheritance: SocialPackage.Infrastructure.Entities.User
示例#1
0
        public ActionResult AddUser()
        {
            var User = new UserViewModel()
            {
                AvailLimits = db.Limit.ToList(),
                allRoles = db.UserRole.ToList(),
                currRoles = new List<UserRole>(),
                SelectedRoles = new int[0]
            };

            // ViewBag.limits = db.Limit.Select(el => new { id = el.Id, values = string.Format("{0}/{1}/{2}", el.Fitnes, el.Proezd, el.CultureEvents) });
            return View(User);
        }
示例#2
0
        public ActionResult AddUser(UserViewModel user)
        {
            if (ModelState.IsValid)
            {
                var usr = new User()
                {
                    FullName = user.FullName,
                    Email = user.Email,
                    Login = user.Login,
                    Limit = db.Limit.Find(user.SelectedLimitId),
                    Roles = user.SelectedRoles.Select(el => db.UserRole.Find(el)).ToList()
                };

                db.Users.Add(usr);
                db.SaveChanges();
                FixBid(user.realProezdLimit, user.realFitnesLimit, user.realCultureEvent, usr);
                return RedirectToAction("Index");
            }
            return View(new UserViewModel()
            {
                AvailLimits = db.Limit.ToList()
            });
        }
示例#3
0
        public ActionResult Edit(int id)
        {
            var usr = db.Users.Find(id);
            if (usr == null)
                return HttpNotFound();
            var allLimits = db.Limit.ToList();
            var Roles = db.UserRole.ToList();

            var usrVm = new UserViewModel()
            {
                FullName = usr.FullName,
                Email = usr.Email,
                Limit = usr.Limit,
                Login = usr.Login,
                SelectedLimitId = usr.Limit != null ? usr.Limit.Id : allLimits.First().Id,
                AvailLimits = allLimits,

                allRoles = Roles,
                currRoles = usr.Roles,
                SelectedRoles = usr.Roles.Select(el => el.RoleId).ToArray()

            };
            return View(usrVm);
        }
示例#4
0
        public ActionResult Edit(UserViewModel user)
        {
            var usr = db.Users.Find(user.id);
            usr.Roles.Clear();
            usr.Roles = user.SelectedRoles.Select(el => db.UserRole.Find(el)).ToList();
            usr.Limit = db.Limit.Find(user.SelectedLimitId);
            usr.FullName = user.FullName;
            usr.Email = user.Email;

            db.Entry(usr).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }