Skip to content

Instantly share code, notes, and snippets.

@ScottWeinstein
Created March 30, 2011 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ScottWeinstein/893773 to your computer and use it in GitHub Desktop.
Save ScottWeinstein/893773 to your computer and use it in GitHub Desktop.
sample code showing how to use the Dynamic version of System.Web.Helpers.Json.Decode to not write serialization mappers
/*
*string items might look like so
{'IVSet':[{'InterviewerId':'dd','InterviewType':'dd','ScheduledDate':'dd'}],
'FullName':'fsd','EmailAddress':'sdf','Phone':'sdf','notes_md':''}
*/
[HttpPost]
public ActionResult Edit(int id, string items)
{
Candidates candidate = _db.Candidates.Where(cd => cd.CandidateId == id).Single();
var decoded = System.Web.Helpers.Json.Decode(items);
candidate.EmailAddress = decoded.EmailAddress;
candidate.FullName = decoded.FullName;
candidate.notes_html = new MarkdownDeep.Markdown().Transform(decoded.notes_md);
candidate.notes_md = decoded.notes_md;
candidate.Phone = decoded.Phone;
var ivset = ((IEnumerable<dynamic>)decoded.IVSet);
foreach (var iv in ivset)
{
Interviews interview;
if (iv.InterviewId == null || string.IsNullOrWhiteSpace(iv.InterviewId.ToString()))
{
interview = new Interviews();
candidate.Interviews.Add(interview);
}
else
{
interview = candidate.Interviews.Where(intv => intv.InterviewId == iv.InterviewId).Single();
}
interview.InterviewerId = iv.InterviewerId;
interview.InterviewLocation = iv.InterviewLocation;
interview.InterviewType = iv.InterviewType;
interview.ScheduledDate = DateTime.Parse(iv.ScheduledDate);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment