Exemplo n.º 1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (cateroryGridView.SelectedRows.Count > 0)
     {
         DataGridViewRow dataRow = cateroryGridView.SelectedRows[0];
         int.TryParse(dataRow.Cells["id"].Value.ToString(), out int id);
         if (id < 0)
         {
             MessageBox.Show("Invalid category id");
             return;
         }
         else
         {
             int success = CategoryDataAccess.DeleteCategory(id);
             if (success > 0)
             {
                 MessageBox.Show("successfully deleted");
                 frmCategory_Load(sender, e);
             }
         }
     }
     else
     {
         MessageBox.Show("Please select a category to delete");
         return;
     }
 }
        public ActionResult ConfirmDelete(int id)
        {
            CategoryDataAccess cda = new CategoryDataAccess();
            int i = cda.DeleteCategory(id);

            if (i > 0)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = true,
                        StatusCode = ((int)ResponseStatus.BadRequest).ToString(),
                        Message = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage))
                    }));
                }
                CategoryDataAccess _categoryAccess = new CategoryDataAccess(_iconfiguration);

                DatabaseResponse response = await _categoryAccess.DeleteCategory(id);

                if (response.ResponseCode == (int)DbReturnValue.DeleteSuccess)
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = true,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.DeleteSuccess),
                        ReturnedObject = response.Results
                    }));
                }
                else if (response.ResponseCode == (int)DbReturnValue.ActiveTryNotDelete)
                {
                    Log.Error(EnumExtensions.GetDescription(DbReturnValue.ActiveTryNotDelete));

                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.ActiveTryNotDelete),
                        ReturnedObject = response.Results
                    }));
                }
                else
                {
                    Log.Error(EnumExtensions.GetDescription(DbReturnValue.NotExists));

                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.NotExists),
                        ReturnedObject = response.Results
                    }));
                }
            }
            catch (Exception ex)
            {
                Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    StatusCode = ((int)ResponseStatus.ServerError).ToString(),
                    IsDomainValidationErrors = false
                }));
            }
        }