예제 #1
0
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            IVoteService service = testServer.Host.Services.GetService(typeof(IVoteService)) as IVoteService;
            var          model   = new ApiVoteServerRequestModel();

            model.SetProperties(2, DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, 1);
            CreateResponse <ApiVoteServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.VoteDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiVoteServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
예제 #2
0
        //public CreateVoteModel Handle(CreateVoteModel model)
        //{

        //    var result = _voteService.Create(new CreateVoteInputModel
        //    {
        //        Result = model.Result,
        //        UID = model.Uid,
        //    });

        //    return model;
        //}

        public ModelHandlerResult Handle(CreateVoteModel model)
        {
            var result = _voteService.Create(new CreateVoteInputModel
            {
                Result = model.Result,
                UID    = model.Uid,
            });

            //var context = GlobalHost.ConnectionManager.GetHubContext<Hubs.VoterHub>();
            //context.Clients.All.broadcastMessage(model.Uid.ToString(), model.Result.HasValue ? (model.Result.Value ? "Yes" : "No") : "Don't know");

            return(new ModelHandlerResult()
            {
                Message = result.IsSuccess ? Resources.Dictionary.Global_Edit_SuccessNotification : null,
                Data = model,
                Exception = result.Exception,
                ValidationMessages = result.ValidationMessages
            });
        }
예제 #3
0
 public IActionResult Create([FromBody] CreateVoteModel model)
 {
     try
     {
         var vote = _voteService.Create(model.OptionId, int.Parse(User.Identity.Name));
         // var topicResource = _mapper.Map<TopicResourceModel>(topic);
         if (vote != null)
         {
             return(Ok(new { message = "Voted" }));
         }
         else
         {
             return(BadRequest(new { message = "Sorry, you've already voted on this topic" }));
         }
     }
     catch (AppException ex)
     {
         return(BadRequest(new { message = ex.Message }));
     }
 }
        private async Task <Guid> AddVote(ImageDto image, Guid userId, VoteType type)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                if (type == VoteType.Like)
                {
                    image.LikesCount++;
                }
                else
                {
                    image.DislikesCount++;
                }
                await imageService.Update(image);

                var guid = voteService.Create(new VoteDto {
                    ImageId = image.Id, UserId = userId, Type = type
                });
                await uow.Commit();

                return(guid);
            }
        }
예제 #5
0
 public bool Create([FromBody] int candidateId)
 {
     return(_voteService.Create(candidateId) != null);
 }