public IActionResult GetCourseByCourseId(long courseId)
        {
            // Fetch data from database
            CourseVO courseVO = null;

            try
            {
                Course course = _iCourseService.GetCourseByCourseId(courseId);
                courseVO = new CourseVO(course);

                return(Json(courseVO));
            }
            //If not found, 返回404
            catch (CourseNotFoundException)
            {
                return(NotFound(new { msg = "未找到该课程!" }));
            }
            //courseId格式错误,返回400
            catch (ArgumentException)
            {
                return(BadRequest(new { msg = "错误的ID格式!" }));
            }
            //catch (Exception)
            //{
            //}
        }
Esempio n. 2
0
    public Boolean DeleteCourse(CourseVO inCourse)
    {
        // Add business validations if any
        Boolean courseCode = courseobj.DeleteCourse(inCourse);

        return(courseCode);
    }
 public InsertCoursViewModel(EMMainViewModel centralEMMain) : base(centralEMMain)
 {
     Subtitle      = "Insertar Cursos";
     this.CourseVO = new CourseVO()
     {
         Id = Guid.NewGuid()
     };
 }
Esempio n. 4
0
        public async Task <CourseVO> AddTaskAsync(CourseVO course)
        {
            if (await _courseRepository.AddTaskAsync(_courseConverter.Parse(course)) is CourseModel courseModel)
            {
                return(_courseConverter.Parse(courseModel));
            }

            return(null);
        }
Esempio n. 5
0
    public bool Equals(CourseVO obj)
    {
        return(ID == obj.ID

               /*
                * && Name == obj.Name
                */
               );
    }
Esempio n. 6
0
        public async Task <CourseVO> UpdateTaskAsync(CourseVO newCourse)
        {
            if (await _courseRepository.FindByCourseIdTaskAsync(newCourse.CourseId) is CourseModel currentCourse)
            {
                return(_courseConverter.Parse(await _courseRepository.UpdateTaskAsync(currentCourse, _courseConverter.Parse(newCourse))));
            }

            return(null);
        }
        public async Task <IActionResult> UpdateTaskAsync([FromBody] DisciplineVO newDiscipline)
        {
            if (ModelState.IsValid)
            {
                if (!(await _disciplineBusiness.FindByDisciplineIdTaskAsync(newDiscipline.DisciplineId) is DisciplineVO currentDiscipline))
                {
                    return(NotFound("Não existe uma disciplina com esse Id"));
                }

                CourseVO course = await _courseBusiness.FindByCourseIdTaskAsync(currentDiscipline.CourseId);

                if (course.CoordinatorId != Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
                {
                    return(Unauthorized("Você não tem autorizaçao para alterar uma disciplina de outro curso!"));
                }

                newDiscipline.CourseId = course.CourseId;

                if (await _disciplineBusiness.ExistsByNameAndCourseIdTaskAsync(newDiscipline.Name, newDiscipline.CourseId))
                {
                    if (newDiscipline.Name != currentDiscipline.Name)
                    {
                        return(Conflict("Ja existe uma disciplina com esse nome"));
                    }
                }

                if (string.IsNullOrEmpty(newDiscipline.Name))
                {
                    return(BadRequest("É necessario informar o nome da disciplina!"));
                }

                if (string.IsNullOrEmpty(newDiscipline.Teacher))
                {
                    return(BadRequest("É necessario informar o nome do professor!"));
                }

                if (newDiscipline.Period <= 0)
                {
                    return(BadRequest("O periodo precisa ser maior que zero!"));
                }

                if (newDiscipline.ClassId == Guid.Empty)
                {
                    return(BadRequest("É necessario informar a sala!"));
                }

                if (await _disciplineBusiness.UpdateTaskAync(newDiscipline) is DisciplineVO disciplineUpdated)
                {
                    return(Created($"/Disciplines/{disciplineUpdated.DisciplineId}", disciplineUpdated));
                }
            }

            return(BadRequest());
        }
Esempio n. 8
0
    public CourseVO GetCourseDetailsForCourseCode(string incourseCode)
    {
        CourseVO courseVO = new CourseVO();

        try{
            courseVO = courseobj.GetCourseDetailsForCourseCode(incourseCode);
        }
        catch (CustomException e)
        {
            throw e;
        }
        return(courseVO);
    }
Esempio n. 9
0
    public string AddCourse(CourseVO inCourse)
    {
        string status = "";

        try
        {
            status = courseobj.AddCourse(inCourse);
        }
        catch (CustomException e)
        {
            throw e;
        }
        return(status);
    }
Esempio n. 10
0
    public string UpdateCourse(CourseVO inCourse, string originalCourseCode)
    {
        string status = "";

        try
        {
            status = courseobj.UpdateCourse(inCourse, originalCourseCode);
        }
        catch (CustomException e)
        {
            throw e;
        }
        return(status);
    }
Esempio n. 11
0
    //Get course details for given course code
    public CourseVO GetCourseDetailsForCourseCode(string incourseCode)
    {
        CourseVO courseVO = new CourseVO();

        try
        {
            DBConnection.conn.Open();
            string query = "SELECT Title,Credits,Level,AllPrerequisites,OfferedFrequency,Active from dbo.Course c" +
                           " LEFT JOIN dbo.CoursePrerequisite cp ON cp.CourseCode=c.CourseCode AND Active='Yes'" +
                           " WHERE c.CourseCode = @CourseCode";
            SqlCommand cmd = new SqlCommand(query, DBConnection.conn);
            cmd.Parameters.AddWithValue("@CourseCode", incourseCode);
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    courseVO.CourseCode = incourseCode;
                    courseVO.Title      = reader["Title"].ToString();
                    courseVO.Credits    = Int32.Parse(reader["Credits"].ToString());
                    courseVO.Level      = Int32.Parse(reader["Level"].ToString());
                    courseVO.Prerequisites.AllPrerequisites = reader["AllPrerequisites"].ToString();
                    courseVO.OfferedFrequency = reader["OfferedFrequency"].ToString();
                    courseVO.Active           = reader["Active"].ToString();
                }
            }
        }
        catch (SqlException e)
        {
            ExceptionUtility.LogException(e, "Error Page");
            throw new CustomException(ApplicationConstants.UnhandledException + ": " + e.Message);
        }
        catch (Exception e)
        {
            ExceptionUtility.LogException(e, "Error Page");
            throw new CustomException(ApplicationConstants.UnhandledException + ": " + e.Message);
        }
        finally
        {
            if (DBConnection.conn != null)
            {
                DBConnection.conn.Close();
            }
        }
        return(courseVO);
    }
Esempio n. 12
0
        public async Task <IActionResult> AddClassTaskAsync([FromBody] CourseVO newCourse)
        {
            if (ModelState.IsValid)
            {
                var coordId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

                if (!(await _coordinatorBusiness.FindByCoordIdTaskAsync(coordId) is AuthCoordinatorVO coordinator))
                {
                    return(NotFound("Não existe nenhum coordenador com o Id informado"));
                }

                if (await _courseBusiness.FindByCoordIdTaskAsync(coordId) is CourseVO)
                {
                    return(Conflict("Ja existe um curso com o coordenador informado!"));
                }

                if (string.IsNullOrEmpty(newCourse.Name))
                {
                    return(BadRequest("É necessario informar o nome do curso!"));
                }

                if (newCourse.Periods <= 0)
                {
                    return(BadRequest("A quantidade de periodos precisa ser maior que zero"));
                }

                if (await _courseBusiness.ExistsWithNameTaskAsync(newCourse.Name))
                {
                    return(Conflict("Ja existe um curso com esse nome"));
                }

                newCourse.CoordinatorId = coordinator.CoordinatorId;
                newCourse.CourseId      = coordinator.CourseId;

                if (await _courseBusiness.AddTaskAsync(newCourse) is CourseVO addedCourse)
                {
                    return(Created("/courses", addedCourse));
                }

                return(BadRequest("Algo deu errado, Tente novamente!"));
            }

            return(BadRequest());
        }
Esempio n. 13
0
        public async Task <IActionResult> UpdateTaskAsync([FromBody] CourseVO newCourse)
        {
            if (ModelState.IsValid)
            {
                var coordId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

                if (!(await _courseBusiness.FindByCourseIdTaskAsync(newCourse.CourseId) is CourseVO currentCourse))
                {
                    return(NotFound("Não existe nenhum curso com esse Id"));
                }

                if (currentCourse.CoordinatorId != coordId)
                {
                    return(Unauthorized("Você não tem permissão para alterar informações do curso onde não é coordenador!"));
                }

                if (string.IsNullOrEmpty(newCourse.Name))
                {
                    return(BadRequest("É necessario informar o nome do curso!"));
                }

                if (newCourse.Periods <= 0)
                {
                    return(BadRequest("A quantidade de periodos precisa ser maior que zero"));
                }

                if (await _courseBusiness.ExistsWithNameTaskAsync(newCourse.Name))
                {
                    if (newCourse.Name != currentCourse.Name)
                    {
                        return(Conflict("Ja existe um curso com esse nome!"));
                    }
                }

                if (await _courseBusiness.UpdateTaskAsync(newCourse) is CourseVO updatedCourse)
                {
                    return(Created("/Courses", updatedCourse));
                }
            }

            return(BadRequest());
        }
Esempio n. 14
0
        public async Task <ResultModel <CourseVO> > AddCourseTaskAsync(CourseVO newCourse, string token)
        {
            IRestResponse resp = await SendRequestTaskAsync(newCourse, token);

            return(resp.StatusCode switch
            {
                HttpStatusCode.Created => new ResultModel <CourseVO>
                {
                    Object = JsonSerializer.Deserialize <CourseVO>(resp.Content, new JsonSerializerOptions {
                        PropertyNameCaseInsensitive = true
                    }),
                    StatusCode = resp.StatusCode,
                    Message = "Curso criado com sucesso!"
                },

                _ => new ResultModel <CourseVO>
                {
                    StatusCode = resp.StatusCode,
                    Message = resp.Content.Replace("\"", string.Empty)
                }
            });
        public IActionResult GetCourses()
        {
            List <CourseVO> courseVOList = null;

            try
            {
                //根据教师id获得其教的所有课程
                IList <Course> courseList = _iCourseService.ListCourseByUserId(User.Id());
                //针对每个课程查询具体信息
                courseVOList = new List <CourseVO>();
                foreach (var i in courseList)
                {
                    //根据课程获得该课程的所有班级
                    List <ClassInfo> classList = (List <ClassInfo>)_iClassService.ListClassByCourseId(i.Id);
                    int numClass = classList.Count;
                    //计算该课程共有多少个学生
                    int numStudent = 0;
                    foreach (var j in classList)
                    {
                        //将每个班的学生相加
                        List <UserInfo> studentList = (List <UserInfo>)_iUserService.ListUserByClassId(j.Id, null, null);
                        numStudent += studentList.Count;
                    }
                    CourseVO courseVO = new CourseVO(i, numClass, numStudent);
                    courseVOList.Add(courseVO);
                }

                return(Json(courseVOList));
            }
            catch (UserNotFoundException)
            {
                return(NotFound(new { msg = "该用户不存在!" }));
            }catch (ArgumentException)
            {
                return(BadRequest());
            }
            //catch
            //{
            //}
        }
Esempio n. 16
0
    // delete the course using coursecode
    public Boolean DeleteCourse(CourseVO inCourse)
    {
        string courseCode = "";

        try
        {
            DBConnection.conn.Open();
            String     query = "DELETE FROM dbo.Course where courseCode=@CourseCode";
            SqlCommand cmd   = new SqlCommand(query, DBConnection.conn);
            cmd.Parameters.AddWithValue("@CourseCode", inCourse.CourseCode);
            // Add other parameters here
            int result = cmd.ExecuteNonQuery();
            if (result > 0)
            {
                courseCode = inCourse.CourseCode;
            }
        }
        catch (SqlException e)
        {
            ExceptionUtility.LogException(e, "Error Page");
            throw new CustomException(ApplicationConstants.UnhandledException + ": " + e.Message);
        }
        catch (Exception e)
        {
            ExceptionUtility.LogException(e, "Error Page");
            throw new CustomException(ApplicationConstants.UnhandledException + ": " + e.Message);
        }
        finally
        {
            if (DBConnection.conn != null)
            {
                DBConnection.conn.Close();
            }
        }
        return(true);
    }
Esempio n. 17
0
    // Add the course details into course, course prequiiste and course programme tables
    public string AddCourse(CourseVO inCourse)
    {
        string         status      = "";
        SqlTransaction transaction = null;

        try
        {
            DBConnection.conn.Open();
            // Start a local transaction.
            transaction = DBConnection.conn.BeginTransaction(IsolationLevel.ReadCommitted);
            String     query = "INSERT INTO dbo.Course (CourseCode, Title, Credits, Level, OfferedFrequency, Active, CreatedDTM, UpdatedDTM) VALUES (@CourseCode,@Title,@Credits, @Level, @OfferedFrequency,@Active,@CreatedDTM,@UpdatedDTM)";
            SqlCommand cmd   = new SqlCommand(query, DBConnection.conn);
            cmd.Transaction = transaction;
            cmd.Parameters.AddWithValue("@CourseCode", inCourse.CourseCode);
            cmd.Parameters.AddWithValue("@Title", inCourse.Title);
            cmd.Parameters.AddWithValue("@Credits", inCourse.Credits);
            cmd.Parameters.AddWithValue("@Level", inCourse.Level);
            cmd.Parameters.AddWithValue("@OfferedFrequency", inCourse.OfferedFrequency);
            cmd.Parameters.AddWithValue("@Active", inCourse.Active);
            cmd.Parameters.AddWithValue("@CreatedDTM", DateTime.Now);
            cmd.Parameters.AddWithValue("@UpdatedDTM", DateTime.Now);
            cmd.Transaction = transaction;
            // Add other parameters here
            int result = cmd.ExecuteNonQuery();
            if (result > 0)
            {
                if (inCourse.Program.Count > 0)
                {
                    foreach (CourseProgrammeVO cp in inCourse.Program)
                    {
                        String     query1 = "INSERT INTO dbo.CourseProgramme (CourseCode, ProgrammeID, MajorID, CourseType) VALUES (@CourseCode,@ProgrammeID,@MajorID, @CourseType)";
                        SqlCommand cmd1   = new SqlCommand(query1, DBConnection.conn);
                        cmd1.Transaction = transaction;
                        cmd1.Parameters.AddWithValue("@CourseCode", inCourse.CourseCode);
                        cmd1.Parameters.AddWithValue("@ProgrammeID", cp.ProgrammeId);
                        cmd1.Parameters.AddWithValue("@MajorID", cp.MajorId);
                        cmd1.Parameters.AddWithValue("@CourseType", cp.CourseType);
                        string temp = inCourse.CourseCode + cp.ProgrammeId + cp.MajorId + cp.CourseType;
                        cmd1.Transaction = transaction;
                        int result1 = cmd1.ExecuteNonQuery();
                        if (result1 < 0)
                        {
                            status = "Course Programme addition failed";
                            break;
                        }
                        else
                        {
                            status = "Course added successfully";
                        }
                    }
                }
                if (!status.Contains("failed") && inCourse.Prerequisites.CourseCode != null)
                {
                    String     query2 = "INSERT INTO dbo.CoursePrerequisite (CourseCode, PrerequisiteCode, PrerequisiteType, AllPrerequisites) VALUES (@CourseCode,@PrerequisiteCode,@PrerequisiteType, @AllPrerequisites)";
                    SqlCommand cmd2   = new SqlCommand(query2, DBConnection.conn);
                    cmd2.Transaction = transaction;
                    cmd2.Parameters.AddWithValue("@CourseCode", inCourse.CourseCode);
                    cmd2.Parameters.AddWithValue("@PrerequisiteCode", inCourse.Prerequisites.PrerequisiteCode);
                    cmd2.Parameters.AddWithValue("@PrerequisiteType", inCourse.Prerequisites.Type);
                    cmd2.Parameters.AddWithValue("@AllPrerequisites", inCourse.Prerequisites.AllPrerequisites);
                    cmd2.Transaction = transaction;
                    int result2 = cmd2.ExecuteNonQuery();
                    if (result2 < 0)
                    {
                        status = "Course Prerequisite addition failed";
                    }
                    else
                    {
                        status = "Course added successfully";
                    }
                }
                transaction.Commit();
            }
            else
            {
                status = "Course addition failed";
            }
        }
        catch (SqlException e)
        {
            ExceptionUtility.LogException(e, "Error Page");
            if (e.Number == 2627)
            {
                status = "CourseCode already exists";
            }
            else
            {
                transaction.Rollback();
                throw new CustomException(ApplicationConstants.UnhandledException + ": " + e.Message);
            }
        }
        catch (Exception e)
        {
            ExceptionUtility.LogException(e, "Error Page");
            transaction.Rollback();
            throw new CustomException(ApplicationConstants.UnhandledException + ": " + e.Message);
        }
        finally
        {
            if (DBConnection.conn != null)
            {
                DBConnection.conn.Close();
            }
        }
        return(status);
    }
Esempio n. 18
0
    protected void BtnUpload_Click(object sender, EventArgs e)
    {
        string          existingCourse = "";
        string          failedCourses  = "";
        bool            courseExists   = false;
        List <CourseVO> courseVOList   = new List <CourseVO>();

        try
        {
            ICourseDao    courseDao = new CourseDaoImpl();
            List <string> existingCourseCodeList = courseDao.GetAllCourseCodeAsList();
            string        filepath = Server.MapPath("~/Files/") + Path.GetFileName(fuBulkCourseUpload.PostedFile.FileName);
            if (fuBulkCourseUpload.HasFile)
            {
                fuBulkCourseUpload.SaveAs(filepath);
                string  data = File.ReadAllText(filepath);
                Boolean headerRowHasBeenSkipped = false;
                foreach (string row in data.Split('\n'))
                {
                    if (headerRowHasBeenSkipped)
                    {
                        courseExists = false;
                        if (!string.IsNullOrEmpty(row))
                        {
                            CourseVO                 courseVO        = new CourseVO();
                            List <string>            pgmList         = new List <string>();
                            string                   courseType      = "COM";
                            int                      i               = 0;
                            List <CourseProgrammeVO> coursePgmVOList = new List <CourseProgrammeVO>();
                            foreach (string cell in row.Split(','))
                            {
                                if (!courseExists)
                                {
                                    string celltemp = "";
                                    if (cell.Contains("\r"))
                                    {
                                        celltemp = cell.Replace("\r", "").Trim();
                                    }
                                    else
                                    {
                                        celltemp = cell;
                                    }
                                    celltemp = celltemp.Trim();
                                    switch (i)
                                    {
                                    case 0:
                                    {
                                        if (existingCourseCodeList.Contains(celltemp))
                                        {
                                            existingCourse += celltemp + ",";
                                            courseExists    = true;
                                        }
                                        else
                                        {
                                            courseVO.CourseCode = celltemp;
                                        }
                                        break;
                                    }

                                    case 1:
                                    {
                                        courseVO.Title = celltemp;
                                        break;
                                    }

                                    case 2:
                                    {
                                        if (celltemp.Contains("&"))
                                        {
                                            foreach (string pgm in celltemp.Split('&'))
                                            {
                                                pgmList.Add(pgm.Trim());
                                            }
                                        }
                                        else
                                        {
                                            pgmList.Add(celltemp);
                                        }
                                        break;
                                    }

                                    case 3:
                                    {
                                        courseType = celltemp;
                                        break;
                                    }

                                    case 4:
                                    {
                                        if (celltemp.Contains("&"))
                                        {
                                            CourseProgrammeVO cp;
                                            foreach (string pgm in pgmList)
                                            {
                                                foreach (string mjr in celltemp.Split('&'))
                                                {
                                                    cp             = new CourseProgrammeVO();
                                                    cp.ProgrammeId = pgm.Trim();
                                                    cp.CourseType  = courseType.Trim();
                                                    cp.MajorId     = mjr.Trim();
                                                    coursePgmVOList.Add(cp);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            CourseProgrammeVO cp;
                                            foreach (string pgm in pgmList)
                                            {
                                                cp             = new CourseProgrammeVO();
                                                cp.ProgrammeId = pgm.Trim();
                                                cp.CourseType  = courseType.Trim();
                                                cp.MajorId     = celltemp.Trim();
                                                coursePgmVOList.Add(cp);
                                            }
                                        }
                                        break;
                                    }

                                    case 5:
                                    {
                                        courseVO.Credits = int.Parse(celltemp);
                                        break;
                                    }

                                    case 6:
                                    {
                                        courseVO.Level = int.Parse(celltemp);
                                        break;
                                    }

                                    case 7:
                                    {
                                        courseVO.OfferedFrequency = celltemp;
                                        break;
                                    }

                                    case 8:
                                    {
                                        if (celltemp != "NA")
                                        {
                                            courseVO.Prerequisites.AllPrerequisites = celltemp.Trim();
                                            courseVO.Prerequisites.CourseCode       = courseVO.CourseCode;
                                        }
                                        break;
                                    }

                                    case 9:
                                    {
                                        string allprerequisite = courseVO.Prerequisites.AllPrerequisites;
                                        if (celltemp != "NA")
                                        {
                                            if (allprerequisite != null)
                                            {
                                                courseVO.Prerequisites.AllPrerequisites = allprerequisite + "#" + celltemp;
                                            }
                                            else
                                            {
                                                courseVO.Prerequisites.AllPrerequisites = "#" + celltemp;
                                                courseVO.Prerequisites.CourseCode       = courseVO.CourseCode;
                                            }
                                        }
                                        else
                                        {
                                            courseVO.Prerequisites.AllPrerequisites = allprerequisite;
                                        }
                                        courseVO.Prerequisites.PrerequisiteCode = "";
                                        courseVO.Prerequisites.Type             = "Prerequisite";
                                        break;
                                    }
                                    }
                                }
                                i++;
                            }
                            if (!courseExists)
                            {
                                courseVO.Program = coursePgmVOList;
                                courseVOList.Add(courseVO);
                            }
                        }
                    }
                    headerRowHasBeenSkipped = true;
                }
                if (courseVOList.Count > 0)
                {
                    foreach (CourseVO courseVO in courseVOList)
                    {
                        courseVO.Active = "Yes";
                        string status = courseBO.AddCourse(courseVO);
                        if (status.Contains("fail"))
                        {
                            failedCourses += courseVO.CourseCode;
                        }
                    }
                    string usermessage = " Courses upload completed.";
                    if (failedCourses != "")
                    {
                        usermessage += " FailedCourseList " + failedCourses;
                    }
                    if (existingCourse != "")
                    {
                        usermessage += " Existing courses cannot be added. " + existingCourse;
                    }
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + usermessage + "');", true);
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert(' Uploaded courses exists already');", true);
                }
            }
        }

        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "Error Page");
            if (ex.Message.Contains("used by another process"))
            {
                Response.Write("<script>alert('CSV file is in use.Please close it and try again');</script>");
            }
            else
            {
                Response.Write("<script>alert('" + ex.Message + "');</script>");
            }
        }
        finally
        {
            if (DBConnection.conn != null)
            {
                DBConnection.conn.Close();
            }
        }
    }
Esempio n. 19
0
 public void ModifyCourse(CourseVO pCourse)
 {
     AddCourse(pCourse);
 }
Esempio n. 20
0
 public void AddCourse(CourseVO pCourse)
 {
     mCourses[pCourse.ID] = pCourse;
     update();
 }
Esempio n. 21
0
    public List <CourseVO> ModifyCourses(CourseVO[] pOriginalCourses, CourseVO[] pNewCourses, bool isForced = false)
    {
        List <CourseVO> result = new List <CourseVO>();

        try
        {
            AuthenticationService.CheckIfUSerIsAuthenticated();
            CourseTableAdapter adapter   = new CourseTableAdapter();
            string             logParams = "";
            bool modifyConflict          = false;

            for (int i = 0; i < Math.Min(pOriginalCourses.Length, pNewCourses.Length); ++i)
            {
                ONyRDataSet.CourseRow row = adapter.GetDataByID(pNewCourses[i].ID)[0];
                // TODO: Fill properties here
                // TODO: Watch out for null values!

                CourseVO vo = new CourseVO(row.ID);

                if (vo.Equals(pOriginalCourses[i]) || isForced)
                {
                    if (logParams.Length > 0)
                    {
                        logParams += ",\n";
                    }

                    result.Add(vo);

                    // TODO: Fill properties here
                    adapter.Update(pNewCourses[i].Name, vo.ID);
                    logParams += String.Format("Name:\"{0}\" => \"{1}\"", vo.Name, pNewCourses[i].Name);
                }
                else
                {
                    modifyConflict = true;
                }
            }

            adapter.Dispose();

            LogService.Log("CourseService", "ModifyCourses", logParams);

            if (modifyConflict)
            {
                throw new ONyRException(ErrorCode.ModifyConflict);
            }
        }
        catch (ONyRException e)
        {
            LogService.LogError(e.ErrorCode, e.StackTrace);
            throw new FaultException <ONyRFaultException>(new ONyRFaultException((int)e.ErrorCode));
        }
        catch (SqlException ex)
        {
            string s = "Class: " + ex.Class + "\n";
            for (int i = 0; i < ex.Errors.Count; i++)
            {
                s += "Index #" + i + "\n" +
                     "Message: " + ex.Errors[i].Message + "\n" +
                     "LineNumber: " + ex.Errors[i].LineNumber + "\n" +
                     "Source: " + ex.Errors[i].Source + "\n" +
                     "Procedure: " + ex.Errors[i].Procedure + "\n" +
                     "Class: " + ex.Errors[i].Class + "\n";
            }
            LogService.LogError(ErrorCode.UnknownError, null, s);
            throw new FaultException <ONyRFaultException>(new ONyRFaultException((int)ErrorCode.DatabaseError));
        }
        catch (Exception e)
        {
            LogService.LogError(ErrorCode.UnknownError, e.StackTrace, e.Message);
            throw new FaultException <ONyRFaultException>(new ONyRFaultException((int)ErrorCode.UnknownError));
        }

        return(result);
    }
Esempio n. 22
0
    private void AddNewRowToCourseGrid(ILMPCourseVO ilmpCourseVO)
    {
        if (ViewState["CurrentTable"] != null)
        {
            DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
            DataRow   drCurrentRow   = null;

            if (dtCurrentTable.Rows.Count > 0)
            {
                drCurrentRow = dtCurrentTable.NewRow();
                //add new row to DataTable
                dtCurrentTable.Rows.Add(drCurrentRow);
                //Store the current data to ViewState
                ViewState["CurrentTable"] = dtCurrentTable;
                for (int i = 0; i < dtCurrentTable.Rows.Count - 1; i++)
                {
                    if (i != dtCurrentTable.Rows.Count - 2)
                    {
                    }
                    else
                    {
                        DropDownList ddl1 = (DropDownList)gvIlmpCourse.Rows[i].Cells[2].FindControl("ddSemester");
                        DropDownList ddl2 = (DropDownList)gvIlmpCourse.Rows[i].Cells[3].FindControl("ddYear");

                        // Update the DataRow with the DDL Selected Items
                        dtCurrentTable.Rows[i]["Column1"] = ilmpCourseVO.CourseCode;
                        CourseProgrammeVO coursePgmVO = new CourseProgrammeVO();
                        coursePgmVO.CourseCode  = ilmpCourseVO.CourseCode;
                        coursePgmVO.ProgrammeId = studentMajorVO.ProgrammeID;
                        coursePgmVO.MajorId     = studentMajorVO.MajorID;
                        // for custom template, course may not be in same major selected

                        /*if (.SelectedItem.Text == "Generic")
                         * {
                         * ILMPCourseGridVO ilmpCourseGridVO = courseBO.GetCourseDetailsForTemplate(coursePgmVO);
                         * dtCurrentTable.Rows[i]["Column2"] = ilmpCourseGridVO.CourseType;
                         * dtCurrentTable.Rows[i]["Column5"] = ilmpCourseGridVO.Title;
                         * dtCurrentTable.Rows[i]["Column6"] = ilmpCourseGridVO.Credits;
                         * dtCurrentTable.Rows[i]["Column7"] = ilmpCourseGridVO.Level;
                         * dtCurrentTable.Rows[i]["Column8"] = ilmpCourseGridVO.Prerequisites;
                         * }
                         * else
                         * {*/
                        CourseVO courseVO = courseBO.GetCourseDetailsForCourseCode(coursePgmVO.CourseCode);
                        dtCurrentTable.Rows[i]["Column2"] = ilmpCourseVO.CourseType;
                        dtCurrentTable.Rows[i]["Column5"] = courseVO.Title;
                        dtCurrentTable.Rows[i]["Column6"] = courseVO.Credits;
                        dtCurrentTable.Rows[i]["Column7"] = courseVO.Level;
                        dtCurrentTable.Rows[i]["Column8"] = courseVO.Prerequisites.AllPrerequisites;
                        //}

                        FillSemesterDropDown(ddl1, coursePgmVO.CourseCode);
                        if (ddl1.SelectedItem != null && ddl1.SelectedItem.Text != "Select")
                        {
                            dtCurrentTable.Rows[i]["Column3"] = ilmpCourseVO.Semester; //ddl1.SelectedItem.Text;
                            FillYearDropDown(ddl2, coursePgmVO.CourseCode, int.Parse(ddl1.SelectedItem.Text));
                        }
                        if (ddl2.SelectedItem != null)
                        {
                            dtCurrentTable.Rows[i]["Column4"] = ilmpCourseVO.Year; //ddl2.SelectedItem.Text;
                        }
                    }
                }
                //Rebind the Grid with the current data
                gvIlmpCourse.DataSource = dtCurrentTable;
                gvIlmpCourse.DataBind();
            }
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('ViewState is null ');", true);
            Response.Write("ViewState is null");
        }

        //Set Previous Data on Postbacks
        SetPreviousDataInCourseGrid();
    }
Esempio n. 23
0
    protected void btnAddCourse_Click(object sender, EventArgs e)
    {
        try
        {
            if (txtCourseCode.Text.Trim() == "")
            {
                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Please enter course code');", true);
                return;
            }
            else if (txtTitle.Text.Trim() == "")
            {
                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Please enter title');", true);
                return;
            }
            string   courseCode                = txtCourseCode.Text;
            string   title                     = txtTitle.Text;
            int      credits                   = Convert.ToInt32(ddlCredits.Text);
            int      level                     = Convert.ToInt32(ddlLevel.Text);
            string   offeredFrequency          = txtOfferedFrequency.Text;
            string   active                    = "Yes";
            DateTime createdDTM                = DateTime.Now;
            DateTime updatedDTM                = DateTime.Now;
            string   prerequisite              = "";
            List <CourseProgrammeVO> coursePgm = new List <CourseProgrammeVO>();

            CourseVO courseVO = new CourseVO(courseCode, title, credits, level, offeredFrequency, active, createdDTM, updatedDTM);
            // get listbox items and set in hidden field
            if (lbPrerequisite.Items.Count > 0)
            {
                string tempprequisite = "";
                for (int i = 0; i < lbPrerequisite.Items.Count; i++)
                {
                    tempprequisite += lbPrerequisite.Items[i].Value;
                    if (i != lbPrerequisite.Items.Count - 1)
                    {
                        tempprequisite += "&";
                    }
                }
                hfPrerequisite.Value = tempprequisite;
            }
            if (ddCorequisite.SelectedItem.Text != "Select")
            {
                hfPrerequisite.Value += "#" + ddCorequisite.SelectedItem.Text;
            }

            string allPrequisite = hfPrerequisite.Value;

            /*if (hfPrerequisite.Value.Trim() == "" && ddCorequisite.SelectedItem.Text == "Select")
             * {
             * }
             * else if (hfPrerequisite.Value.Trim() != "" && ddCorequisite.SelectedItem.Text != "Select")
             * {
             *  //allPrequisite = hfPrerequisite.Value.Substring(1);
             *  allPrequisite += "#" + ddCorequisite.SelectedItem.Text;
             * }
             * else if (hfPrerequisite.Value.Trim() != "Select")
             * {
             *  /*if (hfPrerequisite.Value.Length > 5)
             *      allPrequisite = hfPrerequisite.Value.Substring(1);
             *  else*/
            //  allPrequisite = hfPrerequisite.Value;

            /* }
             * else if (ddCorequisite.SelectedItem.Text != "Select")
             * {
             *   allPrequisite += "#" + ddCorequisite.SelectedItem.Text;
             * } */
            if (allPrequisite != "")
            {
                if (allPrequisite.StartsWith("&"))
                {
                    allPrequisite = allPrequisite.Substring(1);
                }
                CoursePrerequisiteVO prerequisiteVO = new CoursePrerequisiteVO(courseCode, prerequisite, "Prerequisite", allPrequisite);
                courseVO.Prerequisites = prerequisiteVO;
            }
            if (rbtnBIT.Checked)
            {
                foreach (ListItem cb in cblBITMajor.Items)
                {
                    if (cb.Selected)
                    {
                        CourseProgrammeVO coursePgmVO = new CourseProgrammeVO();
                        coursePgmVO.CourseCode  = courseCode;
                        coursePgmVO.ProgrammeId = rbtnBIT.Text;
                        coursePgmVO.MajorId     = cb.Value;
                        coursePgmVO.CourseType  = ddCourseType.SelectedItem.Text;
                        coursePgm.Add(coursePgmVO);
                    }
                }
            }
            if (rbtnGDIT.Checked)
            {
                foreach (ListItem cb in cblGDITMajor.Items)
                {
                    if (cb.Selected)
                    {
                        CourseProgrammeVO coursePgmVO = new CourseProgrammeVO();
                        coursePgmVO.CourseCode  = courseCode;
                        coursePgmVO.ProgrammeId = rbtnGDIT.Text;
                        coursePgmVO.MajorId     = cb.Value;
                        coursePgmVO.CourseType  = ddCourseType.SelectedItem.Text;
                        coursePgm.Add(coursePgmVO);
                    }
                }
            }
            if (coursePgm.Count >= 1)
            {
                courseVO.Program = coursePgm;
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Please select atleast one programme and major');", true);
                return;
            }
            string status = courseBO.AddCourse(courseVO);
            Response.Write("<script>alert('" + status + "');</script>");
        }
        catch (CustomException ex)
        {
            Response.Write("<script>alert('" + ex.Message + "');</script>");
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "Error Page");
            Response.Write("<script>alert('Error in adding course');</script>");
        }
    }
Esempio n. 24
0
    //update course details.To allow updation of coursecode, originalCourseCode paramater is used.
    public string UpdateCourse(CourseVO inCourse, string originalCourseCode)
    {
        string         status      = "";
        SqlTransaction transaction = null;

        try
        {
            DBConnection.conn.Open();
            transaction = DBConnection.conn.BeginTransaction(IsolationLevel.ReadCommitted);
            String     query = "UPDATE dbo.Course SET CourseCode=@CourseCode,Title=@Title,Credits=@Credits, Level=@Level, OfferedFrequency=@OfferedFrequency,Active=@Active,UpdatedDTM=@UpdatedDTM WHERE CourseCode=@OriginalCourseCode";
            SqlCommand cmd   = new SqlCommand(query, DBConnection.conn);
            cmd.Transaction = transaction;
            cmd.Parameters.AddWithValue("@CourseCode", inCourse.CourseCode);
            cmd.Parameters.AddWithValue("@Title", inCourse.Title);
            cmd.Parameters.AddWithValue("@Credits", inCourse.Credits);
            cmd.Parameters.AddWithValue("@Level", inCourse.Level);
            cmd.Parameters.AddWithValue("@OfferedFrequency", inCourse.OfferedFrequency);
            cmd.Parameters.AddWithValue("@Active", inCourse.Active);
            cmd.Parameters.AddWithValue("@UpdatedDTM", inCourse.UpdatedTime);
            cmd.Parameters.AddWithValue("@OriginalCourseCode", originalCourseCode);
            int result = cmd.ExecuteNonQuery();
            if (result > 0)
            {
                if (inCourse.Program.Count > 0)
                {
                    String     query11 = "DELETE FROM dbo.CourseProgramme  WHERE CourseCode=@CourseCode";
                    SqlCommand cmd11   = new SqlCommand(query11, DBConnection.conn);
                    cmd11.Transaction = transaction;
                    cmd11.Parameters.AddWithValue("@CourseCode", inCourse.CourseCode);
                    int result11 = cmd11.ExecuteNonQuery();
                    if (result11 < 0)
                    {
                        status = "Course Programme updation failed";
                    }
                    else
                    {
                        foreach (CourseProgrammeVO cp in inCourse.Program)
                        {
                            String     query1 = "INSERT INTO dbo.CourseProgramme (CourseCode, ProgrammeID, MajorID, CourseType) VALUES (@CourseCode,@ProgrammeID,@MajorID, @CourseType)";
                            SqlCommand cmd1   = new SqlCommand(query1, DBConnection.conn);
                            cmd1.Transaction = transaction;
                            cmd1.Parameters.AddWithValue("@CourseCode", inCourse.CourseCode);
                            cmd1.Parameters.AddWithValue("@ProgrammeID", cp.ProgrammeId);
                            cmd1.Parameters.AddWithValue("@MajorID", cp.MajorId);
                            cmd1.Parameters.AddWithValue("@CourseType", cp.CourseType);
                            int result1 = cmd1.ExecuteNonQuery();
                            if (result1 < 0)
                            {
                                status = "Course Programme updation failed";
                                break;
                            }
                            else
                            {
                                status = "Course updated successfully";
                            }
                        }
                    }
                }
                if (!status.Contains("failed") && inCourse.Prerequisites != null)
                {
                    string     query3 = "SELECT AllPrerequisites from dbo.CoursePrerequisite WHERE CourseCode=@CourseCode";
                    SqlCommand cmd3   = new SqlCommand(query3, DBConnection.conn);
                    cmd3.Transaction = transaction;
                    cmd3.Parameters.AddWithValue("@CourseCode", inCourse.CourseCode);
                    SqlDataReader reader = cmd3.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            string prerequisite = reader["AllPrerequisites"].ToString();
                        }
                        reader.Close();
                        String     query2 = "UPDATE dbo.CoursePrerequisite SET AllPrerequisites=@AllPrerequisites WHERE CourseCode=@CourseCode ";
                        SqlCommand cmd2   = new SqlCommand(query2, DBConnection.conn);
                        cmd2.Transaction = transaction;
                        cmd2.Parameters.AddWithValue("@CourseCode", inCourse.CourseCode);
                        if (inCourse.Prerequisites.AllPrerequisites == null)
                        {
                            inCourse.Prerequisites.AllPrerequisites = "";
                        }
                        cmd2.Parameters.AddWithValue("@AllPrerequisites", inCourse.Prerequisites.AllPrerequisites);
                        int result2 = cmd2.ExecuteNonQuery();
                        if (result2 < 0)
                        {
                            status = "Course Prerequisite updation failed";
                        }
                        else
                        {
                            status = "Course updated successfully";
                        }
                    }
                    else
                    {
                        reader.Close();
                        String     query2 = "INSERT INTO dbo.CoursePrerequisite (CourseCode, PrerequisiteCode, PrerequisiteType, AllPrerequisites) VALUES (@CourseCode,@PrerequisiteCode,@PrerequisiteType, @AllPrerequisites)";
                        SqlCommand cmd2   = new SqlCommand(query2, DBConnection.conn);
                        cmd2.Transaction = transaction;
                        cmd2.Parameters.AddWithValue("@CourseCode", inCourse.CourseCode);
                        cmd2.Parameters.AddWithValue("@PrerequisiteCode", "");
                        cmd2.Parameters.AddWithValue("@PrerequisiteType", "");
                        cmd2.Parameters.AddWithValue("@AllPrerequisites", inCourse.Prerequisites.AllPrerequisites);
                        cmd2.Transaction = transaction;
                        int result2 = cmd2.ExecuteNonQuery();
                        if (result2 < 0)
                        {
                            status = "Course Prerequisite updation failed";
                        }
                        else
                        {
                            status = "Course updated successfully";
                        }
                    }
                }
                transaction.Commit();
            }
            else
            {
                status = "Course updation failed";
            }
        }
        catch (SqlException e)
        {
            status = "Course updation failed";
            ExceptionUtility.LogException(e, "Error Page");
            transaction.Rollback();
            throw new CustomException(ApplicationConstants.UnhandledException + ": " + e.Message);
        }
        catch (Exception e)
        {
            status = "Course updation failed";
            ExceptionUtility.LogException(e, "Error Page");
            transaction.Rollback();
            throw new CustomException(ApplicationConstants.UnhandledException + ": " + e.Message);
        }
        finally
        {
            if (DBConnection.conn != null)
            {
                DBConnection.conn.Close();
            }
        }
        return(status);
    }
Esempio n. 25
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         String coursecode = Request.QueryString["coursecode"];
         hfCourseCode.Value = coursecode;
         SetInitialValues();
         CourseVO courseVO = courseBO.GetCourseDetailsForCourseCode(coursecode);
         txtCourseCode.Text       = courseVO.CourseCode;
         txtOfferedFrequency.Text = courseVO.OfferedFrequency;
         txtTitle.Text            = courseVO.Title;
         ddlLevel.SelectedValue   = courseVO.Level.ToString();
         ddlCredits.SelectedValue = courseVO.Credits.ToString();
         ddActive.SelectedValue   = courseVO.Active;
         string allPrequisites = "";
         allPrequisites = courseVO.Prerequisites.AllPrerequisites;
         // seperating the prerequisites and corequisite if it is present for the selected course
         if (allPrequisites != "")
         {
             // hfPrerequisite.Value = allPrequisites;
             string prerequisites = "";
             if (allPrequisites.Contains("#"))
             {
                 int    pos         = allPrequisites.IndexOf("#");
                 string corequisite = allPrequisites.Substring(pos + 1, 5);// 5 comes from length of any corequisite coursecode which is 5
                 ddCorequisite.SelectedValue = corequisite;
                 if (allPrequisites.Length > 6)
                 {
                     prerequisites = allPrequisites.Substring(0, pos);
                 }
             }
             else
             {
                 prerequisites = allPrequisites;
             }
             if (prerequisites != "")
             {
                 if (prerequisites.Contains("&"))
                 {
                     string[] prerequisiteArr = prerequisites.Split('&');
                     if (prerequisiteArr.Length > 0)
                     {
                         for (int count = 0; count < prerequisiteArr.Length; count++)
                         {
                             lbPrerequisite.Items.Add(prerequisiteArr[count]);
                         }
                     }
                 }
                 else
                 {
                     lbPrerequisite.Items.Add(prerequisites);
                     ddPrerequisite.SelectedItem.Value = prerequisites;
                 }
             }
         }
         List <CourseProgrammeVO> courseProgrammeList = courseProgrammeBO.GetCourseProgrammeForCourseCode(coursecode);
         foreach (CourseProgrammeVO coursePgmVO in courseProgrammeList)
         {
             if (coursePgmVO.ProgrammeId == "BIT")
             {
                 rbtnBIT.Checked = true;
                 cblBITMajor.Items.FindByValue(coursePgmVO.MajorId).Selected = true;
             }
             else if (coursePgmVO.ProgrammeId == "GDIT")
             {
                 rbtnGDIT.Checked = true;
                 cblGDITMajor.Items.FindByValue(coursePgmVO.MajorId).Selected = true;
             }
         }
     }
 }
Esempio n. 26
0
    private void AddNewRowToCourseGrid(TemplateCourseVO templateCourseVO)
    {
        if (ViewState["CurrentTable"] != null)
        {
            DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
            DataRow   drCurrentRow   = null;

            if (dtCurrentTable.Rows.Count > 0)
            {
                drCurrentRow = dtCurrentTable.NewRow();
                //add new row to DataTable
                dtCurrentTable.Rows.Add(drCurrentRow);
                //Store the current data to ViewState
                ViewState["CurrentTable"] = dtCurrentTable;
                for (int i = 0; i < dtCurrentTable.Rows.Count - 1; i++)
                {
                    if (i != dtCurrentTable.Rows.Count - 2)
                    {
                    }
                    else
                    {
                        DropDownList ddl1 = (DropDownList)gvIlmp.Rows[i].Cells[2].FindControl("ddSemester");
                        DropDownList ddl2 = (DropDownList)gvIlmp.Rows[i].Cells[3].FindControl("ddYear");

                        // Update the DataRow with the DDL Selected Items
                        dtCurrentTable.Rows[i]["Column1"] = templateCourseVO.CourseCode;
                        CourseProgrammeVO coursePgmVO = new CourseProgrammeVO();
                        coursePgmVO.CourseCode  = templateCourseVO.CourseCode;
                        coursePgmVO.ProgrammeId = ddProgramme.SelectedItem.Value;
                        coursePgmVO.MajorId     = ddMajor.SelectedItem.Value;
                        ILMPCourseGridVO ilmpCourseGridVO = new ILMPCourseGridVO();
                        // for custom template, course may not be in same major selected
                        if (rbtnILMPTemplateType.SelectedItem.Text == "Generic")
                        {
                            ilmpCourseGridVO = courseBO.GetCourseDetailsForTemplate(coursePgmVO);
                            dtCurrentTable.Rows[i]["Column2"] = ilmpCourseGridVO.CourseType;
                            dtCurrentTable.Rows[i]["Column5"] = ilmpCourseGridVO.Title;
                            dtCurrentTable.Rows[i]["Column6"] = ilmpCourseGridVO.Credits;
                            dtCurrentTable.Rows[i]["Column7"] = ilmpCourseGridVO.Level;
                            dtCurrentTable.Rows[i]["Column8"] = ilmpCourseGridVO.Prerequisites;
                        }
                        else
                        {
                            CourseVO courseVO = courseBO.GetCourseDetailsForCourseCode(coursePgmVO.CourseCode);
                            dtCurrentTable.Rows[i]["Column2"] = "COM";
                            dtCurrentTable.Rows[i]["Column5"] = courseVO.Title;
                            dtCurrentTable.Rows[i]["Column6"] = courseVO.Credits;
                            dtCurrentTable.Rows[i]["Column7"] = courseVO.Level;
                            dtCurrentTable.Rows[i]["Column8"] = courseVO.Prerequisites.AllPrerequisites;
                        }

                        // fills the semester dropdown from courseoffering. If there is any courseoffering, by default first value coming from db will be selected in semester dropdown
                        FillSemesterDropDown(ddl1, coursePgmVO.CourseCode);
                        // checks whether courseoffering is present by checking semster default selected value
                        if (ddl1.SelectedItem != null && ddl1.SelectedItem.Text != "Select")
                        {
                            dtCurrentTable.Rows[i]["Column3"] = templateCourseVO.Semester; //set the selected semester of dropdown to semester from ILMP template
                            FillYearDropDown(ddl2, coursePgmVO.CourseCode, int.Parse(ddl1.SelectedItem.Text));
                        }
                        if (ddl2.SelectedItem != null)
                        {
                            dtCurrentTable.Rows[i]["Column4"] = templateCourseVO.Year;//set the selected year of dropdown to year from ILMP template
                        }
                    }
                }
                //Rebind the Grid with the current data
                gvIlmp.DataSource = dtCurrentTable;
                gvIlmp.DataBind();
            }
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert(' ViewState is null ');", true);
            // Response.Write("ViewState is null");
        }

        //Set Previous Data on Postbacks
        SetPreviousDataInCourseGrid();
    }