public HttpResponseMessage Delete(Guid Id) { try { if (questionLogic.Find(Id).Author.Id != CurrentUserId()) { throw new Unauthorised(); } var question = questionLogic.Delete(Id); if (question == null) { throw new NoSuchQuestionFound(); } HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, new { question }); return(response); } catch (NoSuchQuestionFound e) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, new { error = e.Message }); return(response); } catch (Unauthorised e) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Forbidden, new { error = e.Message }); return(response); } catch (Exception e) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest, e.Message); return(response); } }
private void buttonDelete_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count == 1) { if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value); try { logic.Delete(new QuestionBindModel { Id = id }); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(); } } }