// DELETE: api/UserProfileLog/5 public void Delete(int id) { var userProfileId = Helper_Classes.UserHelpers.GetUserProfile().Id; //var userCheck = _context.UserProfiles.Include(m=>m.UserProgressLog).SingleOrDefault(m=>m.); var progressLogInDb = _context.UserProgressLogs.SingleOrDefault(c => c.Id == id && c.UserProfileId == userProfileId); if (progressLogInDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } var userPhotoId = progressLogInDb.UserPhotoId; _context.UserProgressLogs.Remove(progressLogInDb); _context.SaveChanges(); if (userPhotoId != null) { var photoManager = new PhotoManager(); photoManager.DeletePhotoFromDb((int)userPhotoId); _context.SaveChanges(); } }