Example #1
0
        public async Task <IActionResult> Execute(JObject jObj, string subject)
        {
            if (jObj == null)
            {
                throw new ArgumentNullException(nameof(jObj));
            }

            if (string.IsNullOrWhiteSpace(subject))
            {
                throw new ArgumentNullException(nameof(subject));
            }

            var command = _requestBuilder.GetAddProductComment(jObj);

            command.CreateDateTime = DateTime.UtcNow;
            command.UpdateDateTime = DateTime.UtcNow;
            command.Id             = Guid.NewGuid().ToString();
            command.Subject        = subject;
            var validationResult = await _addCommentValidator.Validate(command);

            if (!validationResult.IsValid)
            {
                var error = _responseBuilder.GetError(ErrorCodes.Request, validationResult.Message);
                return(_controllerHelper.BuildResponse(HttpStatusCode.BadRequest, error));
            }
            _commandSender.Send(command);
            var obj = new { id = command.Id };

            return(new OkObjectResult(obj));
        }