Пример #1
0
        // GET: Students/Delete/5
        public ActionResult Delete(int id)
        {
            StudentRepo repo = new StudentRepo();

            repo.DeleteStudent(id);
            return(RedirectToAction("Index"));
        }
Пример #2
0
        private void dataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                //  var d = (DataGridView)sender;
                //  var df = d.SelectedCells[0].Value.ToString();
                //  if(df == "Edit") (df == "Delete")

                if (!LoggedInUser.IsAdmin)
                {
                    Base.ShowError("Access Denied", "You do not have the required permission");
                    return;
                }

                //edit column
                if (e.ColumnIndex == 0)
                {
                    var id   = dataGrid.Rows[e.RowIndex].Cells["id"].Value.ToString();
                    var item = _repo.GetStudent(id);
                    if (item != null)
                    {
                        var updateForm = new FrmStudent(item.Id);
                        updateForm.ShowDialog();
                        LoadData();
                    }
                }

                //delete column
                if (e.ColumnIndex == 1)
                {
                    var result = Base.ShowDialog(MessageBoxButtons.YesNo, "Confirm Delete", "Are you sure you want to delete this record?");
                    if (result == DialogResult.Yes)
                    {
                        var id       = dataGrid.Rows[e.RowIndex].Cells["id"].Value.ToString();
                        var response = _repo.DeleteStudent(id);

                        if (response == string.Empty)
                        {
                            Base.ShowInfo("Success", "Student deleted successfully");
                            LoadData();
                        }

                        else
                        {
                            Base.ShowError("Failed", response);
                        }
                    }
                }

                //enroll fingerprint column
                if (e.ColumnIndex == 2)
                {
                    var id         = dataGrid.Rows[e.RowIndex].Cells["id"].Value.ToString();
                    var enrollForm = new FrmEnrollFinger(id);
                    enrollForm.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                Base.ShowError("Error occured", ex.Message);
            }
        }