Beispiel #1
0
      public IActionResult AddNewBlock(BlockViewModel model)
      {
          bool isAjaxCall = Request.Headers["x-requested-with"] == "XMLHttpRequest";

          try
          {
              if (ModelState.IsValid)
              {
                  string newBlockName           = model.NewTextBlock.Name;
                  int    newBlock_BlockHolderId = model.NewTextBlock.BlockHolderId;
                  string newBlockContent        = model.NewTextBlock.Content;

                  TextBlock tb = new TextBlock()
                  {
                      Content = newBlockContent, Name = newBlockName
                  };
                  TextBlock addedBlock = _dbHelper.AddNewBlock(tb);

                  Holder_Block hb = new Holder_Block();
                  hb.BlockHolderId = newBlock_BlockHolderId;
                  hb.TextBlockId   = addedBlock.Id;
                  _dbHelper.AddHolder_Block(hb);
                  TempData["Success"] = true;
              }
              else
              {
                  throw new Exception();
              }
          }
          catch
          {
              TempData["ErrorMessage"] = _localizer["An error occured during the creation of the text block."];
          }

          if (isAjaxCall)
          {
              ModelState.Clear();
              return(PartialView("BlockFormPartialView", UpdatePage()));
          }
          else
          {
              return(RedirectToAction("Index"));
          }
      }