Example #1
0
        public static void Initialize(TodoContext context)
        {
            // Look for any students.
            if (context.TodoItems.Any())
            {
                return;   // DB has been seeded
            }

            var todoitems = new TodoItem[]
            {
                new TodoItem {
                    Id = 1223434, Name = "Alexandra", IsComplete = true
                },
                new TodoItem {
                    Id = 3456789854, Name = "Bob", IsComplete = false
                },
            };

            foreach (TodoItem t in todoitems)
            {
                context.TodoItems.Add(t);
            }


            // Look for any students.
            if (context.VoteTopics.Any())
            {
                return;   // DB has been seeded
            }

            var votetopics = new VoteTopic[]
            {
                new VoteTopic {
                    Id                = 32342381,
                    Category          = "construction",
                    VoteTopicFullText = "This is a sample topic to be voted upon",
                    Seconded          = true,
                    BODseconder       = "tbd",
                    Proposer          = "khalil",
                    VotingIsComplete  = false,
                    ProposalApproved  = false
                },
                new VoteTopic {
                    Id                = 3234238,
                    Category          = "revenue",
                    VoteTopicFullText = "This is another sample topic to be voted upon",
                    Seconded          = true,
                    BODseconder       = "tbd",
                    Proposer          = "marsha",
                    VotingIsComplete  = false,
                    ProposalApproved  = false
                }
            };

            foreach (VoteTopic t in votetopics)
            {
                context.VoteTopics.Add(t);
            }
            context.SaveChanges();
        }
        public IActionResult Update(long id, [FromBody] VoteTopic item)
        {
            if (item == null || item.Id != id)
            {
                return(BadRequest());
            }

            var VoteTopic = _context.VoteTopics.FirstOrDefault(t => t.Id == id);

            if (VoteTopic == null)
            {
                return(NotFound());
            }

            VoteTopic.Category          = item.Category;
            VoteTopic.VoteTopicFullText = item.VoteTopicFullText;
            VoteTopic.Seconded          = item.Seconded;
            VoteTopic.BODseconder       = item.BODseconder;
            VoteTopic.Proposer          = item.Proposer;
            VoteTopic.VotingIsComplete  = item.VotingIsComplete;
            VoteTopic.ProposalApproved  = item.ProposalApproved;

            _context.VoteTopics.Update(VoteTopic);
            _context.SaveChanges();
            return(new NoContentResult());
        }
        public VoteTopicsController(TodoContext context)
        {
            _context = context;

            if (_context.VoteTopics.Count() == 0)
            {
                var votetopics = new VoteTopic[]
                {
                    new VoteTopic {
                        Category          = "construction",
                        VoteTopicFullText = "This is a sample topic to be voted upon",
                        Seconded          = true,
                        BODseconder       = "tbd",
                        Proposer          = "khalil",
                        VotingIsComplete  = false,
                        ProposalApproved  = false
                    },
                    new VoteTopic {
                        Category          = "revenues",
                        VoteTopicFullText = "This is another sample topic to be voted upon",
                        Seconded          = true,
                        BODseconder       = "tbd",
                        Proposer          = "marsha",
                        VotingIsComplete  = false,
                        ProposalApproved  = false
                    }
                };
                foreach (VoteTopic t in votetopics)
                {
                    _context.VoteTopics.Add(t);
                }

                _context.SaveChanges();
            }
        }
        public IActionResult Create([FromBody] VoteTopic item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            _context.VoteTopics.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetVote", new { id = item.Id }, item));
        }