Guest User

Untitled

a guest
Oct 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. // POST api/Recipes
  2. [HttpPost]
  3. public void Post([FromBody] RecipeModel newRecipe)
  4. {
  5. if (newRecipe != null)
  6. {
  7. using (var container = Db4oEmbedded.OpenFile(Db4oEmbedded.NewConfiguration(), DbPath))
  8. try
  9. {
  10. var mayBeRecipe = (from RecipeModel recipe in container
  11. where recipe.GetHashCode() == newRecipe.GetHashCode()
  12. select recipe).FirstOrDefault();
  13.  
  14. if (mayBeRecipe == null)
  15. container.Store(newRecipe);
  16. }
  17. catch (Exception e)
  18. {
  19. Debug.WriteLine(e);
  20. }
  21. }
  22.  
  23. }
  24.  
  25. public class RecipeTypeConverter : TypeConverter
  26. {
  27. public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
  28. {
  29. return true;
  30.  
  31. // return base.CanConvertFrom(context, sourceType);
  32. }
  33.  
  34. public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
  35. {
  36. var newRecipe = JsonConvert.DeserializeObject<RecipeModel>(value as string);
  37.  
  38. return newRecipe;
  39. }
  40. }
Add Comment
Please, Sign In to add comment