示例#1
0
        public IActionResult Batch(Guid batchId, string fileName,
                                   [FromHeader(Name = "X-Content-Size")] string contentSize,
                                   [FromHeader(Name = "X-MIME-Type")] string mimeType = "application/octet-stream")
        {
            ModelState.Clear();
            _logger.Log(LogLevel.Information, "Adding a new batch file");

            BatchFileValidator validator = new BatchFileValidator();

            try
            {
                BatchFile batchFile = _batchData.AddBatchFile(batchId, fileName, mimeType, contentSize);
                var       result    = validator.Validate(batchFile);
                if (result.IsValid)
                {
                    _logger.Log(LogLevel.Information, "New batch file added");
                    return(Ok());
                }
                else
                {
                    ModelState.AddModelError("Batch", "Could be a bad batch ID; a batch ID that doesn't exist; a bad filename");
                    _logger.Log(LogLevel.Warning, $"Bad Request, Error(s):- Batch Id doesn't exists.");
                    return(BadRequest("Bad Request - Could be a bad batch ID; a batch ID that doesn't exist; a bad filename"));
                }
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, ex.Message);
                return(BadRequest());
            }
        }