コード例 #1
0
ファイル: ProvisionController.cs プロジェクト: cyehia/Politiq
 //
 // GET: /Provision/Create
 public ActionResult Create(int bill)
 {
     this.legislation = db.Legislations.Find(bill);
     ViewBag.BillName = this.legislation.LongTitle;
     ViewBag.BillStyle = LegislationManager.GenerateStyle(this.legislation);
     ViewBag.ArticleNumber = (this.legislation.Provisions.Count + 1).ToString();
     TempData["Bill"] = this.legislation.LegislationID;
     return View();
 }
コード例 #2
0
ファイル: LegislationManager.cs プロジェクト: cyehia/Politiq
 public void IncludeShortTitle(Legislation legislation)
 {
     if (legislation.ShortTile.ToString().Length >= 5)
     {
         string shortTitle = "This Act may be cited as the <i>" + legislation.ShortTile.ToString() + "</i>.";
         var provision = new Provision
         {
             Article = Numbers.CountOrNull(legislation.Provisions) + 1,
             Proponent = legislation.Sponsor,
             Text = shortTitle,
             Enactment = new Enactment
             {
                 EnactingOrder = null,
                 EnactmentType = 1,
                 EnactingDate = DateTime.MaxValue
             }
         };
         legislation.Provisions.Add(provision);
         db.SaveChanges();
     }
 }
コード例 #3
0
ファイル: LegislationManager.cs プロジェクト: cyehia/Politiq
        public void NumberBill(Legislation legislation)
        {
            switch (legislation.BillType)
            {
            case 1:
                    var currentPublicBills = db.Legislations.Where(l => l.BillType == 1 & l.Parliament.Ending > DateTime.Now);

                    legislation.BillNumber = Numbers.CountOrNull(currentPublicBills) + 1;
                    break;
            case 2:
                    var currentPrivateBills = db.Legislations.Where(l => l.BillType == 2 & l.Parliament.Ending > DateTime.Now);

                    legislation.BillNumber = Numbers.CountOrNull(currentPrivateBills) + 201;
                    break;
            }
        }
コード例 #4
0
ファイル: LegislationManager.cs プロジェクト: cyehia/Politiq
 public static string GenerateStyle(Legislation legislation)
 {
     string style_letter = (legislation.OriginatingChamber == 2) ? "S" : "C";
     return style_letter + "-" + legislation.BillNumber.ToString();
 }
コード例 #5
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;
            }
        }
コード例 #6
0
 public Legislation ProcessAndValidate(Legislation instance, out List <Exception> exceptions, out bool shouldSuppressProcessing)
 {
     ProcessAndValidateCommon(instance, out exceptions, out shouldSuppressProcessing);
     return(instance);
 }
コード例 #7
0
ファイル: BillController.cs プロジェクト: cyehia/Politiq
 public ActionResult Edit(Legislation legislation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(legislation).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(legislation);
 }
コード例 #8
0
        /// <summary>
        /// Performs a JSON-to-Object conversion.
        /// </summary>
        /// <param name="reader">
        /// A JsonReader object.
        /// </param>
        /// <param name="objectType">
        /// The type of the object.
        /// </param>
        /// <param name="existingValue">
        /// The existing value.
        /// </param>
        /// <param name="serializer">
        /// A JsonSerializer object.
        /// </param>
        /// <returns>
        /// A converted object.
        /// </returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            const string ITEM_TYPE_KEY     = "ItemType";
            const string ARGUMENT_EXCEPTON = "Invalid Or Missing ItemType";

            ContentItem contentItem = null;
            ItemType    itemType    = ItemType.Unknown;

            JObject jObject = JObject.Load(reader);
            JToken  jToken  = null;

            if (jObject.TryGetValue(ITEM_TYPE_KEY, StringComparison.CurrentCultureIgnoreCase, out jToken) && jToken != null && Enum.TryParse(jToken.Value <string>(), true, out itemType))
            {
                switch (itemType)
                {
                case ItemType.Unknown:
                    throw new ArgumentException(ARGUMENT_EXCEPTON);

                case ItemType.Book:
                    contentItem = new Book();
                    break;

                case ItemType.Chapter:
                    contentItem = new Chapter();
                    break;

                case ItemType.Journal:
                    contentItem = new Journal();
                    break;

                case ItemType.Magazine:
                    contentItem = new Magazine();
                    break;

                case ItemType.Newspaper:
                    contentItem = new Newspaper();
                    break;

                case ItemType.Webpage:
                    contentItem = new Webpage();
                    break;

                case ItemType.Encyclopedia:
                    contentItem = new Encyclopedia();
                    break;

                case ItemType.Graphic:
                    contentItem = new Graphic();
                    break;

                case ItemType.AudioRecording:
                    contentItem = new AudioRecording();
                    break;

                case ItemType.VideoRecording:
                    contentItem = new VideoRecording();
                    break;

                case ItemType.Broadcast:
                    contentItem = new Broadcast();
                    break;

                case ItemType.PersonalCommunication:
                    contentItem = new PersonalCommunication();
                    break;

                case ItemType.Interview:
                    contentItem = new Interview();
                    break;

                case ItemType.Presentation:
                    contentItem = new Presentation();
                    break;

                case ItemType.Map:
                    contentItem = new Map();
                    break;

                case ItemType.Bill:
                    contentItem = new Bill();
                    break;

                case ItemType.Legislation:
                    contentItem = new Legislation();
                    break;

                case ItemType.LegalCase:
                    contentItem = new LegalCase();
                    break;

                case ItemType.Report:
                    contentItem = new Report();
                    break;

                case ItemType.ConferencePaper:
                    contentItem = new ConferencePaper();
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            else
            {
                throw new ArgumentException(ARGUMENT_EXCEPTON);
            }

            if (serializer != null)
            {
                serializer.Populate(jObject.CreateReader(), contentItem);
            }
            return(contentItem);
        }