Example #1
0
        private async Task <IActionResult> _DoDelete(string deleteType, TEntity entity)
        {
            if (deleteType == null)
            {
                return(BadRequest(new Error()
                {
                    Message = "Can't identify The type of the Delete operation"
                }));
            }
            if (entity == null)
            {
                return(BadRequest(new Error()
                {
                    Message = "Item doesn't exist"
                }));
            }
            // switch on the [deleteType] and perform the appropriate action
            int res;

            switch (deleteType)
            {
            case "logical":
                res = await Task.Run(() => _service.DeleteLogical(entity));

                if (res == -1)
                {
                    return(BadRequest(new Error()
                    {
                        Message = "Can't delete this Item Logically"
                    }));
                }
                else if (res == -2)
                {
                    return(BadRequest(new Error()
                    {
                        Message = "Item has already been Logically deleted before"
                    }));
                }
                _SetDeleteResult(entity, res, "logical");
                // await _hubContext.Clients.Group(_tableName).SendAsync(_clientMethod, "Delete", _deleteResult);
                return(Ok(_deleteResult));

            case "physical":
                res = await Task.Run(() => _service.Delete(entity));

                _SetDeleteResult(entity, res, "physical");
                // await _hubContext.Clients.Group(_tableName).SendAsync(_clientMethod, "Delete", _deleteResult);
                return(Ok(_deleteResult));

            default:
                return(BadRequest(new Error()
                {
                    Message = "Unknown Delete Type"
                }));
            }
        }
Example #2
0
        private async Task DoDelete(string deleteType, TEntity entity)
        {
            // switch on the [deleteType] and perform the appropriate action
            int res;

            try
            {
                switch (deleteType)
                {
                case "logical":
                    res = _service.DeleteLogical(entity);
                    if (res == -1)
                    {
                        await Clients.All.SendAsync(_clientMethod, new Response <String>() { Error = "Can't delete this Item Logically" });
                    }
                    else if (res == -2)
                    {
                        await Clients.All.SendAsync(_clientMethod, new Response <String>() { Error = "Item has already been Logically deleted before" });
                    }
                    SetDeleteResult(entity, res, "logical");
                    await Clients.All.SendAsync(_clientMethod, _deleteResult);

                    break;

                case "physical":
                    res = _service.Delete(entity);
                    SetDeleteResult(entity, res, "physical");
                    await Clients.All.SendAsync(_clientMethod, _deleteResult);

                    break;

                default:
                    await Clients.All.SendAsync(_clientMethod, new Response <String>() { Error = "Unknow Delete Type" });

                    break;
                }
            }
            catch (Exception ex)
            {
                await Clients.All.SendAsync(_clientMethod, ex);
            }
        }