2017-08-28 8 views
1

Entity Frameworkを使用してモデルプロパティを編集するなどの少しの問題が発生しました。Identity2を使用したユーザー情報の編集

1)それでは、始めましょう - 私はプロパティ "PacientInfo" を編集したい

public class RegisterViewModel 
{ 
    [Required] 
    [EmailAddress] 
    [Display(Name = "Адрес электронной почты")] 
    public string Email { get; set; } 

    [Required] 
    [StringLength(100, ErrorMessage = "Значение {0} должно содержать не менее {2} символов.", MinimumLength = 6)] 
    [DataType(DataType.Password)] 
    [Display(Name = "Пароль")] 
    public string Password { get; set; } 

    [DataType(DataType.Password)] 
    [Display(Name = "Подтверждение пароля")] 
    [Compare("Password", ErrorMessage = "Пароль и его подтверждение не совпадают.")] 
    public string ConfirmPassword { get; set; } 

    public string Name { get; set; } 

    public string PacientInfo { get; set; } 
} 

2)と私は、このプロパティを編集するためにいくつかの基本的なロジックを追加しました: GET + POSTメソッド

[HttpGet] 
    public ActionResult EditPacientInfo(string email) 
    { 
     var UserManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); 
     ApplicationUser appUser = new ApplicationUser(); 
     appUser = UserManager.FindByEmail(email); 
     PacientEdit user = new PacientEdit() 
     { 
      Email = appUser.Email, 
      PacientInfo = appUser.PacientInfo 
     }; 
     if (email== null) 
     { 
      return new HttpStatusCodeResult(HttpStatusCode.BadRequest); 
     } 
     ApplicationUser pacient = db.Users.Find(email); 

     if (pacient == null) 
     { 
      return HttpNotFound(); 
     } 
     return View(pacient); 
    } 
[HttpPost] 
    public ActionResult EditPacientInfo(ApplicationUser model) 
    { 

     var UserManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); 
     if (ModelState.IsValid) 
     { 
      ApplicationUser u = UserManager.FindById(model.Id); 
      u.Email = model.Email; 
      u.PacientInfo= model.PacientInfo; // Extra Property 
      UserManager.Update(u); 
      return RedirectToAction("Index"); 
     } 
     return View(model); 
    } 

@model med_projec_roles_added.Models.RegisterViewModel 
@{ 
    ViewBag.Title = "EditPacientInfo"; 
} 
@model med_projec_roles_added.Models.ApplicationUser 
<h2>Pacient , @Model.Email</h2> 
@using (Html.BeginForm()) 
{ 

      @Html.LabelFor(model => model.PacientInfo, new { @class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(model => model.PacientInfo) 
       @Html.ValidationMessageFor(model => model.PacientInfo) 
      </div> 
} 

4)とN:

3)そして、私の "EditInfoMethod" `sのビューをカスタマイズしてみました主な問題:GETメソッドを経由するはずのアドレスバーアドレスに書きますが、この例外を受け取り続けます: Exception

5)私のデータベースに表示されている - この電子メールは既に作成されていますUser database

6)「EditPacientInfo」を正しく変更するためにさまざまな方法を試しましたが、インターネットで正しい決定を下すことはできません。 あなたが本当にこの状況で私を助けることができるいくつかのものを見つけて/書くことができればうれしいです。(皆さん、ありがとうございます^^)

+0

いくつかの点:次のURLを試してみてください[FromRoute]文字列の電子メール) ' 3)あなたの電子メールを[email protected]に符号化してaaa%40bbb.com.br よろしく。 – dime2lo

+0

ありがとう、私はこの問題を解決するのに役立ついくつかの有用な答えを見つけました。 https://stackoverflow.com/questions/22955872/editing-user-profile-details https://stackoverflow.com/questions/ 24343246/asp-net-identity-type-multiple-object-sets-per-type-are-not-supported-Identity 2データベースに問題がある場合 - これは自動スキャフォールディングの問題を解決します – clyde

答えて

0

私はURLと思いますブラウザで正しい形式ではありません。 ( `公共のActionResult EditPacientInfoのように[FromRoute]追加)、 1)HTTPGETアクションで 2 id`文字列`へemail` `文字列を変更します。あなたがしようとするために

localhost:1290/Doctor/[email protected]@gmail.com 
関連する問題