Пример #1
0
    private void Save()
    {
        studentBusiness  = new StudentBusiness(studentDataAccess);
        CurrentOperation = (Operation)ViewState["CurrentOperation"];
        Student student = new Student();

        if (CurrentOperation != Operation.ADD)
        {
            student.ID = Convert.ToInt32(txtStudentID.Text);
        }
        student.StudFirstName  = txtStudentFirstName.Text;
        student.StudMiddleName = txtStudentMiddleName.Text;
        student.StudLastName   = txtStudentLastName.Text;
        student.Department     = new Department();
        student.Department.ID  = Convert.ToInt32(ddlDepartments.SelectedValue);
        studentDataAccess      = new StudentDataAccess();
        studentBusiness        = new StudentBusiness(studentDataAccess);

        try
        {
            bool success = false;
            if (CurrentOperation == Operation.ADD)
            {
                success = studentBusiness.AddStudent(student);
                lblSuccessMessage.Text = "Student was added successfully";
            }
            else if (CurrentOperation == Operation.UPDATE)
            {
                success = studentBusiness.UpdateStudent(student);
                lblSuccessMessage.Text = "Student was updated successfully";
            }
            else if (CurrentOperation == Operation.DELETE)
            {
                success = studentBusiness.DeleteStudent(Convert.ToInt32(txtStudentID.Text));
                lblSuccessMessage.Text = "Student was delete successfully";
            }
            if (success)
            {
                divSuccess.Visible = true;
                BindData();
            }
            else
            {
                divError.Visible = true;
            }
        }
        catch (Exception ex)
        {
            lblError.Text    = ex.Message;
            divError.Visible = true;
        }
        txtStudentID.Text             = string.Empty;
        txtStudentFirstName.Text      = string.Empty;
        txtStudentMiddleName.Text     = string.Empty;
        txtStudentLastName.Text       = string.Empty;
        ddlDepartments.SelectedIndex  = 0;
        CurrentOperation              = Operation.ADD;
        ViewState["CurrentOperation"] = CurrentOperation;
    }
        public async Task <IActionResult> AddStudent(StudentParameter studentParameter)
        {
            if (ModelState.IsValid)
            {
                var isAdded = await _StudentBusiness.AddStudent(studentParameter);

                if (isAdded)
                {
                    return(Ok("Added successfully"));
                }
            }

            return(BadRequest(ModelState));
        }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Student s = new Student();

        //s.ID = Convert.ToInt32(txtID.Text);
        s.StudFirstName   = txtFirstName.Text;
        s.StudMiddleName  = txtMiddleName.Text;
        s.StudLastName    = txtLastName.Text;
        s.Department.ID   = Convert.ToInt32(ddlDepartments.SelectedValue);
        studentDataAccess = new StudentDataAccess();
        studentBusiness   = new StudentBusiness(studentDataAccess);
        bool success = studentBusiness.AddStudent(s);

        BindData();
        divAdd.Visible = false;
    }
Пример #4
0
 public bool AddStudent(Student student)
 {
     return(_studentBusiness.AddStudent(student));
 }