コード例 #1
0
ファイル: SectionController.cs プロジェクト: iamjz/Pepperjack
        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();
        }
コード例 #2
0
ファイル: SectionHelper.cs プロジェクト: iamjz/Pepperjack
        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;
        }
コード例 #3
0
ファイル: SectionHelper.cs プロジェクト: iamjz/Pepperjack
        public static bool UpdateSection(SectionsVM submission)
        {
            //make sure storyID and sectionID already exists.
            //make sure sequence is current.

            return false;
        }
コード例 #4
0
ファイル: SectionHelper.cs プロジェクト: iamjz/Pepperjack
        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;
        }