コード例 #1
0
        public string getScheduledPostInfo()
        {
            string        post_id = "";
            ScheduledPost s_post  = new ScheduledPost();

            if (Request.QueryString["post_id"] != null)
            {
                post_id = Request.QueryString["post_id"];
                newsManagement_Admin newsManager = new newsManagement_Admin();
                s_post = newsManager.GetSchedulePostByID(Convert.ToInt32(post_id));
            }
            else
            {
                return("non");
            }
            if (s_post.scheduled_date > DateTime.Now)
            {
                DateTime datetime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Parse(s_post.scheduled_date.ToString()));
                return(datetime.ToString("yyyy/MM/dd hh:mm tt") + ", " + s_post.activated);
            }
            else
            {
                return("non");
            }
        }
コード例 #2
0
ファイル: UWPController.cs プロジェクト: ashalogic/SocialCRM
        public async Task <IHttpActionResult> Add_Post(PostAddViewModel model)
        {
            if (!string.IsNullOrWhiteSpace(model.accountusername))
            {
                var    Db    = new ApplicationDbContext();
                string uname = RequestContext.Principal.Identity.GetUserName();
                var    user  = Db.Users.Where(x => x.UserName == uname).FirstOrDefault();
                if (user != null)
                {
                    var account = user.accounts.Where(x => x.username == model.accountusername && x.accounttype == AccountsEnum.Instagram).FirstOrDefault();
                    if (account != null)
                    {
                        var postmodel = new ScheduledPost()
                        {
                            id = Guid.NewGuid().ToString(), type = model.type, datetime = DateTime.FromBinary(long.Parse(model.date)), post = Convert.FromBase64String(model.data)
                        };
                        account.ScheduledPosts.Add(postmodel);
                        var result = await Db.SaveChangesAsync();

                        if (result == 1)
                        {
                            return(Ok());
                        }
                        else
                        {
                            return(new System.Web.Http.Results.ExceptionResult(new Exception(result.ToString()), this));
                        }
                    }
                    else
                    {
                        return(new System.Web.Http.Results.ExceptionResult(new Exception("No Account"), this));
                    }
                }
                return(new System.Web.Http.Results.ExceptionResult(new Exception("No user"), this));
            }
            return(new System.Web.Http.Results.ExceptionResult(new Exception("No user"), this));
        }
コード例 #3
0
        public ActionResult AddNewPost(newsPost p_newPost, HttpPostedFileBase file, string scheduled, string datetimepicker, string postgenres, string attributes)
        {
            Hypster_Entities     hyDB = new Hypster_Entities();
            newsManagement_Admin newsManager_admin = new newsManagement_Admin();
            newsManagement       newsManager       = new newsManagement();

            if (p_newPost.post_title != null && p_newPost.post_title != "")
            {
                if (p_newPost.post_content == null || p_newPost.post_content == "")
                {
                    ModelState.AddModelError("", "Please Enter the Post Content; it is REQUIRED!!");
                }
                if (p_newPost.post_short_content == null || p_newPost.post_short_content == "")
                {
                    ModelState.AddModelError("", "Please Enter the Short Post Content; it is REQUIRED!!");
                }

                p_newPost.post_date   = DateTime.Now;
                p_newPost.post_guid   = p_newPost.post_title.Replace("/", "").Replace("\\", "").Replace("&", "").Replace("+", "").Replace(" ", "-").Replace("?", "").Replace("!", "").Replace("*", "").Replace("$", "").Replace("\"", "").Replace("'", "").Replace("{", "").Replace("}", "").Replace(")", "").Replace("(", "").Replace("[", "").Replace("]", "").Replace("|", "").Replace(".", "").Replace(",", "").Replace(":", "").Replace(";", "");
                p_newPost.post_status = (int)postStatus.NoActive;
                //
                //check if post guid is exist in database
                newsPost post_check = newsManager_admin.GetPostByGUID(p_newPost.post_guid);
                if (post_check.post_id != 0 && newsManager_admin.GetPostByGUID(post_check.post_guid).post_guid != "")
                {
                    ModelState.AddModelError("", "NOT ABLE TO GENERATE POST GUID.Please choose modify title. Post with following title already exist.");
                }
                else //if post guid is unique then procceed to finish
                {
                    hyDB.newsPosts.AddObject(p_newPost);
                    hyDB.SaveChanges();
                    int id = p_newPost.post_id;
                    UploadImage(file, id);
                    if (scheduled == "Yes")
                    {
                        ScheduledPost sPost = new ScheduledPost();
                        sPost.post_id        = id;
                        sPost.scheduled_date = convertDateTime(datetimepicker);
                        sPost.activated      = 0;
                        hyDB.ScheduledPost.AddObject(sPost);
                        hyDB.SaveChanges();
                    }
                    if (attributes != "")
                    {
                        string[] attribute = attributes.Split(';');
                        foreach (string attr in attribute)
                        {
                            postNewsletter pNewsletter = new postNewsletter();
                            pNewsletter.post_id   = id;
                            pNewsletter.attribute = attr;
                            hyDB.postNewsletters.AddObject(pNewsletter);
                            hyDB.SaveChanges();
                        }
                    }
                    if (postgenres.Length != 0)
                    {
                        string[] postgenre = postgenres.Split(';');
                        for (int i = 0; i < postgenre.Length; i++)
                        {
                            Post_Genre postGenre = new Post_Genre();
                            postGenre.post_id  = id;
                            postGenre.genre_id = Convert.ToInt32(postgenre[i]);
                            hyDB.Post_Genre.AddObject(postGenre);
                            hyDB.SaveChanges();
                        }
                    }
                    return(RedirectToAction("Index", "managePost"));
                }
            }
            else
            {
                ModelState.AddModelError("", "Please enter post title. It must be unique from previous posts!!!");
            }

            // if no success
            return(View(new newsPost()));
        }
コード例 #4
0
        public ActionResult Edit(newsPost p_Post, HttpPostedFileBase file, string scheduled, string datetimepicker, string postgenres, string attributes)
        {
            newsManagement_Admin newsManager_admin = new newsManagement_Admin();
            newsManagement       newsManager       = new newsManagement();
            Hypster_Entities     hyDB  = new Hypster_Entities();
            ScheduledPost        sPost = new ScheduledPost();

            if (p_Post.post_status == 0 && scheduled == "Yes")
            {
                try
                {
                    // newsManager.GetSchedulePostByID(p_Post.post_id) may throw ArgumentOutOfRangeException error
                    sPost = newsManager_admin.GetSchedulePostByID(p_Post.post_id);
                    sPost.scheduled_date = convertDateTime(datetimepicker);
                    sPost.activated      = 0;
                    newsManager_admin.EditSPost(sPost);
                }
                catch (ArgumentOutOfRangeException e)
                {
                    // newsManager.GetSchedulePostByID(p_Post.post_id) throws ArgumentOutOfRangeException error which was occurred because the post is not having any records in the schedule post table.
                    // Therefore, one must be created.
                    Console.WriteLine(e.Message + " Scheduled Post does not exist previously for this post. Therefore, one must be created.\n\n" + e.StackTrace.ToString());
                    sPost.post_id        = p_Post.post_id;
                    sPost.scheduled_date = convertDateTime(datetimepicker);
                    sPost.activated      = 0;
                    hyDB.ScheduledPost.AddObject(sPost);
                }
            }
            else
            {
                try
                {
                    // newsManager.GetSchedulePostByID(p_Post.post_id) may throw ArgumentOutOfRangeException error
                    sPost           = newsManager_admin.GetSchedulePostByID(p_Post.post_id);
                    sPost.activated = 1;
                    newsManager_admin.EditSPost(sPost);
                }
                catch (ArgumentOutOfRangeException e)
                {
                    // newsManager.GetSchedulePostByID(p_Post.post_id) throws ArgumentOutOfRangeException error which was occurred because the post is not having any records in the schedule post table.
                    // Therefore, one must be created.
                    Console.WriteLine(e.Message + " Scheduled Post does not exist previously for this post. Therefore, one must be created.\n\n" + e.StackTrace.ToString());
                    sPost.post_id        = p_Post.post_id;
                    sPost.scheduled_date = DateTime.Now;
                    sPost.activated      = 1;
                    hyDB.ScheduledPost.AddObject(sPost);
                }
            }
            manageGenres(hyDB, newsManager, p_Post.post_id, postgenres, getAssociatedGenreIds(p_Post.post_id));
            manageAttributes(hyDB, newsManager_admin, p_Post.post_id, attributes, getAttrs(p_Post.post_id));
            newsManager_admin.EditPost(p_Post);
            UploadImage(file, p_Post.post_id);
            hyDB.SaveChanges();
            //update sitemaps date and ping google and bing
            //
            int sitemapNewsID = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["sitemap_newsID"]);

            SitemapManagement sitemapManager = new SitemapManagement();

            sitemapManager.UpdateDateChanged(sitemapNewsID, DateTime.Now);

            HttpWebRequest  ping_google_request   = (HttpWebRequest)WebRequest.Create("http://www.google.com/webmasters/sitemaps/ping?sitemap=http://hypster.com/sitemaps/sitemap_index");
            HttpWebResponse ping_google_response  = (HttpWebResponse)ping_google_request.GetResponse();
            Stream          google_resStream      = ping_google_response.GetResponseStream();
            String          google_responseString = "";

            using (google_resStream)
            {
                StreamReader google_reader = new StreamReader(google_resStream, Encoding.UTF8);
                google_responseString = google_reader.ReadToEnd();
            }

            HttpWebRequest  ping_bing_request   = (HttpWebRequest)WebRequest.Create("http://www.bing.com/webmaster/ping.aspx?siteMap=http://hypster.com/sitemaps/sitemap_index");
            HttpWebResponse ping_bing_response  = (HttpWebResponse)ping_bing_request.GetResponse();
            Stream          bing_resStream      = ping_bing_response.GetResponseStream();
            String          bing_responseString = "";

            using (bing_resStream)
            {
                StreamReader bing_reader = new StreamReader(bing_resStream, Encoding.UTF8);
                bing_responseString = bing_reader.ReadToEnd();
            }
            //-------------------------------------------------------------------------------------------------------------
            return(RedirectToAction("Index"));
        }