Пример #1
0
        /// <summary>
        /// Update floor markers.
        /// </summary>
        /// <param name="floorId">Floor id.</param>
        /// <param name="markers">Markers to set on the floor.</param>
        /// <param name="userEmail">Current user email.</param>
        /// <returns></returns>
        public async Task <bool> UpdateMarkersAsync(Guid floorId, List <MarkerDto> markers, 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 currentFloor = await _floorRepository.GetFloorAsync(floorId, true, true, true);

            if (currentFloor == null || currentFloor.Location == null || currentFloor.Location.OwnerId != user.Id)
            {
                return(false);
            }

            currentFloor.Markers.Clear();
            foreach (var m in markers)
            {
                currentFloor.Markers.Add(new Marker(m));
            }
            await _floorRepository.EditAsync(currentFloor);

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Edit floor.
        /// </summary>
        /// <param name="id">Floor id to edit.</param>
        /// <param name="floor">Floor model.</param>
        /// <param name="file">Image file.</param>
        /// <param name="userEmail">Current user email.</param>
        /// <returns></returns>
        public async Task <bool> EditFloorAsync(Guid id, 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 currentFloor = await _floorRepository.GetFloorAsync(id, true, false, false);

            if (currentFloor == null || currentFloor.Location == null || currentFloor.Location.OwnerId != user.Id)
            {
                return(false);
            }

            if (file != null)
            {
                // Check file size
                if (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;
                }

                await _fileStorageService.DeleteFileAsync(ConcatHelper.GetFloorFileName(currentFloor.LocationId, currentFloor.FloorId, currentFloor.IsSvg));

                currentFloor.MapWidth  = imageInfo.Width;
                currentFloor.MapHeight = imageInfo.Height;
                currentFloor.IsSvg     = isSvg;

                // Upload map file
                if (isSvg)
                {
                    await _fileStorageService.UploadFileAsync(file, ConcatHelper.GetFloorFileName(currentFloor.LocationId, currentFloor.FloorId, isSvg));
                }
                else
                {
                    await _fileStorageService.UploadFileAsync(imageInfo.Stream, ConcatHelper.GetFloorFileName(currentFloor.LocationId, currentFloor.FloorId, isSvg));
                }
            }

            currentFloor.Name = floor.Name;
            await _floorRepository.EditAsync(currentFloor);

            return(true);
        }