public async Task <string> UploadDataDelivery()
        {
            Authorize("Dataleverandør");

            var username = RequestForm("username");

            var       metadata1 = Request.Form.Files.GetFile("metadata");
            IDataFile metadata  = new HttpFormFile(metadata1);
            var       files     = HttpFormFile.GetFormFiles(Request.Form.Files);

            await arkiv.LastOppDataleveranse(dataleveranseXmlGreier, metadata, files, username);

            return("OK");
        }
        public async Task <string> UploadGrid()
        {
            Authorize("Dataleverandør");

            IFormFile    grid2 = Request.Form.Files.GetFile("grid");
            HttpFormFile grid  = new HttpFormFile(grid2);
            DataFiles    files = HttpFormFile.GetFormFiles(Request.Form.Files);

            var gridXml = grid.ReadXml();

            dataleveranseXmlGreier.ValidateGrid(gridXml);
            try
            {
                var gridFileDocId = Guid.NewGuid();
                var gridFile      = new File
                {
                    Id          = gridFileDocId.ToString(),
                    FileName    = grid.Filename,
                    ContentType = grid.ContentType,
                    Content     = grid.OpenReadStream()
                };
                await arkiv.LagreFil(gridFile);

                Collection <Nin.Types.MsSql.Document> documents;
                if (gridXml.Root.Name.LocalName.Equals("AdministrativtOmraadeKart"))
                {
                    AreaLayer areaLayer = AreaLayerImpl.FromXml(gridXml);
                    files.CheckDocuments(areaLayer.Documents);
                    areaLayer.DocGuid = gridFileDocId;
                    documents         = areaLayer.Documents;
                    SqlServer.BulkStoreAreaLayer(areaLayer);
                }
                else
                {
                    var gridLayer = GridLayerImpl.FromXml(gridXml);

                    files.CheckDocuments(gridLayer.Documents);
                    gridLayer.DocGuid = gridFileDocId;
                    documents         = gridLayer.Documents;
                    SqlServer.BulkStoreGridLayer(gridLayer);
                }

                foreach (var file in files.Values)
                {
                    var fileName = file.Filename;
                    var document = FindDocument(documents, fileName);

                    var docFile = new File
                    {
                        Id          = document.Guid.ToString(),
                        FileName    = fileName,
                        ContentType = file.ContentType,
                        Content     = file.OpenReadStream()
                    };
                    await arkiv.LagreFil(docFile);
                }
            }
            catch
            {
                arkiv.DiscardChanges();
                throw;
            }

            return("OK");
        }
        public async Task <string> UploadGridDelivery()
        {
            Authorize("Dataleverandør");

            var mapType = RequestForm("kartType");
            var files   = HttpFormFile.GetFormFiles(Request.Form.Files);

            var delivery = new GridDelivery
            {
                Name        = RequestForm("navn"),
                Description = RequestForm("beskrivelse"),
                Code        = new Code
                {
                    Value    = RequestForm("kode"),
                    Registry = RequestForm("koderegister"),
                    Version  = RequestForm("kodeversjon")
                },
                Owner = new Contact
                {
                    Company       = RequestForm("firmanavn"),
                    ContactPerson = RequestForm("kontaktperson"),
                    Email         = RequestForm("ownerEmail"),
                    Homesite      = RequestForm("hjemmeside"),
                    Phone         = RequestForm("telefon")
                },
                Established = DateTime.Parse(RequestForm("etablertDato"))
            };

            delivery.MapGridTypeNumber(RequestForm("ssbType"));
            delivery.MapAreaTypeNumber(RequestForm("aoType"));
            delivery.DocumentDescription = RequestForm("dokumentBeskrivelse");
            delivery.Username            = RequestForm("username");

            try
            {
                foreach (var file in files.Values)
                {
                    var document = new Nin.Types.RavenDb.Document {
                        FileName = file.Filename
                    };
                    delivery.Documents.Add(document);

                    var docFile = new File
                    {
                        Id          = document.Guid.ToString(),
                        FileName    = document.FileName,
                        ContentType = file.ContentType,
                        Content     = file.OpenReadStream()
                    };
                    await arkiv.LagreFil(docFile);
                }

                arkiv.LagreRutenettleveranse(delivery);
                arkiv.SaveChanges();
            }
            catch
            {
                arkiv.DiscardChanges();
                throw;
            }

            return("OK");
        }