Ejemplo n.º 1
0
        public string calculateMarksheet()
        {
            string subjectStr            = HttpContext.Current.Request.Params["request"];
            List <SubjectModel> subjects = JsonConvert.DeserializeObject <List <SubjectModel> >(subjectStr);

            double totalMarks = 0;
            double min        = subjects[0].obtainedMarks;
            string minSub     = subjects[0].name;
            double max        = subjects[0].obtainedMarks;
            string maxSub     = subjects[0].name;

            for (int i = 0; i < subjects.Count; i++)
            {
                totalMarks += subjects[i].obtainedMarks;
                if (min > subjects[i].obtainedMarks)
                {
                    min    = subjects[i].obtainedMarks;
                    minSub = subjects[i].name;
                }

                if (max < subjects[i].obtainedMarks)
                {
                    max    = subjects[i].obtainedMarks;
                    maxSub = subjects[i].name;
                }
            }

            double percent = (totalMarks / (subjects.Count * 100)) * 100;

            MarksheetModel marksheet = new MarksheetModel();

            marksheet.percentage      = percent;
            marksheet.minMarks        = min;
            marksheet.maxMarks        = max;
            marksheet.minSubjectMarks = minSub;
            marksheet.maxSubjectMarks = maxSub;

            string str = JsonConvert.SerializeObject(marksheet);

            return(str);
        }
Ejemplo n.º 2
0
        public string Calculate()
        {
            string subjectsStr           = HttpContext.Current.Request.Params["request"];
            List <SubjectModel> subjects = JsonConvert.DeserializeObject <List <SubjectModel> >(subjectsStr);

            double totalMarks      = 0;
            int    minMarks        = subjects[0].ObtainedMarks;
            int    maxMarks        = subjects[0].ObtainedMarks;
            string minMarksSubject = subjects[0].Name;
            string maxMarksSubject = subjects[0].Name;

            for (int i = 0; i < subjects.Count; i++)
            {
                totalMarks += subjects[i].ObtainedMarks;
                if (maxMarks < subjects[i].ObtainedMarks)
                {
                    maxMarks        = subjects[i].ObtainedMarks;
                    maxMarksSubject = subjects[i].Name;
                }
                else if (minMarks > subjects[i].ObtainedMarks)
                {
                    minMarks        = subjects[i].ObtainedMarks;
                    minMarksSubject = subjects[i].Name;
                }
            }
            double percent = (totalMarks / (subjects.Count * 100)) * 100;

            MarksheetModel marksheetModel = new MarksheetModel
            {
                Percentage      = percent,
                MinMarks        = minMarks,
                MaxMarks        = maxMarks,
                MinSubjectMarks = minMarksSubject,
                MaxSubjectMarks = maxMarksSubject
            };

            string str = JsonConvert.SerializeObject(marksheetModel);

            return(str);
        }
Ejemplo n.º 3
0
        public string CalculatePercentage()
        {
            string subjectStr = HttpContext.Current.Request.Params["request"];
            List <MarksheetModel> subjects = JsonConvert.DeserializeObject <List <MarksheetModel> >(subjectStr);
            double minMarks        = subjects[0].subjectMarksObtained;
            double maxMarks        = subjects[0].subjectMarksObtained;
            string minMarksSubject = subjects[0].subjectName;
            string maxMarksSubject = subjects[0].subjectName;
            double totalMarks      = 0.0;

            for (int i = 0; i < subjects.Count; i++)
            {
                totalMarks += subjects[i].subjectMarksObtained;
                if (minMarks > subjects[i].subjectMarksObtained)
                {
                    minMarks        = subjects[i].subjectMarksObtained;
                    minMarksSubject = subjects[i].subjectName;
                }

                if (maxMarks < subjects[i].subjectMarksObtained)
                {
                    maxMarks        = subjects[i].subjectMarksObtained;
                    maxMarksSubject = subjects[i].subjectName;
                }
            }
            double percentage = (totalMarks / (subjects.Count * 100)) * 100;

            MarksheetModel marksheetModel = new MarksheetModel();

            marksheetModel.percentage      = percentage;
            marksheetModel.minMarks        = minMarks;
            marksheetModel.maxMarks        = maxMarks;
            marksheetModel.minMarksSubject = minMarksSubject;
            marksheetModel.maxMarksSubject = maxMarksSubject;

            string str = JsonConvert.SerializeObject(marksheetModel);

            return(str);
        }