コード例 #1
0
ファイル: BillController.cs プロジェクト: cyehia/Politiq
        public ActionResult Create(NewLegislationView legislation)
        {
            legislation.OriginatingChamber = 1;    // House of Commons by default, hard-coded. Change if Senate included.

            if (ModelState.IsValid)
            {
                LegislationManager billManager = new LegislationManager();
                int savedLegislation = billManager.Save(legislation);
                if (savedLegislation == 0)
                {
                    ModelState.AddModelError("", "Parliament is not in session.");
                }
                else
                {
                    return RedirectToAction("Create", "Provision", new { bill = savedLegislation });
                }
            }
            return View(legislation);
        }
コード例 #2
0
ファイル: LegislationManager.cs プロジェクト: cyehia/Politiq
        public int Save(NewLegislationView legislation)
        {
            var currentSession = db.CommonsSessions.Where(p => p.Ending > DateTime.Now);

            if (currentSession.Any())
            {
                Legislation newLegislation = new Legislation();

                // Simple transfers
                newLegislation.ShortTile = legislation.ShortTile;
                newLegislation.LongTitle = legislation.LongTitle;
                newLegislation.BillType = legislation.BillType;
                newLegislation.OriginatingChamber = legislation.OriginatingChamber;
                newLegislation.Preamble = legislation.Preamble;

                // More complicated properties
                this.NumberBill(newLegislation); // Provides bill number
                newLegislation.Parliament = currentSession.First();
                newLegislation.Sponsor = db.Members.Single(m => m.Username == HttpContext.Current.User.Identity.Name);

                // Initialize its stage
                newLegislation.Stage = new Stage
                {
                    Reading = 0,
                    LastMovement = DateTime.Now
                };

                // Initialize new list of provisions
                newLegislation.Provisions = new Collection<Provision>();

                // And save
                db.Legislations.Add(newLegislation);
                db.SaveChanges();

                // Check for Short titles
                this.IncludeShortTitle(newLegislation);

                // return the saved legislation
                return newLegislation.LegislationID;
            }
            else
            {
                return 0;
            }
        }