コード例 #1
0
        public async Task <IActionResult> CreatePetition(CreatePetitionModel model)
        {
            var petition = new PetitionEntity()
            {
                Id          = Guid.NewGuid(),
                Title       = model.Title,
                Description = model.Description,
                Category    = model.Category,
                Status      = GovStatus.UNNOTICED,
                DownVotes   = 0,
                UpVotes     = 0
            };

            await _dbContext.Petitions.AddAsync(petition);

            await _dbContext.SaveChangesAsync();

            var createdUri = Url.Action("GetPetition", new
            {
                id = petition.Id
            });

            return(Created(createdUri, petition.Id));
        }
コード例 #2
0
        public async Task <IActionResult> AddComment([FromRoute] Guid id, [FromBody] AddCommentModel model)
        {
            var comment = new PetitionCommentEntity()
            {
                Id               = Guid.NewGuid(),
                Comment          = model.Comment,
                PetitionEntityId = id,
                TimeStamp        = DateTime.Now
            };

            await _dbContext.Comments.AddAsync(comment);

            await _dbContext.SaveChangesAsync();

            return(Ok());
        }