public async Task <IActionResult> Create([FromBody] CreateStorageRequest request)
        {
            if (string.IsNullOrWhiteSpace(request.StorageSite))
            {
                return(BadRequest());
            }

            using var transaction = await this._transactionProvider.BeginTransaction();

            var storage = await this._service.InsertItem(request.PZN, request.Amount, request.StorageSite);

            await transaction.CommitAsync();

            return(Ok(this._mapper.Map <StorageDTO>(storage)));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([FromBody] CreateStorageRequest createModel)
        {
            var storageEntity = _mapper.Map <Storage>(createModel);
            var createdUserId = int.Parse(HttpContext.GetUserIdFromRequest());

            var isCreateSuccess = await _storageService.CreateAsync(storageEntity, createdUserId);

            if (!isCreateSuccess)
            {
                return(BadRequest("Tạo kho hàng không thành công, vui lòng thử lại"));
            }

            var storageUri = _uriService.GetByIdUri(
                ApiRoutes.Storage.GetById.Replace("{storageId}", storageEntity.Id.ToString()));
            var storageResponse = _mapper.Map <StorageResponse>(storageEntity);

            return(Created(
                       storageUri,
                       new Response <StorageResponse>(storageResponse)));
        }