/// <summary> /// Handles GET http method /// </summary> /// <param name="context">Context of incoming http request</param> private void GetHandler(HttpContext context) { try { if (context.Request.RawUrl.Split('/').Last() == RESOURCE_URL) { context.Response.Write(JsonConvert.SerializeObject( ReviewList.ReadAll(), Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); } else { context.Response.Write(JsonConvert.SerializeObject( ReviewList.Read(Int32.Parse(context.Request.RawUrl. Split('/').Last())), Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); } } catch (ArgumentNullException) { context.Response.StatusCode = 400; context.Response.Write("Error: Input values are missing."); } catch (ArgumentException err) { context.Response.StatusCode = 404; context.Response.Write("Error: " + err.Message); } catch (FormatException err) { context.Response.StatusCode = 500; context.Response.Write("Error: " + err.Message); } catch (Exception) { context.Response.StatusCode = 500; context.Response.Write("Error: Server had a problem. Please try " + " again later."); } }
/// <summary> /// Deletes an specific song and all its reviews /// </summary> /// <param name="songId">Id of specific song to delete</param> public static void Delete(int songId) { Song song = songs.Find(s => s.SongId == songId); if (song != null) { foreach (Review review in song.Reviews) { ReviewList.ReadAll().Remove(review); } songs.Remove(song); } else { throw new ArgumentException("Resource not found."); } }