Example #1
0
        public async Task <IActionResult> AddBlogAsync([FromBody] BlogInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ApiError(400, HttpStatusCode.BadRequest.ToString(), "Data isn't valid.")));
            }

            if (!long.TryParse(this.User.Identity.Name, out long userId))
            {
                return(BadRequest(new ApiError(400, HttpStatusCode.BadRequest.ToString(), "UserId isn't valid.")));
            }

            var userById = await _userRepository.GetUserByIdAsync(userId);

            if (userById == null)
            {
                return(NotFound(new ApiError(404, HttpStatusCode.NotFound.ToString(), "User wasn't found.")));
            }

            var blog = Blog.New(userById, model.Title, model.Subtitle, model.ImageUrl, model.Body);

            await _blogRepository.AddBlogAsync(blog);

            var blogOutputModel = Mapper.Map <BlogOutputModel>(blog);

            await _hubContext.Clients.All.BroadcastNotification(new BlogNotification
            {
                BlogId     = blog.Id,
                BlogTitle  = blog.Title,
                AuthorName = blog.User.FullName
            });

            return(Ok(blogOutputModel));
        }
Example #2
0
        public IActionResult UpdateBlogAsync()
        {
            BlogInputModel blogFromBody = JsonConvert.DeserializeObject <BlogInputModel>(JsonFromBody());

            Task tarefa = new Task <long>(() => _blogService.Update(blogFromBody).Result);

            return(ResultSearch(tarefa));
        }
 public ActionResult Create(BlogInputModel model)
 {
     if (ModelState.IsValid)
     {
         _blogService.Create(model);
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Example #4
0
        public void RepositoryReal_ceate_blog_corrected()
        {
            BlogInputModel blogImputModel = configurations.GetBlogInputModel();

            blogImputModel.Title = "title_2";

            BlogViewModel blogViewModelSaved = this.blogService.Create(blogImputModel).Result;

            Assert.Equal("title_2", blogViewModelSaved.Title);
        }
        public void Integration_blog_update_ok()
        {
            BlogInputModel blogImputModel = GetBlogInputModel();

            var responseInfo = this._integrationBase.PutResult(blogImputModel);

            var resultado           = responseInfo.Content.ReadAsStringAsync().Result;
            var patientUpdateResult = JsonConvert.DeserializeObject <long>(resultado, settings);

            Assert.Equal(1, patientUpdateResult);
        }
        public void Integration_blog_create_fail(string fieldEmpty, string messageError)
        {
            BlogInputModel blogInputModel = GetBlogInputModel();

            blogInputModel.GetType().GetProperty(fieldEmpty).SetValue(blogInputModel, "");

            var responseInfo = this._integrationBase.PostResult(blogInputModel);

            var resultado = responseInfo.Content.ReadAsStringAsync().Result;

            Assert.Contains(messageError, resultado);
        }
        public void Integration_blog_update_fail()
        {
            BlogInputModel blogImputModel = GetBlogInputModel();

            blogImputModel.key = new Guid("ca3aa919-c935-4c9f-b304-7d744dbe050e");

            var responseInfo = this._integrationBase.PutResult(blogImputModel);

            var patientUpdateResult = JsonConvert.DeserializeObject <long>(responseInfo.Content.ReadAsStringAsync().Result, settings);

            Assert.Equal(0, patientUpdateResult);
        }
Example #8
0
        public IActionResult Create([FromBody] BlogInputModel blogInputModel)
        {
            try
            {
                Task tarefa = new Task <BlogViewModel>(() => _blogService.Create(blogInputModel).Result);

                return(ResultSearch(tarefa, true, "Create"));
            }
            catch (ArgumentException exception)
            {
                return(BadRequest($"{exception.Message}"));
            }
        }
Example #9
0
        public Task <BlogViewModel> Create(BlogInputModel blogInputModel)
        {
            Domain.Entities.Blog blogToBeSaved = MapperInputViewToDomain(blogInputModel);
            blogToBeSaved.SetItensConstructor();

            this.Validation(blogToBeSaved);

            Domain.Entities.Blog blogSaved = this.BlogRepository.Insert(blogToBeSaved).Result;

            BlogViewModel blogSavedViewModel = _mapper.Map <BlogViewModel> (blogSaved);

            return(Task.FromResult(blogSavedViewModel));
        }
Example #10
0
        public async Task <IActionResult> Create(BlogInputModel input)
        {
            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            await this.blogService.CreateBlog(input.Title, input.ImageUrl, userId);

            await this.blogService.CreateBlogContent(input.Title, input.Content);

            return(this.RedirectToAction(
                       "Blog",
                       "Blog",
                       new { area = string.Empty }));
        }
Example #11
0
        public static BlogInputModel GetBlogInputModel()
        {
            var blogInputModel = new BlogInputModel
            {
                Title     = "title",
                Text      = "text",
                ImageCard = "imagecard",
                Active    = true,
                Tags      = "tags",
                TitleNFD  = "titlenfd"
            };

            return(blogInputModel);
        }
        public void Integration_blog_create_ok()
        {
            BlogInputModel blogInputModel = GetBlogInputModel();

            blogInputModel.Title = "title create_" + DateTime.Now.ToShortDateString() + "_" + DateTime.Now.ToShortTimeString();
            blogInputModel.key   = Guid.Empty;

            var responseInfo = this._integrationBase.PostResult(blogInputModel);

            var resultado        = responseInfo.Content.ReadAsStringAsync().Result;
            var blogCreateResult = JsonConvert.DeserializeObject <BlogViewModel>(resultado, settings);

            Assert.Contains("title create_", blogCreateResult.Title);
        }
        public static BlogInputModel GetBlogInputModel()
        {
            var blogInputModel = new BlogInputModel
            {
                key       = new Guid("620e0d10-e6fa-45e4-a30b-44570542c6d5"),
                Title     = "title_update_" + DateTime.Now.ToShortDateString() + "__" + DateTime.Now.ToShortTimeString(),
                Text      = "text",
                ImageCard = "imagecard",
                Active    = true,
                Tags      = "tags",
                TitleNFD  = "titlenfd"
            };

            return(blogInputModel);
        }
Example #14
0
        public long Create(BlogInputModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var blog = new BlogEntity
            {
                Title   = model.Title,
                Content = model.Content,
                Created = DateTime.Now
            };

            _dbContext.Blogs.Add(blog);
            _dbContext.SaveChanges();
            return(blog.Id);
        }
Example #15
0
        public void RepositoryReal_update_blog_corrected()
        {
            BlogViewModel blogViewModelSaved = this.blogService.SearchByKey(new System.Guid("620e0d10-e6fa-45e4-a30b-44570542c6d5")).Result;

            BlogInputModel blogInputModel = new BlogInputModel()
            {
                Active    = blogViewModelSaved.Active,
                key       = blogViewModelSaved.Key,
                ImageCard = blogViewModelSaved.ImageCard,
                Tags      = blogViewModelSaved.Tags,
                Text      = blogViewModelSaved.Text,
                Title     = blogViewModelSaved.Title + "_update1",
                TitleNFD  = blogViewModelSaved.TitleNFD
            };

            long blogUpdateResult = this.blogService.Update(blogInputModel).Result;

            Assert.Equal(1, blogUpdateResult);
        }
Example #16
0
        public async Task <IActionResult> Create(BlogInputModel input)
        {
            if (!this.stringValidator.IsStringValid(input.Body, BodyMinLength))
            {
                this.ModelState.AddModelError("Error", EmptyBody);
            }

            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            byte[] picture = input.Picture == null ? null : await input.Picture.GetBytesAsync();

            string pictureExtension = input.Picture == null ? null : Path.GetExtension(input.Picture.FileName);

            var userId = this.userManager.GetUserId(this.User);

            await this.blogServie.CreateAsync <BlogInputModel>(input, userId, picture, this.PicturePath, pictureExtension);

            return(this.RedirectToAction(nameof(this.All)));
        }
Example #17
0
 private Domain.Entities.Blog MapperInputViewToDomain(BlogInputModel blogInputModel)
 {
     return(_mapper.Map <Domain.Entities.Blog> (blogInputModel));
 }
        // GET: Blog/Create
        public ActionResult Create()
        {
            var model = new BlogInputModel();

            return(View(model));
        }
Example #19
0
 public Task <long> Update(BlogInputModel blogInputModel)
 {
     Domain.Entities.Blog blogToBeUpdate = MapperInputViewToDomain(blogInputModel);
     this.Validation(blogToBeUpdate);
     return(Task.FromResult(this.BlogRepository.Update(blogToBeUpdate).Result));
 }