Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // POST api/Recipes
- [HttpPost]
- public void Post([FromBody] RecipeModel newRecipe)
- {
- if (newRecipe != null)
- {
- using (var container = Db4oEmbedded.OpenFile(Db4oEmbedded.NewConfiguration(), DbPath))
- try
- {
- var mayBeRecipe = (from RecipeModel recipe in container
- where recipe.GetHashCode() == newRecipe.GetHashCode()
- select recipe).FirstOrDefault();
- if (mayBeRecipe == null)
- container.Store(newRecipe);
- }
- catch (Exception e)
- {
- Debug.WriteLine(e);
- }
- }
- }
- public class RecipeTypeConverter : TypeConverter
- {
- public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
- {
- return true;
- // return base.CanConvertFrom(context, sourceType);
- }
- public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- var newRecipe = JsonConvert.DeserializeObject<RecipeModel>(value as string);
- return newRecipe;
- }
- }
Add Comment
Please, Sign In to add comment