コード例 #1
0
        public async Task <IActionResult> Execute(JObject obj, HttpRequest request, string subject, string commonId)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

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

            // 1. Check the request
            AddShopCommand command = null;

            try
            {
                command = _requestBuilder.GetAddShop(obj);
            }
            catch (ArgumentException ex)
            {
                var error = _responseBuilder.GetError(ErrorCodes.Request, ex.Message);
                return(_controllerHelper.BuildResponse(HttpStatusCode.BadRequest, error));
            }

            var validationResult = await _addShopValidator.Validate(command, subject);

            if (!validationResult.IsValid)
            {
                var error = _responseBuilder.GetError(ErrorCodes.Request, validationResult.Message);
                return(_controllerHelper.BuildResponse(HttpStatusCode.BadRequest, error));
            }

            command.Id             = Guid.NewGuid().ToString();
            command.CreateDateTime = DateTime.UtcNow;
            command.UpdateDateTime = DateTime.UtcNow;
            command.Subject        = subject;
            command.CommonId       = commonId;
            if (!string.IsNullOrWhiteSpace(command.BannerImage))
            {
                string bannerImage = null;
                if (AddImage(command.BannerImage, request, "banner", out bannerImage))
                {
                    command.BannerImage = bannerImage;
                }
            }

            if (!string.IsNullOrWhiteSpace(command.ProfileImage))
            {
                string profileImage = null;
                if (AddImage(command.ProfileImage, request, "profile", out profileImage))
                {
                    command.ProfileImage = profileImage;
                }
            }

            var res = new { id = command.Id };

            _commandSender.Send(command);
            return(new OkObjectResult(res));
        }