public async Task <IActionResult> DeleteProduct(AppProductsDeleteDto dto) { var response = await _appProductsService.DeleteProduct(dto); return(Ok(response)); }
public async Task <ApiResponse <bool> > DeleteProduct(AppProductsDeleteDto dto) { bool resultDto = false; Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <bool> response = new ApiResponse <bool>(resultDto); try { AppProducts product = await GetById(dto.Id); if (product == null) { metadata.IsValid = false; metadata.Message = "Producto No existe!!!"; response.Meta = metadata; response.Data = resultDto; return(response); } var recipes = await _unitOfWork.AppRecipesRepository.GetRecipesByProductId(dto.Id); if (recipes != null || recipes.Count > 0) { metadata.IsValid = false; metadata.Message = "Producto existe en la formulacion!!!"; response.Meta = metadata; response.Data = resultDto; return(response); } resultDto = await Delete(dto.Id); metadata.IsValid = true; metadata.Message = $"Producto Eliminado Satisfactoriamente!"; response.Meta = metadata; response.Data = resultDto; return(response); } catch (Exception ex) { metadata.IsValid = false; metadata.Message = ex.InnerException.Message; response.Meta = metadata; response.Data = resultDto; return(response); } }