public ActionResult UpdateAlumniRecord(int RecordID)
        {
            //method holds the record ID that need to be updated

            //a default value for action result
            ActionResult response = null;

            if (Session["RoleID"] != null)
            {
                //session that check if someone log in or none
                //if there is log in run the condition.
                //if there is none then go to else option

                if ((int)Session["RoleID"] == 1 || (int)Session["RoleID"] == 2 || (int)Session["RoleID"] == 3)
                {
                    //session that determine what user is log in.
                    //if any of these role is not log in then go to else option.

                    //an instance to hold new info from ViewModel specially the form.
                    AlumniVM alumniUpdateForm = new AlumniVM();

                    //identifier for data access object that holds the program,view alumni by ID.
                    AlumniDO mappedDataIDDo = AlumniDataAccessLayer.ViewAlumniRecordByID(RecordID);

                    //calling view model to populate the form with the exsisting info from the database
                    //then converting it to presentation object
                    alumniUpdateForm.AlumniForm = Mapper.MapAlumniDOtoPO(mappedDataIDDo);

                    //department data object identifier that holds program of read department method.
                    List <DepartmentDO> departmentObjectList = DepartmentDataAccessLayer.ReadDepartment();

                    //program that makes a dropdown option for department.
                    //calling the instance then targetting the dropdown then add to the list whichever run in to the foreach loop.
                    alumniUpdateForm.DepartmentDropDown.Add(new SelectListItem {
                        Text = "Please choose a department", Value = "0"
                    });
                    foreach (DepartmentDO departmentObject in departmentObjectList)
                    {
                        SelectListItem item = new SelectListItem();
                        item.Text  = departmentObject.DeptName;
                        item.Value = departmentObject.DeptID.ToString();
                        alumniUpdateForm.DepartmentDropDown.Add(item);
                    }
                    //showing the form with info and the dropdown department.
                    response = View(alumniUpdateForm);
                }
                else
                {
                    response = RedirectToAction("Index", "Home");
                }
            }
            else
            {
                response = RedirectToAction("Index", "Home");
            }
            //returning a populated form value or redirect.
            return(response);
        }
Beispiel #2
0
        public static AlumniDO MapAlumniBOtoDO(AlumniBO frmAlumniBO)
        {
            AlumniDO toAlumniDO = new AlumniDO();

            toAlumniDO.RecordID      = frmAlumniBO.RecordID;
            toAlumniDO.CompleteName  = frmAlumniBO.CompleteName;
            toAlumniDO.YearGraduated = frmAlumniBO.YearGraduated;
            toAlumniDO.Position      = frmAlumniBO.Position;
            toAlumniDO.Company       = frmAlumniBO.Company;
            toAlumniDO.ContactNumber = frmAlumniBO.ContactNumber;
            toAlumniDO.DepartmentID  = frmAlumniBO.DepartmentID;
            return(toAlumniDO);
        }
        public ActionResult UpdateAlumniRecord(AlumniVM updateForm)
        {
            //method holds whatever info does user add in the form.

            //a default value for action result
            ActionResult result = null;

            if (Session["RoleID"] != null)
            {
                //session that check if someone log in or none
                //if there is log in run the condition.
                //if there is none then go to else option

                if ((int)Session["RoleID"] == 1 || (int)Session["RoleID"] == 2 || (int)Session["RoleID"] == 3)
                {
                    //session that determine what user is log in.
                    //if any of these role is not log in then go to else option.

                    if (ModelState.IsValid)
                    {
                        //if everything is valid in a model state,run the program
                        //if it doesnt meet any requirements, run else option.

                        //a DO identifier that hold info from the form
                        //info coming from the form obtain form the user will be converted to data access
                        //object and be added to the database.
                        AlumniDO mappedDataUpdate = Mapper.MapAlumniPOtoDO(updateForm.AlumniForm);
                        AlumniDataAccessLayer.UpdateAlumniRecord(mappedDataUpdate);

                        //after it is added to database redirect to view to check new entry.
                        result = RedirectToAction("ViewAllAlumni");
                    }
                    else
                    {
                        //throwing a view form with a dropdown.
                        result = View(updateForm);
                    }
                }
                else
                {
                    result = RedirectToAction("Index", "Home");
                }
            }
            else
            {
                result = RedirectToAction("Index", "Home");
            }
            //returning a form ,a view all or a redirect.
            return(result);
        }
        public AlumniDO ViewAlumniRecordByID(int alumniID)
        {
            //the method hold alumniID info that will be coming from the controller and returns an object back to controller

            AlumniDO alumniObject = new AlumniDO();

            //an instance that is needed for the return.

            try
            {
                //needed to be able to catch an error if any of the properties or object or functions are not met.

                using (SqlConnection sqlConnection = new SqlConnection(connectionString))
                {
                    //connecting the program to the database
                    //where the stored procedure will be used.
                    SqlCommand sqlCommand = new SqlCommand("VIEW_ALUMNI_RECORD_BY_ID", sqlConnection);
                    sqlCommand.CommandType = CommandType.StoredProcedure;

                    //pass the id before open make a parameter for command
                    sqlCommand.Parameters.AddWithValue("@RecordID", alumniID);
                    sqlConnection.Open();
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

                    while (sqlDataReader.Read())
                    {
                        //using the reader,getting all the info one by one until all are recorded to the return.
                        alumniObject               = new AlumniDO();
                        alumniObject.RecordID      = sqlDataReader.GetInt32(0);
                        alumniObject.CompleteName  = sqlDataReader.GetString(1).Trim();
                        alumniObject.YearGraduated = sqlDataReader.GetInt16(2);
                        alumniObject.Position      = sqlDataReader.GetString(3).Trim();
                        alumniObject.Company       = sqlDataReader.GetString(4).Trim();
                        alumniObject.ContactNumber = sqlDataReader.GetString(5).Trim();
                        alumniObject.DepartmentID  = sqlDataReader.GetInt32(6);
                    }
                    //making sure that all connections are close and dispose
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                    sqlCommand.Dispose();
                }
            }
            catch (Exception exc)
            {
                LoggingDataAccessLayer.LogViewAlumniRecordByID(exc);
                //calling the LoggingDAL instance to pass on the info to the method.
            }
            //return a single DO not a list
            return(alumniObject);
        }
        //an instance for LoggingDAL to hold information.

        public List <AlumniDO> ReadAlumniRecord()
        {
            //method return a list of alumni record

            List <AlumniDO> alumniList = new List <AlumniDO>();

            //an instance for alumni list to be used as a return.

            try
            {
                //needed to be able to catch an error if any of the properties or object or functions are not met.

                using (SqlConnection sqlConnection = new SqlConnection(connectionString))
                {
                    //connecting the program to the database
                    //where the stored procedure will be used.
                    SqlCommand sqlCommand = new SqlCommand("READ_ALUMNI_RECORDS", sqlConnection);
                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlConnection.Open();
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

                    while (sqlDataReader.Read())
                    {
                        //using the reader,getting all the info one by one until all are recorded to the return.
                        AlumniDO alumniObject = new AlumniDO();
                        alumniObject.RecordID            = sqlDataReader.GetInt32(0);
                        alumniObject.CompleteName        = sqlDataReader.GetString(1);
                        alumniObject.YearGraduated       = sqlDataReader.GetInt16(2);
                        alumniObject.Position            = sqlDataReader.GetString(3);
                        alumniObject.Company             = sqlDataReader.GetString(4);
                        alumniObject.ContactNumber       = sqlDataReader.GetString(5);
                        alumniObject.DepartmentID        = sqlDataReader.GetInt32(6);
                        alumniObject.Department.DeptName = sqlDataReader.GetString(7);
                        alumniList.Add(alumniObject);
                    }
                    //making sure that all connections are close and dispose
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                    sqlCommand.Dispose();
                }
            }
            catch (Exception exc)
            {
                LoggingDataAccessLayer.LogReadAlumniRecord(exc);
                //calling the LoggingDAL instance to pass on the info to the method.
            }
            return(alumniList);
        }
Beispiel #6
0
        public static AlumniPO MapAlumniDOtoPO(AlumniDO frmAlumniDO)
        {
            //the method holds info of an AlumniDataObject and pass on an info
            //that is being converted to a presentation object.

            AlumniPO toAlumniPO = new AlumniPO();

            toAlumniPO.RecordID      = frmAlumniDO.RecordID;
            toAlumniPO.CompleteName  = frmAlumniDO.CompleteName;
            toAlumniPO.YearGraduated = frmAlumniDO.YearGraduated;
            toAlumniPO.Position      = frmAlumniDO.Position;
            toAlumniPO.Company       = frmAlumniDO.Company;
            toAlumniPO.ContactNumber = frmAlumniDO.ContactNumber;
            toAlumniPO.DepartmentID  = frmAlumniDO.DepartmentID;
            toAlumniPO.Department    = frmAlumniDO.Department.DeptName;
            return(toAlumniPO);
        }
        public void CreateAlumniRecord(AlumniDO alumniCreateDO)
        {
            //method hold info about the properties in alumni record table and this has no return.

            try
            {
                //needed to be able to catch an error if any of the properties or object or functions are not met.

                using (SqlConnection sqlConnection = new SqlConnection(connectionString))
                {
                    //connecting the program to the database
                    //where the stored procedure will be used.
                    SqlCommand sqlCommand = new SqlCommand("CREATE_ALUMNI_RECORDS", sqlConnection);
                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlConnection.Open();

                    //this time add value on each paramers that the sql stored procedure have.
                    //all value are stored to the method's parameter.
                    sqlCommand.Parameters.AddWithValue("@CompleteName", alumniCreateDO.CompleteName);
                    sqlCommand.Parameters.AddWithValue("@YearGraduated", alumniCreateDO.YearGraduated);
                    sqlCommand.Parameters.AddWithValue("@Position", alumniCreateDO.Position);
                    sqlCommand.Parameters.AddWithValue("@Company", alumniCreateDO.Company);
                    sqlCommand.Parameters.AddWithValue("@ContactNumber", alumniCreateDO.ContactNumber);
                    sqlCommand.Parameters.AddWithValue("@DepartmentID", alumniCreateDO.DepartmentID);
                    sqlCommand.ExecuteNonQuery();

                    //making sure that all connections are close and dispose
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                    sqlCommand.Dispose();
                }
            }
            catch (Exception exc)
            {
                LoggingDataAccessLayer.LogCreateAlumniRecords(exc);
                //calling the LoggingDAL instance to pass on the info to the method.
            }
        }
        public ActionResult CreateAlumniRecord(AlumniVM registerForm)
        {
            //method holds whatever info does user add in the form.

            //a default value for action result
            ActionResult result = null;

            if (Session["RoleID"] != null)
            {
                //session that check if someone log in or none
                //if there is log in run the condition.
                //if there is none then go to else option

                if ((int)Session["RoleID"] == 1 || (int)Session["RoleID"] == 2 || (int)Session["RoleID"] == 3)
                {
                    //session that determine what user is log in.
                    //if any of these role is not log in then go to else option.

                    if (ModelState.IsValid)
                    {
                        //if everything is valid in a model state,run the program
                        //if it doesnt meet any requirements, run else option.

                        //a DO identifier that hold info from the form
                        //info coming from the form obtain form the user will be converted to data access
                        //object and be added to the database.
                        AlumniDO mappedDataCreate = Mapper.MapAlumniPOtoDO(registerForm.AlumniForm);

                        //calling the data access layer instance to create a new record with the info from user.
                        AlumniDataAccessLayer.CreateAlumniRecord(mappedDataCreate);

                        //after it is added to database redirect to view to check new entry.
                        result = RedirectToAction("ViewAllAlumni");
                    }
                    else
                    {
                        //this is a program for dropdown to the form.
                        AlumniVM            alumniForm           = new AlumniVM();
                        List <DepartmentDO> departmentObjectList = DepartmentDataAccessLayer.ReadDepartment();

                        alumniForm.DepartmentDropDown.Add(new SelectListItem {
                            Text = "Please choose a department", Value = "0"
                        });
                        foreach (DepartmentDO departmentObject in departmentObjectList)
                        {
                            SelectListItem item = new SelectListItem();
                            item.Text  = departmentObject.DeptName;
                            item.Value = departmentObject.DeptID.ToString();
                            alumniForm.DepartmentDropDown.Add(item);
                        }
                        //throwing a view form with a dropdown.
                        result = View(alumniForm);
                    }
                }
                else
                {
                    result = RedirectToAction("Index", "Home");
                }
            }
            else
            {
                result = RedirectToAction("Index", "Home");
            }
            //returning a form or redirect.
            return(result);
        }