예제 #1
0
        /// <summary>Determines whether the specified student has been graduated for given diploma.</summary>
        /// <param name="diploma">The diploma.</param>
        /// <param name="student">The student.</param>
        /// <returns>GraduateResult</returns>
        public GraduateResult HasGraduated(Diploma diploma, Student student)
        {
            var totalMarks = 0;

            foreach (var requirement in diploma.Requirements.Select(x => requirementRepository.GetItem(x)))
            {
                foreach (var studentCourse in student.Courses)
                {
                    foreach (var reqCource in requirement.Courses.Where(x => x == studentCourse.Id))
                    {
                        totalMarks            += studentCourse.Mark;
                        studentCourse.Credits += (studentCourse.Mark >= requirement.MinimumMark) ? requirement.Credits : 0;
                    }
                }
            }

            var average = totalMarks / student.Courses.Length;

            var standing =
                (average < 50) ? Standing.Remedial :
                (average < 80) ? Standing.Average :
                (average < 95) ? Standing.MagnaCumLaude :
                Standing.SummaCumLaude;

            var pass = standing > Standing.Remedial;

            return(new GraduateResult()
            {
                Passed = pass, Status = standing
            });
        }
        public void TestCalculateStudentAverageIncompleteCourse()
        {
            var diploma = new Diploma
            {
                Id           = 1,
                Credits      = 4,
                Requirements = new int[] { 100, 102, 103, 104 }
            };

            var student = new Student
            {
                Id      = 1,
                Courses = new Course[]
                {
                    new Course {
                        Id = 1, Name = "Math", Mark = 95
                    },
                    new Course {
                        Id = 2, Name = "Science", Mark = 95
                    },
                    new Course {
                        Id = 4, Name = "Physichal Education", Mark = 95
                    }
                }
            };

            //expected
            var average = 95;
            var credit  = 3;

            standingService.CalculateStudentGrade(diploma, student);

            Assert.AreEqual(student.TotalAverage, average);
            Assert.AreEqual(student.CompletedCredits, credit);
        }
예제 #3
0
        public void TestIfStandingIsSumaCumLaude()
        {
            var tracker = new GraduationTracker();

            var diploma = new Diploma()
            {
                Id           = 1,
                Credits      = 4,
                Requirements = new List <int> {
                    100, 102, 103, 104
                }
            };

            var student = new Student()
            {
                Id      = 34,
                Courses = new List <Course>()
                {
                    new Course {
                        Id = 100, Name = "Math", Mark = 98
                    },
                    new Course {
                        Id = 102, Name = "Science", Mark = 97
                    },
                    new Course {
                        Id = 103, Name = "Literature", Mark = 93
                    },
                    new Course {
                        Id = 104, Name = "Physichal Education", Mark = 98
                    }
                }
            };

            Assert.AreEqual(tracker.HasGraduated(diploma, student).Item2, Standing.SumaCumLaude);
        }
예제 #4
0
        public void TestIfCourseIsOffRequirements()
        {
            var tracker = new GraduationTracker();

            var diploma = new Diploma()
            {
                Id           = 1,
                Credits      = 4,
                Requirements = new List <int> {
                    1, 2, 3, 4
                }
            };

            var student = new Student()
            {
                Id      = 34,
                Courses = new List <Course>()
                {
                    new Course {
                        Id = 100, Name = "Math", Mark = 50
                    },
                    new Course {
                        Id = 102, Name = "Science", Mark = 97
                    },
                    new Course {
                        Id = 103, Name = "Literature", Mark = 76
                    },
                    new Course {
                        Id = 104, Name = "Physichal Education", Mark = 48
                    }
                }
            };

            Assert.IsFalse(tracker.HasGraduated(diploma, student).Item1);
        }
예제 #5
0
        public void TestStatus_SumaCumLaude()
        {
            Diploma            diploma = _diplomaRepository.GetDiploma(1);
            List <List <int> > marks   = new List <List <int> >();
            List <int>         marks1  = new List <int>()
            {
                95, 90, 100, 100
            };
            List <int> marks2 = new List <int>()
            {
                100, 100, 95, 85
            };

            marks.Add(marks1);
            marks.Add(marks2);
            List <STANDING> standings = new List <STANDING>();

            List <Student> students = GetStudents_Fake(marks);

            foreach (Student student in students)
            {
                STANDING studentStanding = _tracker.GetGraduationStatus(diploma, student).Item2;
                standings.Add(studentStanding);
            }

            Assert.IsTrue(standings.FindAll(x => x == STANDING.SumaCumLaude).Count() == 2);
        }
예제 #6
0
        public void Students_TestAllFailed()
        {
            Diploma            diploma = _diplomaRepository.GetDiploma(1);
            List <List <int> > marks   = new List <List <int> >();
            List <int>         marks1  = new List <int>()
            {
                40, 30, 40, 60
            };
            List <int> marks2 = new List <int>()
            {
                60, 45, 30, 30
            };

            marks.Add(marks1);
            marks.Add(marks2);

            List <Student> students          = GetStudents_Fake(marks);
            int            countHasGraduated = 0;

            foreach (Student student in students)
            {
                bool hasGraduated = _tracker.GetGraduationStatus(diploma, student).Item1;
                if (!hasGraduated)
                {
                    countHasGraduated++;
                }
            }

            Assert.AreEqual(marks.Count(), countHasGraduated);
        }
예제 #7
0
        public void TestStatus_Average()
        {
            Diploma            diploma = _diplomaRepository.GetDiploma(1);
            List <List <int> > marks   = new List <List <int> >();
            List <int>         marks1  = new List <int>()
            {
                50, 60, 70, 80
            };
            List <int> marks2 = new List <int>()
            {
                60, 50, 65, 70
            };

            marks.Add(marks1);
            marks.Add(marks2);
            List <STANDING> standings = new List <STANDING>();

            List <Student> students = GetStudents_Fake(marks);

            foreach (Student student in students)
            {
                STANDING studentStanding = _tracker.GetGraduationStatus(diploma, student).Item2;
                standings.Add(studentStanding);
            }

            Assert.IsTrue(standings.FindAll(x => x == STANDING.Average).Count() == 2);
        }
예제 #8
0
        private async Task <UniversityDbContext> PrepareDiplomas()
        {
            var diploma1 = new Diploma {
                Id = DiplomaValidId, StudentId = StudentValidId, CurriculumId = CurriculumValidId
            };
            var diploma2 = new Diploma {
                Id = DiplomaValidId2, StudentId = "2", CurriculumId = 2
            };

            var curriculum1 = new Curriculum {
                Id = CurriculumValidId
            };
            var curriculum2 = new Curriculum {
                Id = CurriculumInvalidId
            };

            var user1 = new User {
                Id = StudentValidId
            };
            var user2 = new User {
                Id = StudentInvalidId
            };

            var db = Tests.InitializeDatabase();
            await db.Curriculums.AddRangeAsync(curriculum1, curriculum2);

            await db.Diplomas.AddRangeAsync(diploma1, diploma2);

            await db.Users.AddRangeAsync(user1, user2);

            await db.SaveChangesAsync();

            return(db);
        }
예제 #9
0
파일: Request.cs 프로젝트: pazhe/JiazheWeb
        /// <summary>
        /// 获取选品库产品淘口令
        /// </summary>
        /// <param name="favoriteItem">参数:选品库产品</param>
        /// <param name="diploma">参数:淘宝API应用证书</param>
        /// <returns>返回:淘口令</returns>
        public string TpwdCreate(FavoriteItem favoriteItem, Diploma diploma)
        {
            try
            {
                TbkTpwdCreateRequest req = new TbkTpwdCreateRequest();
                if (favoriteItem.CouponClickUrl == null)
                {
                    req.Url = favoriteItem.ClickUrl;
                }
                else
                {
                    req.Url = favoriteItem.CouponClickUrl;
                }
                req.Text = favoriteItem.Title;

                req.Logo = favoriteItem.PictUrl;
                req.Ext  = "{}";
                TbkTpwdCreateResponse rsp = DefaultTopClient.Get(diploma.AppUrl, diploma.AppKey, diploma.AppSecret).Execute(req);
                return(rsp.Data.Model);
            }
            catch
            {
                return("未开通淘客佣金");
            }
        }
예제 #10
0
        public async Task <ActionResult <Diploma> > PostDiploma(Diploma diploma)
        {
            _context.Diploma.Add(diploma);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDiploma", new { id = diploma.Id }, diploma));
        }
예제 #11
0
        public async Task <IActionResult> PutDiploma(int id, Diploma diploma)
        {
            if (id != diploma.Id)
            {
                return(BadRequest());
            }

            _context.Entry(diploma).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DiplomaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #12
0
    /// <summary>
    /// แก้ไขข้อมูลจากตาราง DIPLOMA
    /// </summary>
    /// <param name="updateData">Diploma Object</param>
    /// <returns>Success</returns>
    public string updateDiploma(Diploma updateData)
    {
        string        response  = "";
        ConnectDB     db        = new ConnectDB();
        SqlDataSource oracleObj = db.ConnectionOracle_tqf2();

        string sql = "Update DIPLOMA Set DOMAINTHNAME = '" + updateData.DomainThName + "', DOMAINENNAME = '" + updateData.DomainEnName + "', DOMAINTHSHORTNAME = '" + updateData.DomainThShortName + "', DOMAINENSHORTNAME = '" + updateData.DomainEnShortName + "' Where YEARVERSION = '" + updateData.YearVersion + "' And  DIPLOMACODE = '" + updateData.DiplomaCode + "' And  CURRCODE = '" + updateData.CurrCode + "'";

        oracleObj.UpdateCommand = sql;

        try
        {
            if (oracleObj.Update() == 1)
            {
                response = "Success";
            }
        }
        catch (Exception e)
        {
            string exception = e.Message;
            HttpContext.Current.Session["response"] = "updateDiploma: " + exception;
            HttpContext.Current.Response.Redirect("../err_response.aspx");
        }

        return(response);
    }
        public void Test_Diploma_Requirements_Is_Null_Throws_Argument_Null_Exception()
        {
            var tracker = new Bl.GraduationTracker(new Repository());

            var diploma = new Diploma
            {
                Id             = 1,
                Credits        = 4,
                RequirementIds = null
            };

            var student = new Student
            {
                Id      = 1,
                Courses = new[]
                {
                    new Course {
                        Id = 1, Name = "Math", Mark = 20, Credits = 1
                    },
                }
            };

            TestHelperExtensions.Throw <ArgumentException>(() => tracker.HasGraduated(diploma, student),
                                                           $"{nameof(Requirement)}");
        }
예제 #14
0
        /// <summary>
        /// Busines Logic to derieve average
        /// </summary>
        /// <param name="student">Student info</param>
        /// <param name="diploma">Diploma info</param>
        /// /// <returns>average</returns>
        private int CalculateAverage(Student student, Diploma diploma)
        {
            try
            {
                var credits = 0;
                var average = 0;

                foreach (var d in diploma.Requirements)
                {
                    foreach (var s in student.Courses)
                    {
                        var requirement = Repository.GetRequirement(d);

                        foreach (var req in requirement.Courses)
                        {
                            if (req == s.Id)
                            {
                                average += s.Mark;
                                if (s.Mark > requirement.MinimumMark)
                                {
                                    credits += requirement.Credits;
                                }
                            }
                        }
                    }
                }

                return(average / student.Courses.Length);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void Test_Failed_When_Dont_Has_All_Requirements()
        {
            var tracker = new Bl.GraduationTracker(new Repository());

            var diploma = new Diploma
            {
                Id             = 1,
                Credits        = 4,
                RequirementIds = new[] { 100, 102, 103, 104 }
            };

            var student = new Student
            {
                Id      = 1,
                Courses = new[]
                {
                    new Course {
                        Id = 1, Name = "Math", Mark = 100, Credits = 1
                    },
                    new Course {
                        Id = 2, Name = "Science", Mark = 100, Credits = 1
                    },
                    new Course {
                        Id = 3, Name = "Literature", Mark = 100, Credits = 1
                    },
                }
            };

            var result = tracker.HasGraduated(diploma, student);

            Assert.IsFalse(result.Item1);
        }
        /// <summary>
        /// Busines Logic to derieve average
        /// </summary>
        /// <param name="student">Student info</param>
        /// <param name="diploma">Diploma info</param>
        /// /// <returns>average</returns>
        private int CalculateAverage(Student student, Diploma diploma)
        {
            try
            {
                var credits = 0;
                var average = 0;
                for (int i = 0; i < diploma.Requirements.Length; i++)
                {
                    for (int j = 0; j < student.Courses.Length; j++)
                    {
                        var requirement = Repository.GetRequirement(diploma.Requirements[i]);

                        for (int k = 0; k < requirement.Courses.Length; k++)
                        {
                            if (requirement.Courses[k] == student.Courses[j].Id)
                            {
                                average += student.Courses[j].Mark;
                                if (student.Courses[j].Mark > requirement.MinimumMark)
                                {
                                    credits += requirement.Credits;
                                }
                            }
                        }
                    }
                }

                return(average / student.Courses.Length);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #17
0
        public async Task <IHttpActionResult> PutDiploma(int id, Diploma diploma)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != diploma.Id)
            {
                return(BadRequest());
            }

            db.Entry(diploma).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DiplomaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(diploma));
        }
예제 #18
0
    /// <summary>
    /// เรียกดูข้อมูลจากตาราง DIPLOMA
    /// </summary>
    /// <param name="sql">SQL Command</param>
    /// <returns>ข้อมูลจากตาราง DIPLOMA</returns>
    public List <Diploma> getDiplomaManual(string sql)
    {
        List <Diploma> DiplomaData = new List <Diploma>();

        ConnectDB     db        = new ConnectDB();
        SqlDataSource oracleObj = db.ConnectionOracle_tqf2();

        oracleObj.SelectCommand = sql;

        DataView allData = (DataView)oracleObj.Select(DataSourceSelectArguments.Empty);

        foreach (DataRowView rowData in allData)
        {
            Diploma DiplomaRow = new Diploma();

            DiplomaRow.YearVersion       = rowData["YEARVERSION"].ToString();
            DiplomaRow.DiplomaCode       = rowData["DIPLOMACODE"].ToString();
            DiplomaRow.CurrCode          = rowData["CURRCODE"].ToString();
            DiplomaRow.DomainThName      = rowData["DOMAINTHNAME"].ToString();
            DiplomaRow.DomainEnName      = rowData["DOMAINENNAME"].ToString();
            DiplomaRow.DomainThShortName = rowData["DOMAINTHSHORTNAME"].ToString();
            DiplomaRow.DomainEnShortName = rowData["DOMAINENSHORTNAME"].ToString();

            DiplomaData.Add(DiplomaRow);
        }

        return(DiplomaData);
    }
예제 #19
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool Update(Diploma entity)
        {
            HibernateTemplate.Update(entity);
            return(true);

            throw new NotImplementedException();
        }
예제 #20
0
 public virtual void Update(Diploma entity)
 {
     if (entity != null)
     {
         var index = DbSet.Diplomas.FindIndex(x => x.Id == entity.Id);
         DbSet.Diplomas[index] = entity;
     }
 }
예제 #21
0
        /// <summary>
        /// Reterive specific Diploma info from diploma repo
        /// </summary>
        /// <param name="id">Identify</param>
        /// <returns>Diploma Model</returns>
        public static Diploma GetDiploma(int id)
        {
            GetRecords       gr      = new GetRecords();
            getDiplomaValues gdv     = new getDiplomaValues();
            Diploma          diploma = gr.GetValues(gdv, id);

            return(diploma);
        }
        public void TestDiplomaNullTest()
        {
            Diploma diploma      = null;
            var     actualResult = graduationTracker.HasGraduated(diploma, students[0]);
            Tuple <bool, STANDING> expectedResult = new Tuple <bool, STANDING>(false, STANDING.None);

            Assert.AreEqual(actualResult, expectedResult);
        }
예제 #23
0
 public virtual void Delete(Diploma entity)
 {
     if (entity != null)
     {
         var index = DbSet.Diplomas.FindIndex(x => x.Id == entity.Id);
         DbSet.Diplomas.RemoveAt(index);
     }
 }
예제 #24
0
파일: Request.cs 프로젝트: pazhe/JiazheWeb
        public string TbkTpwdParse(string TbkTpwd, Diploma diploma)
        {
            TbkTpwdParseRequest req = new TbkTpwdParseRequest();

            req.PasswordContent = "¥asaff¥";
            TbkTpwdParseResponse rsp = DefaultTopClient.Get(diploma.AppUrl, diploma.AppKey, diploma.AppSecret).Execute(req);

            return(rsp.Data.Model);
        }
        public void TestStudentAndDiplomaNullTest()
        {
            Diploma nullDiploma = null;
            Student nullStudent = null;

            var actualResult = graduationTracker.HasGraduated(nullDiploma, nullStudent);
            Tuple <bool, STANDING> expectedResult = new Tuple <bool, STANDING>(false, STANDING.None);

            Assert.AreEqual(actualResult, expectedResult);
        }
예제 #26
0
        /// <summary>
        ///     Saves a diploma instance in the database
        /// </summary>
        /// <param name="diploma">The diploma to save or update</param>
        /// <returns>The amount of rows affected</returns>
        public static async Task <int> Save(Diploma diploma)
        {
            var connection = await GetConnection();

            // Insert or update
            return(await connection.ExecuteAsync(diploma.Diploma_ID == null
                                                 ? "INSERT INTO diploma(Dog_ID, Date_of_exam, Note) VALUES(@DogId, @DateOfExam, @Note)"
                                                 : "UPDATE diploma SET Dog_ID = @DogId, Date_of_exam = @DateOfExam, Note = @Note WHERE Diploma_ID = @DiplomaId"
                                                 , new { DiplomaId = diploma.Diploma_ID, DogId = diploma.Dog_ID, DateOfExam = diploma.Date_of_exam, diploma.Note }));
        }
        public void HasGraduated_StudentWith95Average_MagnaCumLaudeTest()
        {
            diploma = CreateDiploma();
            var student = CreateStudents().Where(s => s.Id == 1).FirstOrDefault();

            tracker = CreateGraduationTracker();

            Assert.IsTrue(tracker.HasGraduated(diploma, student).Graduated);
            Assert.IsTrue(tracker.HasGraduated(diploma, student).Standing == STANDING.MagnaCumLaude);
        }
예제 #28
0
        public void Test2HasGraduated()
        {
            Diploma diploma = new Diploma();
            Student student = new Student();
            RequirementRepository requRepo = new RequirementRepository();

            diploma = new Diploma
            {
                Id           = 1,
                Credits      = 4,
                Requirements = new List <Requirement>()
                {
                    new Requirement()
                    {
                        Id = 100
                    }, new Requirement()
                    {
                        Id = 102
                    }, new Requirement()
                    {
                        Id = 103
                    }, new Requirement()
                    {
                        Id = 104
                    }
                }
            };

            student = new Student
            {
                Id        = 3,
                DiplomaId = 1,
                Courses   = new Course[]
                {
                    new Course {
                        CourseId = 1, CourseName = "Math", Mark = 50
                    },
                    new Course {
                        CourseId = 2, CourseName = "Science", Mark = 50
                    },
                    new Course {
                        CourseId = 3, CourseName = "Literature", Mark = 50
                    },
                    new Course {
                        CourseId = 4, CourseName = "Physichal Education", Mark = 50
                    }
                }
            };

            var  actual   = new GraduationTracker(requRepo, student, diploma).HasGraduated();
            bool expected = true;

            // Is Graduated
            Assert.AreEqual(expected, actual.Item1);
        }
예제 #29
0
        public void Test1GraduationStanding()
        {
            Diploma diploma = new Diploma();
            Student student = new Student();
            RequirementRepository requRepo = new RequirementRepository();

            diploma = new Diploma
            {
                Id           = 1,
                Credits      = 4,
                Requirements = new List <Requirement>()
                {
                    new Requirement()
                    {
                        Id = 100
                    }, new Requirement()
                    {
                        Id = 102
                    }, new Requirement()
                    {
                        Id = 103
                    }, new Requirement()
                    {
                        Id = 104
                    }
                }
            };

            student = new Student
            {
                Id        = 1,
                DiplomaId = 1,
                Courses   = new Course[]
                {
                    new Course {
                        CourseId = 1, CourseName = "Math", Mark = 95
                    },
                    new Course {
                        CourseId = 2, CourseName = "Science", Mark = 95
                    },
                    new Course {
                        CourseId = 3, CourseName = "Literature", Mark = 95
                    },
                    new Course {
                        CourseId = 4, CourseName = "Physichal Education", Mark = 95
                    }
                }
            };

            var      actual           = new GraduationTracker(requRepo, student, diploma).HasGraduated();
            STANDING expectedStanding = STANDING.MagnaCumLaude;

            // Standing
            Assert.AreEqual(expectedStanding, actual.Item2);
        }
예제 #30
0
        public void TestEmptyListItems()
        {
            var tracker = new GraduationTracker();

            var diploma = new Diploma();
            var student = new Student();

            var result = tracker.HasGraduated(diploma, student);

            Assert.IsFalse(result.Item1);
        }
예제 #31
0
        public ActionResult Create(CreateDiplomaViewModel viewModel)
        {
            if (this.ModelState.IsValid)
            {
                var teacher = this.teachers.GetByUserId(this.User.Identity.GetUserId()).FirstOrDefault();

                // create diploma
                var diploma = new Diploma()
                {
                    Teacher = teacher,
                    Title = viewModel.Title,
                    Description = viewModel.Description,
                    ExperimentalPart = viewModel.ExperimentalPart,
                    ContentCSV = string.Join(GlobalConstants.ContentSeparator.ToString(), viewModel.ContentCSV),
                };

                var listOfTags = new List<Tag>();
                foreach (var viewModelTag in viewModel.TagsNames)
                {
                    var tagId = 0;
                    Tag tag;
                    if (int.TryParse(viewModelTag, out tagId))
                    {
                        tag = this.tags.GetObjectById(tagId);
                    }
                    else
                    {
                        tag = this.tags.EnsureCategory(viewModelTag);
                    }

                    listOfTags.Add(tag);
                }

                diploma.Tags = listOfTags;

                // add diploma to teacher
                this.teachers.AddDiploma(teacher.Id, diploma);
                this.TempData["Message"] = "Дипломата е създадена!";

                return this.RedirectToAction("Index", "ManageDiplomas");
            }

            return this.View(viewModel);
        }