public IActionResult CreateNewPost(PostNew postNew)
        {
            if (ModelState.IsValid)
            {
                var idUser = aartistRepository.GetIdUserByUsurName(User.Identity.Name);

                var id = aartistRepository.GetIdArtistByIdUser(idUser);

                byte[] fileBytes = new byte[] { };


                using (var ms = new MemoryStream())
                {
                    postNew.ImageFile.CopyTo(ms);
                    fileBytes = ms.ToArray();

                    // act on the Base64 data
                }



                aartistRepository.AddPost(new Data.ModelsData.Post
                {
                    idArtist    = id,
                    Description = postNew.Description,
                    Title       = postNew.Title,
                    Image       = ResizeImage(fileBytes),
                    UploadTime  = DateTime.Now
                });
            }
            return(RedirectToAction("MyPost"));
        }
        public JsonResult CreateNewPostJson(PostNew postNew)
        {
            if (ModelState.IsValid)
            {
                //var idUser = aartistRepository.GetIdUserByUsurName(User.Identity.Name);

                //var id = aartistRepository.GetIdArtistByIdUser(idUser);

                //byte[] fileBytes = new byte[] { };


                //using (var ms = new MemoryStream())
                //{
                //    postNew.ImageFile.CopyTo(ms);
                //    fileBytes = ms.ToArray();

                //    // act on the Base64 data
                //}



                //aartistRepository.AddPost(new Data.ModelsData.Post
                //{

                //    idArtist = id,
                //    Description = postNew.Description,
                //    Title = postNew.Title,
                //    Image = ResizeImage(fileBytes),
                //    UploadTime = DateTime.Now

                //});
            }
            return(Json("ok"));
        }
        /// <summary>
        /// Translate an XML RPC Post in Database Post
        /// </summary>
        /// <param name="db"></param>
        /// <param name="post"></param>
        /// <returns></returns>
        private static Engine.Data.Models.Post TranslatePost(DataService db, PostNew post, Boolean publish)
        {
            // Create a new post
            var result = new Engine.Data.Models.Post
            {
                Title          = post.Title,
                DateCreatedGmt = post.DateCreatedGmt ?? post.DateCreated ?? DateTime.UtcNow,
                Published      = publish
            };

            result.SetContentFromHtml(post.Description);

            // Get categories
            result.Categories = new Collection <Engine.Data.Models.Category>();
            var categories = db.GetCategoriesAndCreatIfNotExists(post.Categories);

            if (categories?.Length > 0)
            {
                // Add categories
                foreach (var category in categories)
                {
                    result.Categories.Add(category);
                }
            }

            return(result);
        }
Esempio n. 4
0
        public object AddNews(PostNews Reg)
        {
            try
            {
                PostNew mg = new PostNew();
                if (mg.NewsId == 0)
                {
                    mg.Headlines = Reg.Headlines;
                    mg.News      = Reg.News;



                    DB.PostNews.Add(mg);
                    DB.SaveChanges();
                    return(new Response
                    {
                        Status = "Success", Message = "News SuccessFully Saved."
                    });
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(new Response
            {
                Status = "Error", Message = "Invalid Data."
            });
        }
Esempio n. 5
0
 public ActionResult DodajPost(PostNew obiekt)
 {
     if (db_admin.DodajPosta(obiekt))
     {
         ViewData["action"] = "Post zostal dodany ;)";
     }
     else
     {
         ViewData["action"] = "Post nie zostal dodany ;(";
     }
     return(View(obiekt));
 }
Esempio n. 6
0
 public async Task <IActionResult> Add(PostNew payload)
 {
     var question = new Models.Question
     {
         Answers = payload.Answ.Select(text => new Models.Answer {
             Text = text
         }).ToList(),
         QuestionType = payload.Type switch
         {
             "SingleAnswer" => Models.QuestionType.SingleAnswer,
             "ManyAnswers" => Models.QuestionType.ManyAnswers,
             string other => throw new ArgumentException($"Не поддерживаемый тип вопроса {other}")
         },
Esempio n. 7
0
        /// <summary>
        /// 添加岗位
        /// </summary>
        /// <param name="post"></param>
        /// <returns></returns>
        public ActionResult <bool> AddPost(PostNew post)
        {
            try
            {
                if (post == null)
                {
                    throw new Exception("参数有误");
                }
                if (post.Org == Guid.Empty || post.Principal == Guid.Empty)
                {
                    throw new Exception("请选择组织架构或负责人!");
                }
                var check = _rpspost.Any(p => p.Name == post.Name);
                if (check)
                {
                    throw new Exception("该岗位已存在");
                }

                var dbpost = post.MAPTO <Basic_Post>();
                //自定义项
                var definedvalue = new UserDefinedBusinessValue
                {
                    BusinessID = dbpost.ID,
                    Values     = post.UserDefineds
                };
                var defined = usedefinedService.SaveBuisnessValue(definedvalue);
                if (defined.state != 200)
                {
                    throw new Exception(defined.msg);
                }
                //文件
                var files = new AttachFileSave
                {
                    BusinessID = dbpost.ID,
                    files      = post.fileNews
                };
                var file = srvFile.SaveFiles(files);
                if (file.state != 200)
                {
                    throw new Exception(file.msg);
                }
                _rpspost.Add(dbpost);
                _work.Commit();
                return(new ActionResult <bool>(true));
            }
            catch (Exception ex)
            {
                return(new ActionResult <bool>(ex));
            }
        }
Esempio n. 8
0
        public static void Crawling(string url, string image, string subLinkID, string accID)
        {
            try
            {
                using (var _db = new CrawlerModel())
                {
                    var checkInsert = _db.PostNews.Where(o => o.LinkHTML == url && !o.IsDelete).FirstOrDefault();
                    var crawler     = _db.CrawlerSubLinks.Where(o => o.ID == subLinkID && o.IsRun && !o.IsDelete).FirstOrDefault();
                    if (crawler != null && checkInsert == null)
                    {
                        HtmlWeb htmlWeb = new HtmlWeb();
                        HtmlAgilityPack.HtmlDocument htmlDoc = htmlWeb.Load(url);

                        string   title       = htmlDoc.DocumentNode.SelectNodes(crawler.XPathTitle).ToString().Trim();
                        string   description = htmlDoc.DocumentNode.SelectNodes(crawler.XPathDescription).ToString().Trim();
                        DateTime date        = GetDatetimeFormString(htmlDoc.DocumentNode.SelectNodes(crawler.XPathDate).ToString().Trim());
                        string   content     = htmlDoc.DocumentNode.SelectNodes(crawler.XPathContent).ToString().Trim();

                        PostNew news = new PostNew()
                        {
                            ID               = Guid.NewGuid().ToString(),
                            CrawlerLinkID    = crawler.CrawlerLinkID,
                            CrawlerSubLinkID = crawler.ID,
                            LinkHTML         = url,
                            Title            = title,
                            Image            = image,
                            Description      = description,
                            Date             = date,
                            Content          = content,
                            IsAccept         = false,
                            IsDelete         = false,
                            CreateUser       = accID,
                            CreateDate       = DateTime.Now,
                            ModifierUser     = accID,
                            ModifierDate     = DateTime.Now
                        };
                        _db.PostNews.Add(news);
                        _db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 public Int32 NewPost(String blogId, String userName, String password, PostNew post, Boolean publish)
 {
     using (var db = new DataService())
     {
         if (!db.PublisherAccessAllowed(userName, password))
         {
             return(-1);
         }
         // Get a post to insert
         var result = TranslatePost(db, post, publish);
         // Try to insert
         if (!db.AddPost(result))
         {
             return(-1);
         }
         return(result.Id);
     }
 }
 public Boolean EditPost(String postId, String userName, String password, PostNew post, Boolean publish)
 {
     using (var db = new DataService())
     {
         if (!db.PublisherAccessAllowed(userName, password))
         {
             return(false);
         }
         // Get a post to insert
         var   result = TranslatePost(db, post, publish);
         Int32 id     = Int32.Parse(postId);
         if (id > 0)
         {
             result.Id = id;
             // Try to edit
             return(db.EditPost(result));
         }
         else
         {
             return(db.AddPost(result));
         }
     }
 }
Esempio n. 11
0
 public ActionResult <bool> AddPost(PostNew post)
 {
     LogContent = "新建岗位模型,参数源:" + JsonConvert.SerializeObject(post);
     return(bll.AddPost(post));
 }