Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
3
Answers
Need to compare Value.From other table
Malcom Graves
7y
223
1
Reply
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);
}
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
when sending post request from angular to webapi ?
jQuery validation plugin is not working in MVC 5