Exemple #1
0
        public IActionResult Delete([FromBody] APIPostReqs <List <string> > req, string student_Id)
        {
            if (req == null)
            {
                return(BadRequest());
            }

            List <string> crns = req.data;

            var p = new DynamicParameters();

            p.Add("@stdId", student_Id);

            var isStudent = cloasisdbRef.Query("SELECT * FROM dbo.STUDENT WHERE STUDENTID = @stdId", p);


            if (isStudent.Count() == 0)
            {
                return(BadRequest("Please Provide a valid StudentId"));
            }

            string CRNsInString = "";
            string log          = "";

            foreach (string crn in crns)
            {
                bool flag = false;


                var x = new
                {
                    class_crn = crn,
                    std_Id    = student_Id
                };

                var isClass = cloasisdbRef.Query("SELECT * FROM dbo.CLASS WHERE CRN = @class_crn", x);

                if (isClass.Count() == 0)
                {
                    flag = true;
                    log  = log + $"Please Provide a valid CRN because {crn} is not valid.\n";
                    continue;
                }

                List <RegistrationEntry> entriesMatched = cloasisdbRef.Query <RegistrationEntry>("SELECT * FROM dbo.ENROLLMENT WHERE STUDENTID = @std_Id AND CRN = @class_crn", x).ToList();

                if (entriesMatched.Count() == 0)
                {
                    flag = true;
                    log  = log + $"Student Is Not Registered in the Class -> {crn}\n";
                    continue;
                }

                if (!flag)
                {
                    string sql = $@"DELETE FROM dbo.ENROLLMENT WHERE STUDENTID = @std_Id AND CRN = @class_crn";

                    CRNsInString = CRNsInString + crn + ", ";


                    cloasisdbRef.Execute(sql, x);
                }
            }

            return(Ok($"Student {student_Id} is dropped from classes [{CRNsInString}]" + $"\nLog: \n{log}"));
        }
Exemple #2
0
        public IActionResult Post([FromBody] APIPostReqs <List <string> > req, string student_Id)
        {
            if (req == null)
            {
                return(BadRequest());
            }

            List <string> crns = req.data;

            var p = new DynamicParameters();

            p.Add("@stdId", student_Id);

            var isStudent = cloasisdbRef.Query("SELECT * FROM dbo.STUDENT WHERE STUDENTID = @stdId", p);


            if (isStudent.Count() == 0)
            {
                return(BadRequest("Please Provide a valid StudentId"));
            }

            string CRNsInString = "";
            string log          = "";

            foreach (string crn in crns)
            {
                bool flag = false;

                var x = new
                {
                    class_crn = crn,
                    std_Id    = student_Id
                };


                var isClass = cloasisdbRef.Query("SELECT * FROM dbo.CLASS WHERE CRN = @class_crn", x);

                if (isClass.Count() == 0)
                {
                    flag = true;
                    log  = log + $"Please Provide a valid CRN because {crn} is not valid.\n";
                    continue;
                }

                int course_Id = cloasisdbRef.Query <int>("SELECT COURSE_ID FROM CLASS WHERE CRN = @class_crn", x).ToList()[0];

                List <RegistrationEntry> entriesMatched = cloasisdbRef.Query <RegistrationEntry>("SELECT * FROM dbo.ENROLLMENT WHERE STUDENTID = @stdId", p).ToList();


                foreach (RegistrationEntry ent in entriesMatched)
                {
                    int crsIdOfEnt = cloasisdbRef.Query <int>("SELECT COURSE_ID FROM CLASS WHERE CRN = @CRN", ent).ToList()[0];

                    if (ent.CRN == crn)
                    {
                        flag = true;
                        log  = log + $"Student Already Registered in the Class -> {crn}\n";
                        break;
                    }

                    if (crsIdOfEnt == course_Id)
                    {
                        flag = true;
                        log  = log + $"Student Already Registered in another section of this Course -> {crn}\n";
                        break;
                    }
                }

                if (!flag)
                {
                    string sql = $@"insert into dbo.ENROLLMENT (CRN, STUDENTID) 
                                values (@class_crn, @std_Id)";

                    CRNsInString = CRNsInString + crn + ", ";


                    cloasisdbRef.Execute(sql, x);
                }
            }

            return(Ok($"Student {student_Id} is now registered in classes [{CRNsInString}]" + $"\nLog: \n{log}"));
        }