예제 #1
0
        public async Task <IActionResult> CreateMap(string name)
        {
            // Validate data
            if (string.IsNullOrEmpty(name))
            {
                return(StatusCode((int)HttpStatusCode.BadRequest));
            }

            string validateResult = this.ValidateImageUploadData();

            if (validateResult != null)
            {
                return(StatusCode((int)HttpStatusCode.BadRequest, _localizer[validateResult]));
            }

            // Prepare Map
            KartaMap map = new KartaMap();

            map.Id   = Guid.NewGuid().ToString();
            map.Name = name;

            await this.SetModifiedData(_userManager, map);

            GoNorthProject project = await _projectDbAccess.GetDefaultProject();

            map.ProjectId = project.Id;

            // Process Map
            try
            {
                await _imageProcessor.ProcessMapImage(map, Request.Form.Files[0]);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Could not process map image.");
                _mapImageAccess.DeleteMapFolder(map.Id);
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }

            // Save Map
            try
            {
                await _mapDbAccess.CreateMap(map);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Could not save map.");
                _mapImageAccess.DeleteMapFolder(map.Id);
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }

            await _timelineService.AddTimelineEntry(TimelineEvent.KartaMapCreated, map.Name, map.Id);

            return(Ok(map.Id));
        }