Пример #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> DeleteStudent(int id)
        {
            var deleted = await _StudentBusiness.DeleteStudent(id);

            if (deleted)
            {
                return(Ok("Deleted successfully"));
            }
            return(BadRequest());
        }
Пример #3
0
 public IHttpActionResult DeleteStudent(int id)
 {
     try
     {
         var deleted_student = _stuentbusiness.DeleteStudent(id);
         if (deleted_student)
         {
             return(Ok("Deleted Successfully"));
         }
         return(NotFound());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Пример #4
0
 public bool DeleteStudent(int ID)
 {
     return(_studentBusiness.DeleteStudent(ID));
 }