Esempio n. 1
0
        public async Task <IActionResult> Delete(int id)
        {
            string message = Messages.AnErrorOccuredWhileDeleteItem;

            bool success = false;

            try
            {
                await _insuranceService.DeleteInsuranceAsync(id);

                message = Messages.ItemDeletedSuccessFully;
                success = true;
            }
            catch (DbUpdateException ex)
            {
                if (ex.GetBaseException() is SqlException sqlException)
                {
                    var number = sqlException.Number;

                    if (number == 547)
                    {
                        message = Core.Resources.UI.AdminPanel.PanelResource.ItemIsUsedYouCannotDeleteIt;
                    }
                }
            }
            catch
            {
                message = Messages.AnErrorOccuredWhileDeleteItem;
            }

            return(Json(new { success, message }));
        }