Beispiel #1
0
        public async Task <IActionResult> PutPublishedPost(int id, PublishedPost publishedPost)
        {
            if (id != publishedPost.Id)
            {
                return(BadRequest());
            }

            _context.Entry(publishedPost).State = EntityState.Modified;

            try
            {
                DateTime currentTime = DateTime.Now;
                publishedPost.ModifiedTime = currentTime;
                publishedPost.DisplayDate  = publishedPost.ConvertToLocalTime(currentTime, "short");
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PublishedPostExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #2
0
        private async Task PublishPost(int id)
        {
            var user = await _userManager.GetUserAsync(User);

            var postFromDb = _db.Posts.Single(x => x.Id == id);



            var postList = _db.Posts.Where(p => p.UserId == user.Id).ToList();
            var b        = _db.Businesses.Single(x => x.UserId == user.Id);

            var results = Publisher.ValidToPost(postList, postFromDb, b);

            if (results.Item1 == true)
            {
                var publishedPost = new PublishedPost
                {
                    Post     = postFromDb,
                    Business = b
                };
                postFromDb.IsPublished = true;
                _db.PublishedPosts.Add(publishedPost);
                await _db.SaveChangesAsync();

                ViewData["PublishSuccess"] = results.Item2;
            }
            else
            {
                ViewData["PublishAlert"] = results.Item2;
            }
        }
Beispiel #3
0
        public static Tuple <bool, string> ValidToBump(PublishedPost post)
        {
            var now  = DateTime.Now;
            var span = now.Subtract(post.PublishTime);

            if (span.Hours >= MIN_BUMP)
            {
                return(Tuple.Create(true, "הפוסט הוקפץ בהצלחה"));
            }
            return(Tuple.Create(false, "הקפצת פוסט יכולה להתבצע כל 12 שעות"));
        }
Beispiel #4
0
        public async Task <ActionResult <PublishedPost> > PostPublishedPost(PublishedPost publishedPost)
        {
            DateTime currentTime = DateTime.Now;

            publishedPost.PublishedTime = currentTime;
            publishedPost.ModifiedTime  = currentTime;
            publishedPost.DisplayDate   = publishedPost.ConvertToLocalTime(currentTime, "short");
            _context.PublishedPost.Add(publishedPost);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPublishedPost", new { id = publishedPost.Id }, publishedPost));
        }
Beispiel #5
0
        public static PublishedPost ToPublishedPost(this FeedsIndexDoc indexDoc)
        {
            var publishedPost = new PublishedPost
            {
                Id           = indexDoc.Id,
                Heading      = indexDoc.Title,
                Snippet      = indexDoc.Text,
                CreatedTime  = indexDoc.CreatedTime.HasValue ? indexDoc.CreatedTime.Value : DateTime.UtcNow,
                ImageUrl     = indexDoc.ImageUrl,
                OriginalLink = indexDoc.OriginalLink,
                CardStyle    = indexDoc.CardStyle,
                PostedBy     = indexDoc.PostedBy,
                SharedBy     = indexDoc.SharedBy,
                LikedBy      = indexDoc.LikedBy,
                Streams      = indexDoc.Streams,
                Language     = indexDoc.Language,
                Tags         = indexDoc.Tags
            };

            return(publishedPost);
        }