Created
March 30, 2011 02:54
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*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