public async Task <IActionResult> Edit(string id, [Bind("MediaTypeId,MediaFormatId")] MediaTypeFormat mediaTypeFormat) { if (id != mediaTypeFormat.MediaTypeId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(mediaTypeFormat); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MediaTypeFormatExists(mediaTypeFormat.MediaTypeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["MediaFormatId"] = new SelectList(_context.MediaFormat, "Id", "Id", mediaTypeFormat.MediaFormatId); ViewData["MediaTypeId"] = new SelectList(_context.MediaType, "Id", "Id", mediaTypeFormat.MediaTypeId); return(View(mediaTypeFormat)); }
public async Task <IActionResult> Create([Bind("MediaTypeId,MediaFormatId")] MediaTypeFormat mediaTypeFormat) { if (ModelState.IsValid) { _context.Add(mediaTypeFormat); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MediaFormatId"] = new SelectList(_context.MediaFormat, "Id", "Id", mediaTypeFormat.MediaFormatId); ViewData["MediaTypeId"] = new SelectList(_context.MediaType, "Id", "Id", mediaTypeFormat.MediaTypeId); return(View(mediaTypeFormat)); }
public static async Task <ParseResult <T> > Parse <T>(this RequestResult result, MediaTypeFormat messageTypeFormat, Func <string, ParseResult <T> > customDeserializer = null) where T : class { if (result.Exception != null) { return new ParseResult <T> { Successful = false, Error = result.Exception.Message } } ; if (result.ResponseCode == HttpStatusCode.NoContent) { return new ParseResult <T> { Successful = true } } ; var contentAsString = await result.ResponseContent.ReadAsStringAsync(); if (customDeserializer != null) { return(customDeserializer(contentAsString)); } switch (messageTypeFormat) { case MediaTypeFormat.Json: return(TryParseJson <T>(contentAsString)); case MediaTypeFormat.Xml: return(TryParseXml <T>(contentAsString)); default: return(TryParseJson <T>(contentAsString)); } }