public ActionResult CreateContainerPost(CreateContainerInputModel inputModel) { var rootContainer = _contentManager.GetContainer("", null); var container = _contentManager.GetContainer(inputModel.PagePath ?? "", null); if (container == null) return HttpNotFound(); if (!container.CanWrite) return new HttpStatusCodeResult(403, "Forbidden"); if (ModelState.IsValid) { if (container.Contents.Any(x => String.Compare(x.Alias, inputModel.ContainerName, false) == 0)) { ModelState.AddModelError("ContainerName", "コンテナまたはページがすでに存在しています。"); return View("CreateContainer", new CreateContainerViewModel() { RootContainer = rootContainer, Container = container, InputModel = inputModel }); } } else { return View("CreateContainer", new CreateContainerViewModel() { RootContainer = rootContainer, Container = container, InputModel = inputModel }); } var newContainer = _contentManager.CreateContainer(container, inputModel.ContainerName); return RedirectToAction("List", new { pagePath = newContainer.Path }); }
public JsonResult IsNewContainerAvailable(CreateContainerInputModel inputModel) { var container = _contentManager.GetContainer(inputModel.PagePath ?? "", null); if (container == null || !container.CanRead) return Json("コンテナが見つかりません", JsonRequestBehavior.AllowGet); if (!container.CanWrite) return Json("作成する権限がありません", JsonRequestBehavior.AllowGet); if (container.Contents.Any(x => String.Compare(x.Alias, inputModel.ContainerName, false) == 0)) { ModelState.AddModelError("ContainerName", "コンテナまたはページがすでに存在しています。"); } if (ModelState.IsValid) { return Json(true, JsonRequestBehavior.AllowGet); } else { return Json(ModelState.Values.Where(x => x.Errors.Any()).First().Errors.First().ErrorMessage, JsonRequestBehavior.AllowGet); } }