public async Task <int> DeleteRoasterByIdAsync(Guid id) { try { _logger.Information("Roaster admin service layer access in progress..."); var roaster = await _roasterRepository.GetSingleAsync(id); _roasterRepository.Delete(roaster); var pairs = await _roasterTagRepository.GetPairsByRoasterIdAsNoTrackingAsync(id); _roasterTagRepository.DeleteRoasterTags(pairs); var picture = await _pictureRepository.GetPictureByRoasterIdAsyncAsNoTracking(id); if (picture != null) { _pictureRepository.Delete(picture); } await _roasterRepository.SaveChangesAsync(); _logger.Information($"Roaster, Tags, RoasterTags, Addresses tables have been modified. Deleted roaster:\n Id: {roaster.Id}\n Roaster name: {roaster.Name}"); return(0); } catch (Exception e) { _logger.Error("Roaster admin service layer error occured! Error text message:" + e.Message); return(-1); } }
public async Task <IActionResult> DeleteRoaster(Guid roasterId) { try { var roaster = await _roasterRepository.GetSingleAsync(roasterId); _roasterRepository.Delete(roaster); await _roasterRepository.SaveChangesAsync(); return(Ok()); } catch (Exception e) { return(BadRequest(e.ToString())); } }