Beispiel #1
0
        public ActionResult Edit(ProfileViewModel editedUser)
        {
            if (ModelState.IsValid)
            {
                var user = db.Users.Find(editedUser.UserId);
                if (user == null)
                {
                    return HttpNotFound();
                }

                if (editedUser.File != null)
                {
                    var image = new WebImage(editedUser.File.InputStream);
                    if (image != null)
                    {
                        var imageName = Guid.NewGuid().ToString() + "." + image.ImageFormat;
                        var path = Path.Combine(Server.MapPath("~/Content/Images"), WebSecurity.CurrentUserName, "Profile");
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        path = Path.Combine(path, imageName);
                        image.Save(path);
                        user.ImageName = imageName;
                        user.ImageUrl = Path.Combine("~/Content/Images", WebSecurity.CurrentUserName, "Profile", imageName);
                    }
                }
                user.FullName = editedUser.FullName;
                user.Description = editedUser.Description;
                user.DateOfBirth = editedUser.DateOfBirth;
                db.SaveChanges();
                return RedirectToAction("Edit");
            }

            return View(editedUser);
        }
Beispiel #2
0
 private User ViewModelIntoEntity(ProfileViewModel viewModel)
 {
     return new User()
         {
             UserId = viewModel.UserId,
             FullName = viewModel.FullName,
             Description = viewModel.Description,
             DateOfBirth = viewModel.DateOfBirth
         };
 }