コード例 #1
0
        public async Task <IActionResult> Create([FromBody] UpdateObjectViewModel request)
        {
            if (request == null)
            {
                return(BadRequest());
            }

            var currentUser = HttpContext.User;

            var updateCommand = new CreateObjectCommand
            {
                Name        = request.Name,
                Description = request.Description,
                Latitude    = request.Latitude,
                Longitude   = request.Longitude,
                Type        = request.Type
            };

            if (request.MainPhoto != null)
            {
                updateCommand.MainPhoto = new FileInfo
                {
                    FileId      = request.MainPhoto.FileId,
                    Description = request.MainPhoto.Description
                };
            }

            if (request.Photos != null)
            {
                updateCommand.Photos = request.Photos.Select(x => new FileInfo
                {
                    FileId      = x.FileId,
                    Description = x.Description
                }).ToList();
            }

            updateCommand.SetCreator(
                long.Parse(currentUser.FindFirstValue(ClaimTypes.NameIdentifier)).ToString(),
                currentUser.FindFirstValue(ClaimTypes.Name),
                currentUser.FindFirstValue(ClaimTypes.Email));

            var result = await _objectsRepository.CreateObject(updateCommand, CancellationToken.None);

            return(Ok(result));
        }