public IHttpActionResult PutCategory(long id, Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != category.CategoryId) { return(BadRequest()); } db.Entry(category).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutRecipe(long id, RecipeDal.Recipe recipe) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != recipe.RecipeId) { return(BadRequest()); } db.Entry(recipe).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RecipeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "Name,Category,Description")] Recipe recipe, string[] selectedIngredients, string[] quantity, string[] quantityType) { recipe.DateCreated = System.DateTime.Now; try { if (ModelState.IsValid && User.Identity.IsAuthenticated) { // get id of current user and add it to the recipe var userId = User.Identity.GetUserId(); recipe.ChefId = userId; db.Recipes.Add(recipe); db.SaveChanges(); CreateRecipeIngredients(selectedIngredients, recipe, quantity, quantityType); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (RetryLimitExceededException dex) { // log error here ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(recipe)); }
public IActionResult Create(Recipe recipe) { _context.Recipes.Add(recipe); _context.SaveChanges(); return(new CreatedAtRouteResult("GetRecipe", new { id = recipe.Id }, recipe)); }
public int Insert(TDto dtoToInsert) { var entity = mapper.Map <TEntity>(dtoToInsert); recipeContext.Add(entity); recipeContext.SaveChanges(); return(entity.Id); }
public int InsertRecipe(RecipeDto recipeDto) { var recipeToInsert = mapper.Map <Entities.Recipe>(recipeDto); recipeContext.Recipes.Add(recipeToInsert); recipeContext.SaveChanges(); return(recipeToInsert.Id); }
public ActionResult Create([Bind(Include = "RecipeID,RecipeTitle,Steps,PrepTime,CookTime,Servings,MealType")] Recipe recipe) { if (ModelState.IsValid) { db.Recipes.Add(recipe); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(recipe)); }
public ActionResult Create([Bind(Include = "Id,ToolCode,ToolName,MachineId,WerkzeughoeheA1,WerkzeughoeheA2,HeizelementhoeheObenA3,HeizelementhoeheUntenA3,WarmpositionA3,BestueckungspositionA1,BestueckungspositionA2,PruefpositionA1,PruefpositionA2,IRKameraTriggerpositionA3")] DatMWerkzeug datMWerkzeug) { if (ModelState.IsValid) { db.DatMWerkzeugs.Add(datMWerkzeug); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(datMWerkzeug)); }
public ActionResult Create([Bind(Include = "ID,Name")] Recipe recipe) { if (ModelState.IsValid) { db.Recipes.Add(recipe); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(recipe)); }
public ActionResult Create([Bind(Include = "UserID,Username,Password,Email")] User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Create([Bind(Include = "Id,HK01,HK02,HK03,HK04,HK05,HK06,HK07,HK08,HK09,HK10,HK11,HK12,HK13,HK14,HK15,HK16,HK17,HK18,HK19,HK20,HK21,HK22,HK23,HK24")] DatHE datHE) { if (ModelState.IsValid) { db.DatHEs.Add(datHE); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(datHE)); }
public ActionResult Create([Bind(Include = "ID,Name,EngName,CookingTime,MainImageUrl,PortionMinWeight,Weight,AudioStartUrl")] Recipe recipe) { if (ModelState.IsValid) { db.Recipes.Add(recipe); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(recipe)); }
public ActionResult Create([Bind(Include = "IngedientID,IngredientName")] Ingredient ingredient) { if (ModelState.IsValid) { db.Ingredients.Add(ingredient); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ingredient)); }
public ActionResult Create([Bind(Include = "ID,Name,EngName")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "Id,ToolCode,ToolName")] DatWerkzeug datWerkzeug) { if (ModelState.IsValid) { db.DatWerkzeugs.Add(datWerkzeug); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(datWerkzeug)); }
public ActionResult Create([Bind(Include = "Id,ToolCode,ToolName,Propventil01,Propventil02,Propventil03,Propventil04,Propventil05,Propventil06,Propventil07,Propventil08,Propventil09,Propventil10,Propventil11,Propventil12,Propventil13,Propventil14,Propventil15,Propventil16,Propventil17,Propventil18,Propventil19,Propventil20,Propventil21,Propventil22,Propventil23,Propventil24,Propventil25,Propventil26,Propventil27,Propventil28,Propventil29,Propventil30,Propventil31,Propventil32,Propventil33,Propventil34,Propventil35,Propventil36,Propventil37,Propventil38,Propventil39,Propventil40,Propventil41,Propventil42,Propventil43,Propventil44,Propventil45,Propventil46,Propventil47,Propventil48,Propventil49,Propventil50,Propventil51,Propventil52,Propventil53,Propventil54,Propventil55,Propventil56,Propventil57,Propventil58,Propventil59,Propventil60")] DatN2 datN2) { if (ModelState.IsValid) { db.DatN2s.Add(datN2); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(datN2)); }
public void CreateUser(CreateUserRequest request) { if (request == null) { throw new ActionFailedException("invalid request body"); } if (string.IsNullOrWhiteSpace(request.Email)) { throw new ActionFailedException("E-mail cannot be empty"); } if (string.IsNullOrWhiteSpace(request.Username)) { throw new ActionFailedException("Username cannot be empty"); } if (string.IsNullOrWhiteSpace(request.Password)) { throw new ActionFailedException("Password cannot be empty"); } if (request.Password.Length < 8) { throw new ActionFailedException("Password is too short"); } if (request.Password.Length > 20) { throw new ActionFailedException("Password is too long"); } if (userContext.Users.Any(x => x.Username == request.Username)) { throw new ActionFailedException("Username \"" + request.Username + "\" is already taken"); } if (userContext.Users.Any(x => x.Email == request.Email)) { throw new ActionFailedException("Email \"" + request.Username + "\" is already taken"); } byte[] passwordHash, passwordSalt; CreatePasswordHash(request.Password, out passwordHash, out passwordSalt); User user = new User(); user.Username = request.Username; user.Email = request.Email; user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; user.Id = 0; user.RecipesOfUser = new List <Recipe>(); user.LikedRecipesOfUser = new List <UserRecipe>(); userContext.Users.Add(user); userContext.SaveChanges(); }
public IActionResult AddFavorite(string title, string href, string thumbnail) { var dbModel = new RecipeDAL(); dbModel.title = title; dbModel.href = href; dbModel.thumbnail = thumbnail; _recipeDbContext.Favorites.Add(dbModel); _recipeDbContext.SaveChanges(); return(RedirectToAction("HomePage")); }
public string Create(Recipe rec) { string s = ""; db.Recipes.Add(rec); db.SaveChanges(); s = "~/Home/About/" + rec.Id.ToString(); Response.Redirect(s); return(s); }
public ActionResult Favorites(string IsFavorite) { List <Recipe> output = (List <Recipe>)Session["UsersSearchedList"]; foreach (Recipe r in output) { if (IsFavorite != null) { db.Recipes.Add(r); db.SaveChanges(); } } return(View(db.Recipes)); }
public void AddIngredient(Model.Ingredient ingredient) { //check that it's not already in DB var query = from Ingredient in _dbContext.Ingredients where ingredient.Name == Ingredient.Name && ingredient.IngredientType == Ingredient.IngredientType select Ingredient; if (query.ToList <Ingredient>().Count == 0) { _dbContext.Ingredients.Add(ingredient); _dbContext.SaveChanges(); } }
public void Category_Create() { var newCategory = new Category { Description = $"Test {DateTime.Now.Ticks}" }; dc.Categories.Add(newCategory); dc.SaveChanges(); Assert.IsTrue(newCategory.Id > 0); // Cleanup dc.Categories.Remove(newCategory); dc.SaveChanges(); }
public static void MapRecipe(HtmlAgilityPack.HtmlNode recipe, ScrapingBrowser browser) { using (var context = new RecipeContext()) { WebPage recipePage = browser.NavigateToPage(new Uri(BaseURL + recipe.Attributes["href"].Value)); var html = recipePage.Html; var name = html.CssSelect("h1.post__header__hed a").FirstOrDefault().InnerHtml; var result = context.Recipes.FirstOrDefault(x => x.RecipeName == name); if (result == null) { result = new Recipe(); result.RecipeName = name; context.Recipes.Add(result); result.Ingredients = new List <Ingredient>(); } var ingredients = html.CssSelect("li.ingredient div").ToList(); System.Console.WriteLine(name); foreach (var ingredientHtml in ingredients) { if (context.Ingredients.Any(x => x.IngredientName == ingredientHtml.InnerHtml) == false && result.Ingredients.Any(x => x.IngredientName == ingredientHtml.InnerHtml)) { result.Ingredients.Add(MapIngredient(ingredientHtml)); } } context.SaveChanges(); } }
private void addDefaultKey() { using (var db = new RecipeContext()) { Key key = new Key { Name = configuration[nameof(key.Name)], Role = configuration[nameof(key.Role)], ExpirationDate = new DateTime(2999, 12, 31) }; if (db.Keys.Where(a => a.Name == key.Name).Count() == 0) { db.Keys.Add(key); db.SaveChanges(); } } }
public IActionResult CreateChef(Chef userImput) { if (ModelState.IsValid) { // do somethng! maybe insert into db? then we will redirect dbContext.Add(userImput); // OR _context.Users.Add(NewPerson); dbContext.SaveChanges(); return(Redirect("/")); } else { // Oh no! We need to return a ViewResponse to preserve the ModelState, and the errors it now contains! return(View("NewChef", userImput)); } }
public static void Initialize(RecipeContext context) { if (context.Recipes.Any()) { return; } var recipes = new Recipe[] { new Recipe { Name = "spaghetti", Ingredients = "water, spaghetti", Instructions = "just read the packet" }, new Recipe { Name = "meatballs", Ingredients = "microwave meal meatballs", Instructions = "read the packet and just shove it in the microwave" }, new Recipe { Name = "brownies", Ingredients = "shoes, socks, clothes, local shop", Instructions = "use google to find a local shop and go for a walk to buy some..." }, new Recipe { Name = "Chips", Ingredients = "frozen chips", Instructions = "put a portion on a baking tray in a preheated oven till browned and crispy" }, new Recipe { Name = "Pizza", Ingredients = "a smart phone, tablet, or computer", Instructions = "place an order with just eat and enjoy a nice chilled night in" }, }; foreach (Recipe recipe in recipes) { context.Recipes.Add(recipe); } context.SaveChanges(); }
public static void EnsureDatabaseSeeded(this RecipeContext context) { context.Database.Migrate(); var rp1 = new Recipe() { RecipeId = 1, Name = "Pasta", Description = "Pasta med kødsovs", Ingrediens = "Pasta", }; var rp2 = new Recipe() { RecipeId = 2, Name = "Pizza", Description = "Pizza med skinke og ost", Ingrediens = "Dej, ost, skinke", }; var rp3 = new Recipe() { RecipeId = 3, Name = "Rugbrød", Description = "Rugbrød med hamburgeryg", Ingrediens = "Rugbrød, smør, hamburgeryg", }; context.Add(rp1); context.Add(rp2); context.Add(rp3); context.SaveChanges(); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new RecipeContext( serviceProvider.GetRequiredService < DbContextOptions <RecipeContext> >())) { // Look for any movies. if (context.Recipe.Any()) { return; // DB has been seeded } context.Recipe.AddRange( new Recipe { Name = "When Harry Met Sally", Time = 30, Difficulty = "4", NumberOfLikes = 24, Ingredients = "apple, egg", Process = "123", TipsAndTricks = "..." }, new Recipe { Name = "Ghostbusters ", Time = 30, Difficulty = "4", NumberOfLikes = 24, Ingredients = "apple, egg", Process = "123", TipsAndTricks = "..." }, new Recipe { Name = "Ghostbusters 2", Time = 30, Difficulty = "4", NumberOfLikes = 24, Ingredients = "apple, egg", Process = "123", TipsAndTricks = "..." }, new Recipe { Name = "Rio Bravo", Time = 30, Difficulty = "4", NumberOfLikes = 24, Ingredients = "apple, egg", Process = "123", TipsAndTricks = "..." } ); context.SaveChanges(); } }
public ActionResult Create([Bind(Include = "Title,Body,AuthorID")] Post post) { if (ModelState.IsValid && User.Identity.IsAuthenticated) { // get id of current user and add it to the recipe var userId = User.Identity.GetUserId(); post.AuthorID = userId; post.DateCreated = System.DateTime.Now; db.Posts.Add(post); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(post)); }
public ActionResult Create(Group group) { try { User currentUser = _recipeContext.Users.Single(u => u.Id == User.Identity.Name); group.Users.Add(currentUser); currentUser.Groups.Add(group); _recipeContext.Groups.Add(group); _recipeContext.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }