internal object Delete(int id) { Lego exists = Get(id); _repo.Delete(id); return($"{exists.Description} has been deleted"); }
internal Lego Create(Lego newLego) { int id = _repo.Create(newLego); newLego.Id = id; return(newLego); }
public async Task <IActionResult> PutLego([FromRoute] int id, [FromRoute] Lego lego) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != lego.SerialNumber) { return(BadRequest()); } _context.Entry(lego).State = EntityState.Modified; try { _repo.Update(lego); var save = await _repo.SaveAsync(lego); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LegoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
internal Lego Delete(int id) { Lego found = Get(id); _repo.Delete(id); return(found); }
public async Task <IActionResult> Edit(string id, [Bind("Item_Number,Name,Year,Theme,Subtheme,Pieces,Minifigures,Image_URL,GBP_MSRP,USD_MSRP,CAD_MSRP,EUR_MSRP,Packaging,Availability")] Lego lego) { if (id != lego.Item_Number) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(lego); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LegoExists(lego.Item_Number)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(lego)); }
private void placeBricks(Vector3 origin, Direction direction, int gridLimit, int steps = 3) { if (steps <= 0) { return; } setPreviewFromTemplate(prefabs[count++ % prefabs.Length], origin); Lego script = lego.gameObject.GetComponent <Lego>(); script.setPosition(origin); script.rotate(true); rotateBrickByDirection(direction, script); int tries = 0; Vector3 from = origin; while (script.placeSolid() && tries < gridLimit) { from = from + (toVector(direction) * script.getCubeGridCellWith() * script.getLengthCount() * randomizeLength()); if (tryIf(0.2f)) { placeBricks(from, randomFrom2(rightAngle(direction), leftAngle(direction), 7f), gridLimit, steps - 1); } if (tryIf(0.18f) || outsideMap(from)) { return; } script = swapBrickMaybe(0.4f, from, direction, script); tries++; } }
internal Lego Edit(int id, Lego updatedLego) { Lego foundLego = GetById(id); //NOTE GetById() is already handling our null checking foundLego.Title = updatedLego.Title; return(_repo.Edit(foundLego)); }
internal object Edit(Lego editLego) { Lego original = Get(editLego.Id); original.Color = editLego.Color.Length > 0 ? editLego.Color : original.Color; original.Description = editLego.Description.Length > 0 ? editLego.Description : original.Description; original.size = editLego.size.Length > 0 ? editLego.size : original.size; return(_repo.Edit(original)); }
public RedirectToActionResult RemoveItem(int ingredientID) { Ingredient ingredient = repository.Ingredients.FirstOrDefault(i => i.IngredientID == ingredientID); Lego lego = GetLego(); lego.RemoveItem(ingredient); SaveLego(lego); return(RedirectToAction("Index")); }
internal int Create(Lego newLego) { string sql = @" INSERT INTO legos(x,y) VALUES(@X,@Y); SELECT LAST_INSERT_ID();"; return(_db.ExecuteScalar <int>(sql, newLego)); }
public Lego Get(int id) { Lego exists = _repo.GetById(id); if (exists == null) { throw new Exception("Invalid lego bruh"); } return(exists); }
internal Lego GetById(int id) { Lego foundLego = _repo.GetById(id); if (foundLego == null) { throw new Exception("Invalid id."); } return(foundLego); }
internal Lego Get(int id) { Lego found = _repo.Get(id); if (found == null) { throw new Exception("invalid id mi amigo"); } return(found); }
internal Lego Delete(int id) { Lego foundLego = GetById(id); if (_repo.Delete(id)) { return(foundLego); } throw new Exception("Something bad happened..."); }
public ActionResult <Lego> Post([FromBody] Lego newLego) { try { return(Ok(_service.Create(newLego))); } catch (Exception e) { return(BadRequest(e.Message)); } }
internal void Edit(Lego update) { string sql = @" UPDATE legos SET name = @Name, WHERE id = @Id; "; _db.Execute(sql, update); }
internal int Create(Lego newLego) { string sql = @" INSERT INTO legos (size, name) VALUES (@Size, @Name); SELECT LAST_INSERT_ID();"; return(_db.ExecuteScalar <int>(sql, newLego)); }
private Lego swapBrickMaybe(float ratio, Vector3 at, Direction d, Lego defaultScript) { if (tryIf(ratio)) { setPreviewFromTemplate(prefabs[count++ % prefabs.Length], at); defaultScript = lego.gameObject.GetComponent <Lego>(); rotateBrickByDirection(d, defaultScript); } defaultScript.setPosition(at); return(defaultScript); }
public Lego Delete(int id, string UserEmail) { Lego exists = Get(id); if (exists.Owner != UserEmail) { throw new UnauthorizedAccessException("You do not own this kit!"); } _repo.Delete(id); return(exists); }
public async Task <IActionResult> Create([Bind("Item_Number,Name,Year,Theme,Subtheme,Pieces,Minifigures,Image_URL,GBP_MSRP,USD_MSRP,CAD_MSRP,EUR_MSRP,Packaging,Availability")] Lego lego) { if (ModelState.IsValid) { _context.Add(lego); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(lego)); }
public ActionResult <Lego> Create([FromBody] Lego newData) { try { return(Ok(_ss.Create(newData))); } catch (Exception e) { return(BadRequest(e.Message)); } }
internal Lego Edit(Lego legoToUpdate) { string sql = @" UPDATE legos SET title = @Title WHERE id = @Id LIMIT 1"; _db.Execute(sql, legoToUpdate); return(legoToUpdate); }
public async Task <ActionResult <Lego> > PostLego(Lego lego) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _repo.Add(lego); var save = await _repo.SaveAsync(lego); return(CreatedAtAction("GetLego", new { id = lego.SerialNumber }, lego)); }
public ActionResult <Lego> Edit(int id, [FromBody] Lego updatedLego) { try { return(Ok(_bs.Edit(id, updatedLego))); } catch (System.Exception err) { return(BadRequest(err.Message)); } }
internal int Create(Lego newLego) { string sql = @" INSERT INTO lego (description, color, size) VALUES (@Description, @Color, @Size); SELECT LAST_INSERT_ID();"; return(_db.ExecuteScalar <int>(sql, newLego)); }
public ActionResult <Lego> Edit([FromBody] Lego editLego, int id) { try { editLego.Id = id; return(Ok(_service.Edit(editLego))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public Lego Edit(Lego editLego, string UserEmail) { Lego original = Get(editLego.Id); if (original.Owner != UserEmail) { throw new UnauthorizedAccessException("You do not own this kit!"); } original.Name = editLego.Name.Length > 0 ? editLego.Name : original.Name; original.Size = editLego.Size.Length > 0 ? editLego.Size : original.Size; return(_repo.Edit(original)); }
internal Lego Create(Lego newLego) { string sql = @" INSERT INTO legos (title, creatorEmail) VALUES (@Title, @CreatorEmail); SELECT LAST_INSERT_ID()"; newLego.Id = _db.ExecuteScalar <int>(sql, newLego); return(newLego); }
public ActionResult <Lego> Create([FromBody] Lego newLego) { try { newLego.CreatorEmail = "*****@*****.**"; return(Ok(_bs.Create(newLego))); } catch (System.Exception err) { return(BadRequest(err.Message)); } }
public ActionResult <Lego> Edit([FromBody] Lego update, int id) { try { update.Id = id; return(Ok(_ss.Edit(update))); } catch (Exception e) { return(BadRequest(e.Message)); } }