示例#1
0
        public async Task <ActionResult> Create(PostViewModel postViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(new JsonResult(new { success = false, Response = "", Error = ErrorHelper.GetModelStateErrorMessages(ModelState) }));
            }

            if (!_identityHelper.TryGetDistributor(out Distributor distributor, out string errorMessage))
            {
                return(new JsonResult(new { success = false, Response = "", Error = errorMessage }));
            }

            try
            {
                //uploading post photo to azure storage.
                string url = await _azureBlobService.UploadPostImage(postViewModel.DistributorId, postViewModel.Id, Request.Form.Files [0].FileName, Request.Form.Files [0].OpenReadStream());

                postViewModel.OriginalMediaLink = url;

                var createdPost = _postAdapter.Create(postViewModel, distributor);
                return(new JsonResult(new { success = true, Response = createdPost, Error = "" }));
            }
            catch (Exception exception)
            {
                return(new JsonResult(new { success = false, Response = "", Error = exception.Message }));
            }
        }