예제 #1
0
        public async Task<ActionResult> Edit(UserEditViewModel model)
        {
            var userid = User.Identity.GetUserId();
            var user = await db.Users.FirstOrDefaultAsync(q => q.Id == userid);

            if (user == null)
                return HttpNotFound();

            if (!await IsNameAvailable(model.UserName, user.UserName))
                ModelState.AddModelError(String.Empty, "Name is not available");

            if (ModelState.IsValid)
            {
                user.ImageUrl = model.ImageUrl;
                user.UserName = model.UserName;
                user.Slug = model.UserName.ToFriendlyUrl();

                db.Entry(user).State = EntityState.Modified;

                await db.SaveChangesAsync();
                await SignInAsync(user, isPersistent: false);

                return RedirectToAction("Manage");
            }

            return View(model);
        }
예제 #2
0
        public async Task<ActionResult> Edit()
        {
            var userid = User.Identity.GetUserId();
            var user = await db.Users.FirstOrDefaultAsync(q => q.Id == userid);

            if (user == null)
                return HttpNotFound();

            var viewmodel = new UserEditViewModel()
            {
                ImageUrl = user.ImageUrl,
                UserName = user.UserName
            };

            return View(viewmodel);
        }