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
Malcom Graves
NA
19
609
Need to compare Value.From other table
Nov 4 2017 6:06 PM
i have 3 classes in my model
Model
public
class
Student
{
public
int
id {
get
;
set
; }
[Required]
[DisplayName(
"Student Name"
)]
public
string
Name {
get
;
set
; }
[Required]
public
int
RollNO {
get
;
set
; }
public
DateTime EnrollmentDate {
get
;
set
; }
public
ICollection<Record> Records {
get
;
set
; }
}
public
class
Record
{
public
int
Id {
get
;
set
; }
public
int
StudentId {
get
;
set
; }
public
int
SubjectId {
get
;
set
; }
[Required]
public
int
Marks {
get
;
set
; }
public
string
Result {
get
;
set
; }
public
virtual
Student Students {
get
;
set
; }
public
virtual
Subject Subjects {
get
;
set
; }
}
public
class
Subject
{
public
int
id {
get
;
set
; }
[Required]
public
string
Title {
get
;
set
; }
[Required]
[DisplayName(
"Minimum Marks"
)]
public
int
MinMarks {
get
;
set
; }
[Required]
[DisplayName(
"Max Marks"
)]
public
int
MaxMarks {
get
;
set
; }
public
ICollection<Record> Records {
get
;
set
; }
}
In subject table i will be creating each subject and setting its minimum and maximum marks required to pass...now in record table
(Create Page)
i want to compare the selected subject minimum marks with
Record.Marks
and if its less the minimum marks get Fail in
Record.Result
and if its greater then maximum marks get Pass in
Record.Result
...and i also want to compare the Result.Marks property with Subject.MaxMarks and if its greater then Subject.MaxMarks the user should get and error in any form possible...
This is my controller
public
ActionResult Create([Bind(Include =
"Id,StudentId,SubjectId,Marks,Result"
)] Record record,Subject subject)
{
if
(record.Marks<record.Subjects.MinMarks)
{
record.Result =
"Fail"
;
}
else
{
record.Result =
"Pass"
;
}
if
(ModelState.IsValid)
{
db.Records.Add(record);
db.SaveChanges();
return
RedirectToAction(
"Index"
);
}
ViewBag.StudentId =
new
SelectList(db.Students,
"id"
,
"Name"
, record.StudentId);
ViewBag.SubjectId =
new
SelectList(db.Subjects,
"id"
,
"Title"
, record.SubjectId);
return
View(record);
}
Reply
Answers (
3
)
when sending post request from angular to webapi ?
jQuery validation plugin is not working in MVC 5