예제 #1
0
        public ActionResult EditProfile(EditProfileViewModel model)
        {
            var user = this.userService.GetById(this.User.Identity.GetUserId())
                                              .FirstOrDefault();

            if (!string.IsNullOrEmpty(model.FirstName))
            {
                user.FirstName = model.FirstName;
            }

            if (!string.IsNullOrEmpty(model.LastName))
            {
                user.LastName = model.LastName;
            }

            if (!string.IsNullOrEmpty(model.Email))
            {
                user.Email = model.Email;
            }

            if (model.ProfilePic != null)
            {
                using (var memory = new MemoryStream())
                {
                    model.ProfilePic.InputStream.CopyTo(memory);
                    var content = memory.GetBuffer();

                    var image = new Image
                    {
                        Content = content,
                        FileExtension = model.ProfilePic.FileName.Split(new[] { '.' }).Last()
                    };

                    user.ProfilePic = image;
                }
            }

            this.userService.UpdateUser(user);
            return this.RedirectToAction("UserDetails","Account");
        }
예제 #2
0
        public ActionResult Images_Destroy([DataSourceRequest]DataSourceRequest request, Image image)
        {
            this.imageService.MarkAsDeleted(image);

            return Json(new[] { image }.ToDataSourceResult(request, ModelState));
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                Image image = null;

                if (model.ProfilePic != null)
                {
                    using (var memory = new MemoryStream())
                    {
                        model.ProfilePic.InputStream.CopyTo(memory);
                        var content = memory.GetBuffer();

                        image = new Image
                        {
                            Content = content,
                            FileExtension = model.ProfilePic.FileName.Split(new[] { '.' }).Last()
                        };
                    }
                }

                var user = new User { UserName = model.Username, Email = model.Email, ProfilePic = image, FirstName = model.FirstName, LastName = model.LastName };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    UserManager.AddToRole(user.Id, "user");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }