Exemple #1
0
        public async Task AddAsync(ArticleAddModel model)
        {
            MultipartFormDataContent formData = new MultipartFormDataContent();

            if (model.Image != null)
            {
                var bytes = await System.IO.File.ReadAllBytesAsync(model.Image.FileName);

                ByteArrayContent byteContent = new ByteArrayContent(bytes);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue(model.Image.ContentType);

                formData.Add(byteContent, nameof(ArticleAddModel.Image), model.Image.FileName);
            }

            var user = _httpContextAccessor.HttpContext.Session.GetObject <UserViewModel>(null);

            model.UserId = user.UserId;

            formData.Add(new StringContent(model.UserId.ToString()), nameof(ArticleAddModel.UserId));

            formData.Add(new StringContent(model.ShortDescription), nameof(ArticleAddModel.ShortDescription));

            formData.Add(new StringContent(model.Description), nameof(ArticleAddModel.Description));

            formData.Add(new StringContent(model.Title), nameof(ArticleAddModel.Title));

            // _httpClient.DefaultRequestHeaders.Authorization= new AuthenticationHeaderValue("Bearer",_httpContextAccessor.HttpContext.Session.GetString("token"));

            await _httpClient.PostAsync("", formData);
        }
Exemple #2
0
        public ActionResult AddConfirm(ArticleAddModel model)
        {
            var parameter = new ArticleCreateRequest(model.Title, model.Body, myId());
            var response  = bus.Handle(parameter);

            // You shoud return generated id from service or defivary notification object, if you wanna redirect to detail.
            return(RedirectToAction("MyList"));
        }
Exemple #3
0
        public ActionResult AddConfirm(ArticleAddModel model)
        {
            var createArticle = new CreateArticleCommand(model.Title, model.Body, myId());

            articleService.CreateArticle(createArticle);

            // You shoud return generated id from service or defivary notification object, if you wanna redirect to detail.
            return(RedirectToAction("MyList"));
        }
        public async Task <IActionResult> Create(ArticleAddModel model)
        {
            // TempData["active"]="blog";
            if (ModelState.IsValid)
            {
                await _blogApiService.AddAsync(model);

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Exemple #5
0
        public async Task <IResultModel> Add(ArticleAddModel model)
        {
            var entity = _mapper.Map <ArticleEntity>(model);
            //if (await _repository.Exists(entity))
            //{
            //return ResultModel.HasExists;
            //}

            var result = await _repository.AddAsync(entity);

            return(ResultModel.Result(result));
        }
        public async Task <IActionResult> Create([FromForm] ArticleAddModel articleAddModel)
        {
            var uploadModel = await UploadFileAsync(articleAddModel.Image, "image/jpeg");

            if (uploadModel.UploadState == Enums.UploadState.Success)
            {
                articleAddModel.ImagePath = uploadModel.NewName;
                await _articleService.AddAsync(_mapper.Map <Article>(articleAddModel));

                return(Created("", articleAddModel));
            }
            else if (uploadModel.UploadState == Enums.UploadState.NotExist)
            {
                await _articleService.AddAsync(_mapper.Map <Article>(articleAddModel));

                return(Created("", articleAddModel));
            }
            else
            {
                return(BadRequest(uploadModel.ErrorMessage));
            }
        }
Exemple #7
0
 public Task <IResultModel> Add(ArticleAddModel model)
 {
     return(_service.Add(model));
 }