Beispiel #1
0
 public IActionResult CreateBlog(BlogCommand blog)
 {
     try
     {
         if (blog != null)
         {
             BlogDto data     = _mapper.Map <BlogDto>(blog);
             var     iSuccess = _blogService.AddBlog(data);
             if (iSuccess)
             {
                 SuccessModel.SuccessMessage = "Success";
                 SuccessModel.SuccessCode    = "200";
                 return(Ok(SuccessModel));
             }
             else
             {
                 ErrorModel.ErrorMessage = "Update fail";
                 ErrorModel.ErrorCode    = "400";
                 return(StatusCode(400, ErrorModel));
             }
         }
         else
         {
             ErrorModel.ErrorMessage = "Data fail";
             ErrorModel.ErrorCode    = "400";
             return(StatusCode(400, ErrorModel));
         }
     }
     catch (Exception ex)
     {
         ErrorModel.ErrorMessage = ex.Message;
         ErrorModel.ErrorCode    = "500";
         return(StatusCode(500, ErrorModel));
     }
 }
Beispiel #2
0
        public virtual JsonResult Edit(BlogEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { MessageType = 0, MessageContent = "数据未通过验证,请检查。" }));
            }
            Model.Blogs.Blog blog;

            if (model.Id > 0)
            {
                //编辑
                blog             = _blogService.GetBlog(model.Id);
                blog             = model.MapTo(blog);
                blog.Author      = UserContext.CurrentUser;
                blog.UpdatedTime = DateTime.Now;
                blog             = _blogService.UpdateBlog(blog);
            }
            else
            {
                //新增
                blog        = model.MapTo <Model.Blogs.Blog>();
                blog.Author = UserContext.CurrentUser;
                blog        = _blogService.AddBlog(blog);
            }

            if (blog == null || blog.Id == 0)
            {
                return(Json(new { MessageType = 0, MessageContent = "操作失败。请重试" }));
            }
            return(Json(new { MessageType = 1, MessageContent = "操作成功。" }));
        }
Beispiel #3
0
        public ActionResult <BlogItem> PostBlogItem(BlogItem item)
        {
            _blogService.AddBlog(item);

            return(CreatedAtAction(nameof(GetBlogItem), new BlogItem {
                Id = item.Id
            }, item));
        }
Beispiel #4
0
        public async Task AddBlogTest()
        {
            var blog = new AddBlogRequest("W", "Varasto ja sen tyhjennys", "vie kamat vittuun sielt.");

            await _service.AddBlog(blog);

            Assert.AreEqual(2, _blogs.Count);
        }
Beispiel #5
0
        public ActionResult AddBlog(Blog blog)
        {
            if (!IsBlogValid(blog))
            {
                return(BadRequest("Invalid Input model"));
            }

            _blogService.AddBlog(blog);
            return(Ok(blog));
        }
Beispiel #6
0
        public BlogController(IBlogService blogService)
        {
            _blogService = blogService;

            if (_blogService.AllBlogs().Count() == 0)
            {
                _blogService.AddBlog(new BlogItem {
                    Title = "First Post"
                });
            }
        }
        public bool AddBlog()
        {
            var blog = blogService.AddBlog();

            if (blog != null)
            {
                Blogs.Add(blog);
                return(true);
            }

            return(false);
        }
        public async Task <IActionResult> Post()
        {
            var model = new Blog();

            model.Url = "https://localhost:5001/test";

            var result = await _blogService.AddBlog(model);

            if (result == null)
            {
                return(BadRequest());
            }

            return(Ok(result));
        }
Beispiel #9
0
        public ActionResult CreateBlog(Blog blog)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            BlogDTO blogDTO          = MapDataDTO(blog);
            bool    createSuccessful = blogService.AddBlog(blogDTO);

            if (!createSuccessful)
            {
                ModelState.AddModelError("", "Creating blog failed...");
                return(View());
            }
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> AddBlog([FromBody] AddBlogModel model)
        {
            if (!TryValidateModel(model))
            {
                var errors = ModelState.Select(x => new { x.Key, x.Value }).ToArray();

                return(BadRequest(errors));
            }

            var result = await service.AddBlog(model);

            if (result == null)
            {
                return(BadRequest("Selected title already taken. Please change it to something else"));
            }

            return(Ok(result));
        }
Beispiel #11
0
        public object ItemSave(Blog blog, BlogInput blogInput)
        {
            //TODO: (erikpo) Check permissions

            ValidationStateDictionary validationState;

            if (blog == null)
            {
                ModelResult <Blog> results = blogService.AddBlog(blogInput);

                validationState = results.ValidationState;

                if (results.IsValid)
                {
                    ////TODO: (erikpo) Get rid of HasMultipleBlogs and make it a calculated field so the following isn't necessary
                    //Site siteToEdit = siteService.GetSite(site.Name);

                    //siteToEdit.HasMultipleBlogs = true;

                    //siteService.EditSite(siteToEdit, out validationState);

                    if (validationState.IsValid)
                    {
                        OxiteApplication.Load(ControllerContext.HttpContext);
                    }
                }
            }
            else
            {
                ModelResult <Blog> results = blogService.EditBlog(blog, blogInput);

                validationState = results.ValidationState;
            }

            if (!validationState.IsValid)
            {
                ModelState.AddModelErrors(validationState);

                return(ItemEdit(blog));
            }

            return(Redirect(Url.AppPath(Url.Admin())));
        }
Beispiel #12
0
        public JsonResult Add(string title, string content, string ids)
        {
            ResultModel result = new ResultModel();
            int         userId = Convert.ToInt32(User.Claims.Single(c => c.Type == ClaimTypes.Sid).Value);

            string[] sids = ids.Split(',').ToArray();
            Blog     blog = new Blog {
                Title = title, Content = content, UserInfoId = userId
            };

            if (_blogService.AddBlog(blog, sids))
            {
                result.Status = System.Net.HttpStatusCode.OK;
                result.Msg    = "Success";
            }
            else
            {
                result.Status = System.Net.HttpStatusCode.InternalServerError;
                result.Msg    = "Error";
            }
            return(Json(result));
        }
Beispiel #13
0
        public async Task <IActionResult> NewBlog(BlogInfo blog)
        {
            try
            {
                var result = await blogService.AddBlog(blog);

                var blogInfo = new BlogInfo {
                    Id = result.Id
                };
                return(Ok(blogInfo));
            }
            catch (InternalException ie)
            {
                logger.LogError(500, ie, ie.Message, null);
                return(NotFound(ie.Message));
            }
            catch (BadRequestException be)
            {
                logger.LogError(404, be, be.Message, null);
                return(BadRequest(be.Message));
            }
        }
        public async Task <IActionResult> Create(BlogCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var blog = new Blog()
                {
                    BlogName        = viewModel.BlogName,
                    Description     = viewModel.Description,
                    Author          = await _accountService.GetCurrentUser(User),
                    CreatedDateTime = DateTime.Now,
                    UpdatedDateTime = DateTime.Now,
                };

                if (viewModel.ImageFile?.FileName != null)
                {
                    blog.ImagePath = await _imageService.SaveBlogImage(viewModel.ImageFile);
                }

                await _blogService.AddBlog(blog, viewModel.BlogStyleId);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewModel));
        }
 public ActionResult <Blog> AddBlog(Blog blog)
 {
     myService.AddBlog(blog);
     return(blog);
 }
Beispiel #16
0
 public void Post([FromBody] BlogDetailViewModel blogDetailModel)
 {
     _blogService.AddBlog(blogDetailModel);
 }