public ActionResult ExitEdit(BlockEdit model) { if (!ModelState.IsValid) { ViewBag.MapPreview = _mSvc.Value.GetMapByID(model.MapID).MapModel.MapPreview; return(View(model)); } ; if (!ExitEditValidation(model)) { ViewBag.MapPreview = _mSvc.Value.GetMapByID(model.MapID).MapModel.MapPreview; return(View(model)); } ; if (_bSvc.Value.UpdateExitBlock(model)) { ModelState.AddModelError("", "The block was updated succesfully."); return(RedirectToAction("Details", "Map", new { id = model.MapID })); } ViewBag.MapPreview = _mSvc.Value.GetMapByID(model.MapID).MapModel.MapPreview; ModelState.AddModelError("", "Your block could not be updated."); return(View(model)); }
public void TryApplyPendingEdits() { if (dying) { return; } Assert.IsTrue(loaded); if (pendingEdits.Count > 0 && blockReaders == 0 && !blockWriter) { int c = pendingEdits.Count; while (c-- > 0) // just incase setblock fails, prob wont happen tho { BlockEdit e = pendingEdits.Dequeue(); SetBlock(e.x, e.y, e.z, e.block); } if (!NeighborsLoaded() || !IsLocalGroupFreeForMeshing()) { update = true; } else // slam out job right away if you can { update = false; lightUpdate = false; JobController.StartMeshJob(this); } } }
public ActionResult Edit(int id, BlockEdit model) { if (!EditValidation(id, model)) { return(View(model)); } if (model.TypeOfBlock == "Exit") { if (!EditIntoExitValidation(model)) { return(View(model)); } TempData["model"] = model; return(RedirectToAction("ExitEdit", "Block", new { id = model.ID })); } if (!_bvSvc.Value.CheckIfBlockPlacementIsValidEdit(model)) { ModelState.AddModelError("", "There is already a block in that position."); return(View(model)); } if (_bSvc.Value.UpdateBlock(model)) { TempData["SaveResult"] = "The block was updated succesfully."; return(RedirectToAction("Details", "Map", new { id = model.MapID })); } ModelState.AddModelError("", "Your block could not be updated."); return(View(model)); }
private bool EditIntoExitValidation(BlockEdit model) { if (!_bvSvc.Value.CheckIfExitLocationIsValid(model)) { ModelState.AddModelError("", "Exit blocks must be positioned at the edge of the map."); return(false); } return(true); }
public bool CheckIfWallHasEvent(BlockEdit model) { using (var ctx = new ApplicationDbContext()) { if (ctx.GameEvents.Any(e => e.BlockID == model.ID) && model.TypeOfBlock == "Wall") { return(true); } } return(false); }
public bool CheckIfBlockPlacementIsValidEdit(BlockEdit model) { using (var ctx = new ApplicationDbContext()) { if (ctx.Blocks.Any(b => b.PosX == model.PosX && b.PosY == model.PosY && b.ID != model.ID)) { return(false); } } return(true); }
public bool CheckIfExitLocationIsValid(BlockEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Maps.Single(m => m.ID == model.MapID); bool locationValid = CheckIfExitIsAtEdgeOfMap(model.PosX, model.PosY, entity.SizeX, entity.SizeY); bool spotNotOccupied = CheckForExistingExits(model.ID, model.PosX, model.PosY, model.ExitDirection, entity); return(locationValid && spotNotOccupied); } }
public bool UpdateBlock(BlockEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Blocks.Single(e => e.MapID == model.MapID && e.OwnerID == _userID && e.ID == model.ID); entity.TypeOfBlock = GetBlockTypeFromString(model.TypeOfBlock); entity.Name = model.Name; entity.Description = model.Description; entity.PosX = model.PosX; entity.PosY = model.PosY; return(ctx.SaveChanges() == 1); } }
public JsonResult UpdateBlock(int blockId, string title, int column, int priority, bool isDelete = false) { var blockEdit = new BlockEdit(new Block { BlockId = blockId, Title = title, Column = column, Priority = priority, DivisionId = 1 }); var result = isDelete ? blockEdit.Delete() : blockEdit.Update();; return(new JsonResult(result)); }
private bool ExitEditValidation(BlockEdit model) { bool idValid = true; bool locationValid = true; if (!_bvSvc.Value.CheckIfExitLocationIsValid(model)) { ModelState.AddModelError("", "Exit blocks must face a wall that does not already contain an exit."); idValid = false; } if (!_bvSvc.Value.CheckIfExitIdIsValid(model.ExitToID, model.MapID)) { ModelState.AddModelError("", "Please enter an ExitToID that matches an existing map other than the current one.\n" + $"Available Map IDs to exit to: | {_mSvc.Value.GetExitMapIDAvailabilityExcludingCurrentID(model.MapID)}"); locationValid = false; } return(idValid && locationValid); }
// GET: Block/Edit/5 public ActionResult Edit(int id) { var detail = _bSvc.Value.GetBlockByID(id).BlockDetail; var model = new BlockEdit { ID = detail.ID, MapID = detail.MapID, Creator = detail.Creator, TypeOfBlock = detail.TypeOfBlock, Name = detail.Name, Description = detail.Description, PosX = detail.PosX, PosY = detail.PosY }; ViewBag.Title = detail.Name; ViewBag.MapPreview = _mSvc.Value.GetMapByID(detail.MapID).MapModel.MapPreview; return(View(model)); }
public string Update() { if (!BlockEdit.IsOnlyOneBlockId(dbContext, Container.BlockId)) { return($"BlockId {Messages.NotUnique}"); } try { if (IsOnlyOneContainerId(dbContext, Container.ContainerId)) { Edit(); } else { Create(); } return(null); } catch { return(Messages.EditFail); } }
private bool EditValidation(int id, BlockEdit model) { if (!ModelState.IsValid) { return(false); } if (model.ID != id) { ModelState.AddModelError("", "ID Mismatch"); return(false); } if (model.TypeOfBlock == "Wall") { if (_bvSvc.Value.CheckIfWallHasEvent(model)) { ModelState.AddModelError("", "Game event attached to this block must be removed before turning it into a wall block type."); return(false); } } return(true); }