コード例 #1
0
ファイル: ProfileController.cs プロジェクト: Zerek/edurate
        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);
        }
コード例 #2
0
ファイル: ProfileController.cs プロジェクト: Zerek/edurate
 private User ViewModelIntoEntity(ProfileViewModel viewModel)
 {
     return new User()
         {
             UserId = viewModel.UserId,
             FullName = viewModel.FullName,
             Description = viewModel.Description,
             DateOfBirth = viewModel.DateOfBirth
         };
 }