Example #1
0
        public ActionResult WriteSection(SectionsVM submission)
        {
            if (!User.Identity.IsAuthenticated)
            {
                User.Identity.Name.ToString();
                return View();
            }
            else
            {
                if (ModelState.IsValid
                    && Session["StoryID"].ToString() != null
                    && Session["CurrentSeq"].ToString() != null)
                {
                    var StoryID = Session["StoryID"];
                    int formattedID = 0;
                    bool isIdNumeric = int.TryParse(StoryID.ToString(), out formattedID);

                    //check seq number
                    var SeqNumber = Session["CurrentSeq"];
                    int formattedSeqNumber = 0;
                    bool isSeqNumNumeric = int.TryParse(SeqNumber.ToString(), out formattedSeqNumber);

                    if (isIdNumeric && isSeqNumNumeric)
                    {
                        submission.StoryID = (int)StoryID;
                        submission.SequenceNumber = (int)SeqNumber;
                        Helpers.SectionHelper.InsertSection(submission);

                        IEnumerable<SectionsVM> s = Helpers.SectionHelper.ShowCurrentSections(submission.StoryID);
                        return PartialView("_CurrentSections", s);
                    }

                    return View();
                    //if insert failed, redirect to failed submission partial view
                }

                return View();
            }
        }
Example #2
0
        public static SectionsVM getSectionFromId(int id)
        {
            try
            {
                using (var db = new WriteEntities())
                {
                    var section = db.Sections.Find(id);

                    if (section != null)
                    {
                        SectionsVM sectionObj = new SectionsVM();

                        sectionObj.SectionID = section.SectionID;
                        sectionObj.SectionContent = section.SectionContent;
                        sectionObj.SequenceNumber = section.SequenceNumber;
                        sectionObj.Author = section.Author;
                        sectionObj.Votes = calculateTotUpvotes(section.SectionID);
                        sectionObj.WrittenDate = section.WrittenDate;
                        sectionObj.StoryID = section.StoryID;

                        return sectionObj;
                    }
                }
            }
            catch (Exception ex)
            {
                //TODO: Add error handling
                return null;
            }

            return null;
        }
Example #3
0
        public static bool UpdateSection(SectionsVM submission)
        {
            //make sure storyID and sectionID already exists.
            //make sure sequence is current.

            return false;
        }
Example #4
0
        public static bool InsertSection(SectionsVM submission)
        {
            if (IsValidStory(submission.StoryID))
            {
                if (GetCurrentSeq(submission.StoryID) == submission.SequenceNumber)
                {
                    //map submission back to data model: Section
                    Section dataModel = new Section();

                    dataModel.SectionContent = submission.SectionContent;
                    dataModel.SequenceNumber = submission.SequenceNumber;
                    dataModel.StoryID = submission.StoryID;

                    //default properties upon submission:
                    dataModel.IsCommitted = false;
                    dataModel.WrittenDate = DateTime.Now;
                    //dataModel.Downvotes = 0;
                    //dataModel.Upvotes = 0;
                    dataModel.Author = "Frontend User";

                    try
                    {
                        using (var db = new WriteEntities())
                        {
                            db.Sections.Add(dataModel);
                            db.SaveChanges();

                            return true;
                        }
                    }
                    catch (Exception ex)
                    {
                        return false;
                    }
                }
            }

            return false;
        }