TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
2.1k
469.6k
How to check your crud if its working or not in sql db?
Feb 4 2020 12:35 PM
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<ActionResult> 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}<BR/>Thank you for your registration, please click on the below link to complete your registration: <a href=\"{1}\" title=\"User Email Confirm\">{1}</a>"
, 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"
;
}
<h2>@ViewBag.Title.</h2>
@
using
(Html.BeginForm(
"Register"
,
"Account"
, FormMethod.Post,
new
{ @
class
=
"form-horizontal"
, role =
"form"
}))
{
@Html.AntiForgeryToken()
<h4>Create a
new
account.</h4>
<hr />
@Html.ValidationSummary()
<div
class
=
"form-group"
>
@Html.LabelFor(m => m.UserName,
new
{ @
class
=
"col-md-2 control-label"
})
<div
class
=
"col-md-10"
>
@Html.TextBoxFor(m => m.UserName,
new
{ @
class
=
"form-control"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(m => m.Password,
new
{ @
class
=
"col-md-2 control-label"
})
<div
class
=
"col-md-10"
>
@Html.PasswordFor(m => m.Password,
new
{ @
class
=
"form-control"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(m => m.ConfirmPassword,
new
{ @
class
=
"col-md-2 control-label"
})
<div
class
=
"col-md-10"
>
@Html.PasswordFor(m => m.ConfirmPassword,
new
{ @
class
=
"form-control"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(m => m.Email,
new
{ @
class
=
"col-md-2 control-label"
})
<div
class
=
"col-md-10"
>
@Html.TextBoxFor(m => m.Email,
new
{ @
class
=
"form-control"
})
</div>
</div>
<div
class
=
"form-group"
>
<div
class
=
"col-md-offset-2 col-md-10"
>
<input type=
"submit"
class
=
"btn btn-info"
value=
"Register"
/>
</div>
</div>
}
@section Scripts {
@Scripts.Render(
"~/bundles/jqueryval"
)
}
Reply
Answers (
1
)
how to save multiple selected values of dropdownlist in mvc
File name maybe incorrect on database path?