Hi Team
I have MVC, i am using core development and have class called "ApplicationDbContext". Now my question is how do i check if my crud operation working? Meaning i cant seem to see the operation from the back end. Let me show you my Controller method for Reg, Model(Registration) and View. Can you mates at least tell me where to look? It does not do any crud operation to my tables on the DB. I havent configure yet my Web.Config file for connectionString. Do i also need to do this? Could this be reason, please assist me further.
- // Controller.cs
- [HttpPost]
- [AllowAnonymous]
- [ValidateAntiForgeryToken]
- public async Task
Register(RegisterViewModel model) - {
- if (ModelState.IsValid)
- {
- var user = new ApplicationUser() { UserName = model.UserName };
- user.Email = model.Email;
- user.ConfirmedEmail = false;
- var result = await UserManager.CreateAsync(user, model.Password);
- if (result.Succeeded)
- {
- System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(
- new System.Net.Mail.MailAddress("[email protected]", "Web Registration"),
- new System.Net.Mail.MailAddress(user.Email));
- m.Subject = "Email confirmation";
- m.Body = string.Format("Dear {0}
Thank you for your registration, please click on the below link to complete your registration: {1}", user.UserName, Url.Action("ConfirmEmail", "Account", new { Token = user.Id, Email = user.Email }, Request.Url.Scheme)); - m.IsBodyHtml = true;
- System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.mydomain.com");
- smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
- smtp.EnableSsl = true;
- smtp.Send(m);
- return RedirectToAction("Confirm", "Account", new { Email = user.Email });
- }
- else
- {
- AddErrors(result);
- }
- }
- // If we got this far, something failed, redisplay form
- return View(model);
- }
- // Model class
- public class RegisterViewModel
- {
- [Required]
- [Display(Name = "User name")]
- public string UserName { get; set; }
- [Required]
- [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
- [DataType(DataType.Password)]
- [Display(Name = "Password")]
- public string Password { get; set; }
- [DataType(DataType.Password)]
- [Display(Name = "Confirm password")]
- [Compare("Password", ErrorMessage = "The password and confirmation do not match.")]
- public string ConfirmPassword { get; set; }
- [Required]
- [EmailAddress]
- [Display(Name = "Email")]
- public string Email { get; set; }
- }
- // View cshtml
- @model ContentManagementSystem.Models.RegisterViewModel
- @{
- ViewBag.Title = "Register";
- }
@ViewBag.Title.
- @using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
- {
- @Html.AntiForgeryToken()
-
Create a new account.
-
- @Html.ValidationSummary()
- class="form-group">
- @Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
class="col-md-10">- @Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
- class="form-group">
- @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
class="col-md-10">- @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
- class="form-group">
- @Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })
class="col-md-10">- @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })
- class="form-group">
- @Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
class="col-md-10">- @Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
- class="form-group">class="col-md-offset-2 col-md-10">
- "submit" class="btn btn-info" value="Register" />
- }
- @section Scripts {
- @Scripts.Render("~/bundles/jqueryval")
- }
Gowtham RamarPosted Feb 4, 2020, 8:53 PM