Exemple #1
0
        public ActionResult ApproveLastPost(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BigStory bigStory = db.BigStories.Include("UnModeratedPost").Where(x => x.Id == id).FirstOrDefault();

            if (bigStory == null)
            {
                return(HttpNotFound());
            }
            if (!bigStory.AllUsers.Any(x => x.StoryTellerName == bigStory.UnModeratedPost.User.StoryTellerName))
            {
                bigStory.AllUsers.Add(bigStory.UnModeratedPost.User);
            }
            bigStory.Posts.Add(bigStory.UnModeratedPost);
            bigStory.IsLocked        = false;
            bigStory.WhenLocked      = null;
            bigStory.CurrentUser     = null;
            bigStory.UnModeratedPost = null;

            db.SaveChanges();

            return(RedirectToAction("BigStoryModerate"));
        }
Exemple #2
0
        public async Task <ActionResult> BigStoryEdit([Bind(Include = "Id,Title,Created,IsLocked,Deadline,MaxNumberOfPosts,HoursToWrite", Exclude = "StoryPhoto")] BigStory bigStory)
        {
            var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());

            byte[] imageData = null;
            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase poImgFile = Request.Files["StoryPhoto"];

                using (var binary = new BinaryReader(poImgFile.InputStream))
                {
                    imageData = binary.ReadBytes(poImgFile.ContentLength);
                }
            }

            var oldPhoto = db.BigStories.Find(bigStory.Id).StoryPhoto;

            if (ModelState.IsValid)
            {
                if (imageData.Count() > 0)
                {
                    bigStory.StoryPhoto = imageData;
                }
                else
                {
                    bigStory.StoryPhoto = oldPhoto;
                }
                db.Set <BigStory>().AddOrUpdate(bigStory);
                db.SaveChanges();
                return(RedirectToAction("BigStoryIndex"));
            }
            return(View(bigStory));
        }
Exemple #3
0
        public ActionResult Index(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }


            BigStory bigStory    = db.BigStories.Find(id);
            var      currentUser = manager.FindById(User.Identity.GetUserId());

            if (bigStory == null)
            {
                return(HttpNotFound());
            }

            UpdateBigStory(bigStory);

            BigStoryUser bigStoryUser = new BigStoryUser()
            {
                bigStory  = bigStory,
                loginUser = currentUser
            };

            return(View(bigStoryUser));
        }
Exemple #4
0
        public ActionResult BigStoryDeleteConfirmed(int id)
        {
            BigStory bigStory = db.BigStories.Find(id);

            db.Comments.RemoveRange(bigStory.Comments);
            db.PartsBigStory.RemoveRange(bigStory.Posts);
            db.BigStories.Remove(bigStory);
            db.SaveChanges();
            return(RedirectToAction("BigStoryIndex"));
        }
Exemple #5
0
        public ActionResult BigStoryDetails(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BigStory bigStory = db.BigStories.Find(id);

            if (bigStory == null)
            {
                return(HttpNotFound());
            }
            return(View("~/Views/Admin/BigStory/Details.cshtml", bigStory));
        }
Exemple #6
0
        public void UpdateBigStory(BigStory bigStory)
        {
            if (bigStory.WhenLocked != null)
            {
                DateTime timeToFinish = bigStory.WhenLocked.Value.AddHours(bigStory.HoursToWrite);

                if (DateTime.Now.Ticks > timeToFinish.Ticks && bigStory.UnModeratedPost == null)
                {
                    bigStory.IsLocked = false;
                    bigStory.CurrentUser.isWritting = false;
                    bigStory.CurrentUser            = null;
                    bigStory.WhenLocked             = null;

                    db.SaveChanges();
                }
            }
        }
Exemple #7
0
        public ActionResult DenyLastPost(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BigStory bigStory = db.BigStories.Include("UnModeratedPost").Where(x => x.Id == id).FirstOrDefault();

            if (bigStory == null)
            {
                return(HttpNotFound());
            }
            bigStory.IsLocked        = false;
            bigStory.WhenLocked      = null;
            bigStory.CurrentUser     = null;
            bigStory.UnModeratedPost = null;

            db.SaveChanges();

            return(RedirectToAction("BigStoryModerate"));
        }
Exemple #8
0
        public ActionResult BigStoryCreate([Bind(Include = "Id,Title,Text,MaxNumberOfPosts,IsLocked,Deadline,HoursToWrite", Exclude = "StoryPhoto,PostText")] BigStory bigStory)
        {
            var currentUser = manager.FindById(User.Identity.GetUserId());

            byte[] imageData = null;
            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase poImgFile = Request.Files["StoryPhoto"];

                using (var binary = new BinaryReader(poImgFile.InputStream))
                {
                    imageData = binary.ReadBytes(poImgFile.ContentLength);
                }
            }

            var text = Request["PostText"];

            if (ModelState.IsValid)
            {
                bigStory.Posts = new List <PartBigStory>();
                bigStory.Posts.Add(new PartBigStory()
                {
                    User    = currentUser,
                    Created = DateTime.Now,
                    Text    = text
                });
                bigStory.Administrator   = currentUser;
                bigStory.UnModeratedPost = null;
                bigStory.Created         = DateTime.Now;
                bigStory.StoryPhoto      = imageData;
                db.BigStories.Add(bigStory);
                db.SaveChanges();
                return(RedirectToAction("BigStoryIndex"));
            }

            return(View(bigStory));
        }