Ejemplo n.º 1
0
        public ActionResult WriteSection(SectionsVM submission)
        {
            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();
        }
Ejemplo n.º 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.Upvotes = section.Upvotes;
                        sectionObj.Author = section.Author;
                        sectionObj.Downvotes = section.Downvotes;
                        sectionObj.WrittenDate = section.WrittenDate;
                        sectionObj.StoryID = section.StoryID;

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

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

            return false;
        }
Ejemplo n.º 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;
        }