public void Save(Recipe data) { var connection = Database.GetConnection(); try { if (data.RecipeID > 0) return; var command = connection.CreateCommand(); command.CommandText = "insert into recipes (title, urlkey, recipedescription, created_date, createdby, modified_date, modifiedby) values (@title, @urlkey, @recipedescription, @created_date, @createdby, @modified_date, @modifiedby) returning *"; command.AddParams( Database.CreateParameter("title", data.Title, DbType.String, command), Database.CreateParameter("urlkey", data.UrlKey, DbType.String, command), Database.CreateParameter("recipedescription", data.RecipeDescription, DbType.String, command), Database.CreateParameter("created_date", data.CreatedDate, DbType.DateTime, command), Database.CreateParameter("createdby", data.CreatedBy, DbType.Int64, command), Database.CreateParameter("modified_date", data.ModifiedDate, DbType.DateTime, command), Database.CreateParameter("modifiedby", data.ModifiedBy, DbType.Int64, command) ); if (connection.State != ConnectionState.Open) connection.Open(); var reader = command.ExecuteReader(CommandBehavior.CloseConnection); if (!reader.Read()) throw new ApplicationException("Error Writing Recipe"); data.RecipeID = reader.GetInt64(0); connection.Close(); } catch (Exception ex) { throw ex; } finally { connection.Close(); } }
public Recipe Save(Recipe data) { data.ComputeUrlKey(); data.ModifiedBy = 2; data.CreatedBy = 2; data.CreatedDate = DateTime.UtcNow; data.ModifiedDate = DateTime.UtcNow; RecipeDataProvider.Save(data); data.Ingredients.ForEach((RecipeIngredient ingredient) => { ingredient.RecipeID = data.RecipeID; ingredient.IngredientID = IngredientService.LoadOrSave(ingredient).IngredientID; ingredient.RecipeIngredientId = RecipeIngredientDataProvider.Save(ingredient).RecipeIngredientId; }); return data; }
public Recipe Parse(string text) { try { var recipe = new Recipe(); PreParsedRecipe preParsed = Preparse(text); preParsed.Lines .ToList() .ForEach((RecipeLine line) => { switch (line.DataType) { case RecipeDataType.Categories: break; case RecipeDataType.Empty: break; case RecipeDataType.Ingredients: recipe.Ingredients.Add(IngredientParser.ParseIngredient(line.Data)); break; case RecipeDataType.Instructions: recipe.RecipeDescription += line.Data; break; case RecipeDataType.Source: break; case RecipeDataType.Title: if(String.IsNullOrEmpty(recipe.Title)) recipe.Title = line.Data.Replace("Title:", "").Trim(); break; default: break; } }); return recipe; } catch (Exception ex) { throw ex; } }