Exemplo n.º 1
0
        public ActionResult Create(UserFormModel user)
        {
            if (ModelState.IsValid)
            {
                // TODO: check for duplicate username, ...

                var createdUser = new UserProfile
                {
                    UserName = user.UserName,
                    Email = user.Email
                };
                _db.UserProfiles.Add(createdUser);
                _db.SaveChanges();

                // if valid, redirect to edit page
                return RedirectToAction("Edit", new { id = createdUser.UserId });
            }

            return View(new CreateUserViewModel(user));
        }
Exemplo n.º 2
0
        //
        // GET: /Default1/Edit/5
        public ActionResult Edit(int id = 0)
        {
            var existingUser = _db.UserProfiles.SingleOrDefault(u => u.UserId == id);
            if (existingUser == null)
            {
                return HttpNotFound();
            }

            var user = new UserFormModel { UserName = existingUser.UserName, Email = existingUser.Email };
            return View(new EditUserViewModel(user)
            {
                IsOnline = existingUser.IsOnline,
                SessionId = existingUser.SessionId
            });
        }
Exemplo n.º 3
0
 public EditUserViewModel(UserFormModel user)
 {
     User = user;
 }
Exemplo n.º 4
0
        public ActionResult Edit(int id, UserFormModel user)
        {
            var existingUser = _db.UserProfiles.SingleOrDefault(u => u.UserId == id);
            if (existingUser == null) { /* TODO: handle error */ }

            if (ModelState.IsValid)
            {
                existingUser.UserName = user.UserName;
                existingUser.Email = user.Email;
                _db.SaveChanges();

                return RedirectToAction("Edit", new { id = existingUser.UserId });
            }

            return View(new EditUserViewModel(user)
            {
                IsOnline = existingUser.IsOnline,
                SessionId = existingUser.SessionId
            });
        }
Exemplo n.º 5
0
 public CreateUserViewModel(UserFormModel user)
 {
     User = user;
 }