Ejemplo n.º 1
0
        protected async Task <IActionResult> DeleteItem(int id, bool setFlag)
        {
            var item = await _repository.GetById(id);

            if (item == null)
            {
                return(Ok(ResponseDTO.NotFound()));
            }

            IActionResult response = BadRequest(ResponseDTO.BadRequest());

            if (setFlag)
            {
                item.DeleteFlag = true;
                item            = await _repository.Update(item);

                response = Ok(ResponseDTO.OkDeleted(item));
            }
            else
            {
                var result = await _repository.Remove(id);

                response = result
                    ? Ok(ResponseDTO.OkDeleted(item, "Removed from database."))
                    : response;
            }
            return(response);
        }