Exemple #1
0
        //[Route("geodatalov/{registername}/ny")]
        //[Route("geodatalov/{parentregister}/{registerowner}/{registername}/ny")]
        public ActionResult Create(GeodatalovDatasetViewModel viewModel, string parentregister, string registername, string metadataUuid)
        {
            viewModel.Register = _registerService.GetRegisterBySystemId(viewModel.RegisterId);
            if (!_accessControlService.Access(viewModel.Register))
            {
                throw new HttpException(401, "Access Denied");
            }

            if (viewModel.SearchString != null)
            {
                viewModel.SearchResultList = _metadataService.SearchMetadataFromKartkatalogen(viewModel.SearchString);
                return(View(viewModel));
            }

            if (metadataUuid != null)
            {
                viewModel.Update(_metadataService.FetchGeodatalovDatasetFromKartkatalogen(metadataUuid));
                if (viewModel.Name == null)
                {
                    ModelState.AddModelError("ErrorMessage", "Det har oppstått en feil ved henting av metadata...");
                }
            }
            if (!_registerItemService.ItemNameIsValid(viewModel))
            {
                ModelState.AddModelError("ErrorMessage", HtmlHelperExtensions.ErrorMessageValidationDataset());
                return(View(viewModel));
            }
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }
            var inspireDataset = _geodatalovDatasetService.NewGeodatalovDataset(viewModel, parentregister, registername);

            return(Redirect(inspireDataset.Register.GetObjectUrl()));
        }
        //[Route("dataset/{parentRegister}/{registerowner}/{registername}/ny")]
        //[Route("dataset/{registername}/ny")]
        public ActionResult Create(Dataset dataset, string registername, string metadataUuid, string parentRegister, string registerowner, string searchString)
        {
            dataset.register = _registerService.GetRegister(parentRegister, registername);
            if (dataset.register != null)
            {
                if (_accessControlService.Access(dataset.register))
                {
                    dataset.systemId    = dataset.GetSystemId();
                    dataset.registerId  = dataset.register.GetSystemId();
                    dataset.DatasetType = dataset.GetDatasetType();

                    if (!string.IsNullOrEmpty(searchString))
                    {
                        SearchResultsType result = SearchMetadataFromKartkatalogen(searchString);
                        var resList = ParseSearchResult(result);
                        if (resList.Count == 0)
                        {
                            ViewBag.Message = "Søket gav ingen treff";
                        }
                        ViewBag.SearchResultList = resList;
                    }
                    else if (!string.IsNullOrEmpty(metadataUuid))
                    {
                        Dataset model = GetMetadataFromKartkatalogen(dataset, metadataUuid);
                        Viewbags(dataset);
                        return(View(model));
                    }
                    else if (!string.IsNullOrWhiteSpace(dataset.name))
                    {
                        if (!NameIsValid(dataset))
                        {
                            ModelState.AddModelError("ErrorMessage", HtmlHelperExtensions.ErrorMessageValidationDataset());
                            Viewbags(dataset);
                            return(View(dataset));
                        }
                        if (ModelState.IsValid)
                        {
                            dataset = GetMetadataFromKartkatalogen(dataset, dataset.Uuid);
                            dataset = _datasetService.UpdateDataset(dataset);
                            dataset.StatusHistories = _statusReportService.GetStatusHistoriesByDataset(dataset);
                            _registerItemService.SaveNewRegisterItem(dataset);
                            return(Redirect(dataset.GetObjectUrl()));
                        }
                    }
                }
                else
                {
                    throw new HttpException(401, "Access Denied");
                }
            }
            Viewbags(dataset);
            return(View(dataset));
        }