public IActionResult Create() { var model = new CreateBlockViewModel { BlockCategories = _pagesContext.BlockCategories.ToList() }; return(View(model)); }
public async Task <IActionResult> Create([Required] CreateBlockViewModel model) { _pagesContext.Blocks.Add(model); var dbResult = await _pagesContext.PushAsync(); if (dbResult.IsSuccess) { return(RedirectToAction("Index")); } model.BlockCategories = _pagesContext.BlockCategories.ToList(); return(View(model)); }
public IActionResult Edit([Required] CreateBlockViewModel model) { model.Changed = DateTime.Now; try { _pagesContext.Blocks.Update(model); _pagesContext.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { ModelState.AddModelError(string.Empty, e.Message); Console.WriteLine(e); } return(View(model)); }
public bool AddBlockToMap(CreateBlockViewModel model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Blocks.Single(e => e.ID == model.CreateBlockModel.ID); entity.MapID = model.MapModel.MapID; entity.OwnerID = _userID; entity.TypeOfBlock = GetBlockTypeFromString(model.CreateBlockModel.Type); entity.Name = model.CreateBlockModel.Name; entity.Description = model.CreateBlockModel.Description; entity.PosX = model.CreateBlockModel.PosX; entity.PosY = model.CreateBlockModel.PosY; return(ctx.SaveChanges() == 1); } }
public ActionResult Create(CreateBlockViewModel model) { //if (!ModelState.IsValid) return View(model); if (!_bvSvc.Value.CheckIfBlockPlacementIsValid(model.CreateBlockModel.MapID, model.CreateBlockModel.PosX, model.CreateBlockModel.PosY)) { ModelState.AddModelError("", "There is already a block in that position."); ViewBag.MapPreview = _mSvc.Value.GetMapByID(model.MapModel.MapID).MapModel.MapPreview; return(View(model)); } if (_bSvc.Value.CreateBlock(model)) { TempData["SaveResult"] = "Block succesfully added!"; return(RedirectToAction("Details", "Map", new { id = model.MapModel.MapID })); } return(View(model)); }
public IActionResult Create([Required] CreateBlockViewModel model) { try { model.TenantId = CurrentUserTenantId; model.Author = GetCurrentUser().Id; model.Changed = DateTime.Now; _pagesContext.Blocks.Add(model); _pagesContext.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { Console.WriteLine(e); } model.BlockCategories = _pagesContext.BlockCategories.ToList(); return(View(model)); }
public bool CreateBlock(CreateBlockViewModel model) { var entity = new Block { MapID = model.MapModel.MapID, OwnerID = _userID, Name = model.CreateBlockModel.Name, Description = model.CreateBlockModel.Description, TypeOfBlock = GetBlockTypeFromString(model.CreateBlockModel.Type), PosX = model.CreateBlockModel.PosX, PosY = model.CreateBlockModel.PosY, }; using (var ctx = new ApplicationDbContext()) { ctx.Blocks.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult CreateExit(CreateBlockViewModel model) { if (!ModelState.IsValid) { ModelState.AddModelError("", "Something went wrong | Error: ModelState is not valid."); return(View(model)); } if (!ExitValidation(model.CreateBlockModel)) { return(View(model)); } if (_bSvc.Value.CreateExitBlock(model)) { TempData["SaveResult"] = "Block succesfully added!"; return(RedirectToAction("Details", "Map", new { id = model.MapModel.MapID })); } return(View(model)); }
public async Task <Response> CreateBlock(CreateBlockViewModel model) { var createBlockCommand = _mapper.Map <CreateBlockCommand>(model); return(await _mediator.Send(createBlockCommand)); }
public async Task <Response> CreateBlock([FromForm] CreateBlockViewModel model) { return(await _blockService.CreateBlock(model)); }