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
Rajesh Gami
79
24.4k
1.3m
Simple question please help
Apr 12 2018 10:53 PM
i want to create login page for admin and user in MVC5.
if registration time select user then after login automatically goto user panel.
and if admin then automatically go to admin panel in MVC
here is my code for admin.
public
ActionResult Login()
{
return
View();
}
[HttpPost]
public
ActionResult Login(UserMaster_Model user)
{
if
(ModelState.IsValid)
{
var details = (from userlist
in
_userMaster.GetAll()
where userlist.USMType ==
"Admin"
&& userlist.USMEmail == user.USMEmail && userlist.USMPassword == user.USMPassword
select
new
{
userlist.USMUserName,
userlist.USMId,
userlist.USMEmail
}).ToList();
if
(details.FirstOrDefault() !=
null
)
{
Session[
"USMUserName"
] = details.FirstOrDefault().USMUserName;
Session[
"USMId"
] = details.FirstOrDefault().USMId;
Session[
"USMEmail"
] = details.FirstOrDefault().USMEmail;
return
RedirectToAction(
"Dashboard"
);
}
else
{
ViewBag.ErrorMessage =
"Invalid User Name OR Password"
;
}
}
else
{
ViewBag.ErrorMessage =
"Enter Username & Password"
;
}
return
View(user);
}
and user side login for below code
public
ActionResult Login()
{
return
View();
}
[HttpPost]
public
ActionResult Login(UserMaster_Model user)
{
if
(ModelState.IsValid)
{
var details = (from userlist
in
_userMaster.GetAll()
where userlist.USMEmail == user.USMEmail && userlist.USMPassword == user.USMPassword
select
new
{
userlist.USMId,
userlist.USMEmail,
userlist.USMUserName
}).FirstOrDefault();
if
(details !=
null
)
{
Session[
"USMUserName"
] = details.USMUserName;
Session[
"USMId"
] = details.USMId;
Session[
"USMEmail"
] = details.USMEmail;
return
RedirectToAction(
"Index"
,
"CompanyMaster"
);
}
else
{
ViewBag.ErrorMessage =
"Invalid User Name OR Password"
;
}
}
else
{
ViewBag.ErrorMessage =
"Enter Username AND Password"
;
}
return
View(user);
}
both code are in different controller, i want to both code are use in one action one controller
How is possible ?
give me answer for only MVC.
thanks in advance
Reply
Answers (
2
)
c# Convert curl request into http request?
example for a data trigger in wpf