public async Task <IActionResult> EditFloorAsync(Guid id) { var files = Request.Form.Files; var floor = new FloorCreateRequestDto(await Request.ReadFormAsync()); var success = await _floorManager.EditFloorAsync(id, floor, files.Count == 1?files[0] : null, User.FindFirstValue(ClaimTypes.Email)); if (success) { return(Ok(true)); } else { return(BadRequest()); } }
/// <summary> /// Create a new floor to a location. /// </summary> /// <param name="floor">Floor model.</param> /// <param name="file">Image file.</param> /// <param name="locationId">Location id to map the floor to.</param> /// <param name="userEmail">Current user email.</param> /// <returns></returns> public async Task <bool> CreateFloorAsync(Guid locationId, FloorCreateRequestDto floor, IFormFile file, string userEmail) { // Get current user id var user = await _accountManager.GetAccountInfoAsync(userEmail); if (user == null) { return(false); } // Get location to edit and check user rights var currentLocation = await _locationRepository.GetLocationAsync(locationId, true); if (currentLocation == null || currentLocation.OwnerId != user.Id) { return(false); } // Check file size if (file.Length == 0 || file.Length > _uploadOptions.MaxFileSize) { return(false); } // Check file type var isSvg = false; ImageStreamInfo imageInfo; try { imageInfo = ImageHelper.ConvertImage(file, ImageFormat.Jpeg); } catch (Exception ex) { _logger.LogError(ex.Message); imageInfo = null; } if (imageInfo == null) { // Check if svg imageInfo = ImageHelper.GetSvgInfo(file); isSvg = true; } var newFloor = new Floor(floor) { IsSvg = isSvg, MapWidth = imageInfo.Width, MapHeight = imageInfo.Height }; currentLocation.Floors.Add(newFloor); await _locationRepository.EditAsync(currentLocation); // Upload map file if (isSvg) { await _fileStorageService.UploadFileAsync(file, ConcatHelper.GetFloorFileName(currentLocation.LocationId, newFloor.FloorId, isSvg)); } else { await _fileStorageService.UploadFileAsync(imageInfo.Stream, ConcatHelper.GetFloorFileName(currentLocation.LocationId, newFloor.FloorId, isSvg)); } return(true); }
public Floor(FloorCreateRequestDto floor) { this.Name = floor.Name; }