Example #1
0
        public JsonResult SetRating(string penname, string title, int id, string comment, int rating)
        {
            try
            {
                int ratingValue = CanUserVote(id, rating);
                if (ratingValue > 0)
                {
                    return(Json(new
                    {
                        Success = false,
                        Message = "Sorry, you already voted " + ratingValue.ToString() + " star(s) for this post."
                    }));
                }

                BizInfo post = BizInfoRepository.SetBizInfoRating(id, rating);
                Vote    v    = VoteRepository.AddVote(0, id, title, penname, CurrentUserID, rating, CurrentUserIP,
                                                      comment, DateTime.Now, UserName, DateTime.Now, UserName, true);
                return(Json(new
                {
                    Success = true,
                    Message = "Your Vote for " + Math.Abs(ratingValue).ToString() + " star(s)  was cast successfully" //  , Result = new { Rating = post.AverageRating, Raters = post.Votes }
                }));
            }
            catch
            {
                return(Json(new
                {
                    Success = false,
                    Message = "your vote  was not casted successfully."
                }));
            }
        }
        public override void Handle(RegisterVoteCommand message)
        {
            var conference = conferenceLoader.LoadConference(message.SessionId);

            if (conference == null || !conference.CanVote())
            {
                return;
            }

            if (voteRepository.HasVotedFor(message.SessionId, message.CookieId))
            {
                return;
            }

            voteRepository.AddVote(new Vote
            {
                CookieId         = message.CookieId,
                IPAddress        = message.IPAddress,
                Referrer         = message.Referrer,
                ScreenResolution = message.ScreenResolution,
                SessionId        = message.SessionId,
                TimeRecorded     = message.TimeRecorded,
                UserAgent        = message.UserAgent,
                UserId           = message.UserId,
                WebSessionId     = message.WebSessionId,
                PositionInList   = message.PositionInList
            });
        }
        public async Task <IActionResult> ToVote([FromBody] CreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    await _voteRepository.AddVote(model);

                    scope.Complete();
                }
                catch (DbUpdateException)
                {
                    return(BadRequest());
                }
                catch (Exception)
                {
                    return(BadRequest());
                }

                return(Ok());
            }
        }
Example #4
0
        private void SaveVote(int movieId, int userId, bool like)
        {
            var vote = GetMovieVoteForUser(movieId, userId);

            if (vote == No.Vote)
            {
                var newVote = new Vote(userId, movieId);
                if (like)
                {
                    newVote.LikeMovie();
                }
                else
                {
                    newVote.HateMovie();
                }

                _voteRepository.AddVote(newVote);
            }
            else
            {
                if (like)
                {
                    vote.LikeMovie();
                }
                else
                {
                    vote.HateMovie();
                }
                _voteRepository.UpdateVote(vote);
            }

            var voteResult = GetMovieVotes(movieId);

            if (voteResult == No.Votes)
            {
                var newVoteResult = new VoteResult(movieId);
                if (like)
                {
                    newVoteResult.LikeMovie();
                }
                else
                {
                    newVoteResult.HateMovie();
                }
                _voteRepository.AddVoteResult(newVoteResult);
            }
            else
            {
                if (like)
                {
                    voteResult.LikeMovie();
                }
                else
                {
                    voteResult.HateMovie();
                }
                _voteRepository.UpdateVoteResult(voteResult);
            }
        }
Example #5
0
        /// <summary>
        /// Convert VoteViewModel to Vote and cast vote to the DB
        /// </summary>
        /// <param name="vote">VoteViewModel to be mapped and added</param>
        public async Task <VoteViewModel> CastVote(VoteViewModel vote)
        {
            var voteId = await _voteRepository.AddVote(VoteViewModel.ToDataModel(vote));

            Vote voteVM = _voteRepository.GetVote(voteId);

            return(VoteViewModel.ToViewModel(voteVM));
        }
Example #6
0
        public async Task <IActionResult> Vote(int linkId, bool voteType)
        {
            var link = await _linkRepository.GetLinkWithVotes(linkId);

            var user = await _userManager.GetUserAsync(User);

            try
            {
                if (voteType)
                {
                    if (link.Points == int.MaxValue)
                    {
                        _toastNotification.AddWarningToastMessage("Link has already maximum number of points");
                        return(RedirectToAction(nameof(Index)));
                    }

                    if (link.User == user)
                    {
                        _toastNotification.AddWarningToastMessage("You cannot vote for your links");
                        return(RedirectToAction(nameof(Index)));
                    }

                    if (link.Votes.FirstOrDefault(v => v.User == user) != null)
                    {
                        _toastNotification.AddWarningToastMessage("You already have voted for this link");
                        return(RedirectToAction(nameof(Index)));
                    }

                    link.Points += 1;
                    var vote = new Vote
                    {
                        Link  = link,
                        User  = user,
                        Voted = true
                    };

                    await _voteRepository.AddVote(vote);
                }
                else
                {
                    link.Points -= 1;
                    await _linkRepository.Edit(link);

                    var vote = link.Votes.First(v => v.User == user);

                    await _voteRepository.RemoveVote(vote.Id);
                }

                _toastNotification.AddSuccessToastMessage("Successfully voted");
                return(RedirectToAction(nameof(Index)));
            }
            catch (DbUpdateException)
            {
                _toastNotification.AddErrorToastMessage("Something went wrong");
                return(RedirectToAction(nameof(Index)));
            }
        }
        public ActionResult Add(AddVoteModel anAddVoteModel)
        {
            _voteRepository.AddVote(new Vote()
            {
                Antwort  = anAddVoteModel.Antwort,
                Id       = ObjectId.GenerateNewId(),
                PersonId = ObjectId.Parse(anAddVoteModel.PersonId),
                PollId   = ObjectId.Parse(anAddVoteModel.PollId)
            });

            return(NoContent());
        }
        public void CastUserVote(int memeId, bool updown)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return;
            }
            Vote vote = new Vote()
            {
                UserId = _userRepository.GetByUsername(User.Identity.Name).Id,
                MemeId = memeId,
                UpDown = updown
            };

            _repository.AddVote(vote);
        }
 /// <summary>
 /// It Add Vote to the candidate
 /// </summary>
 /// <param name="addVote">Candidate Id and Evmvote or postalvote</param>
 /// <returns>Add Vote Response Model</returns>
 public AddVoteResponseModel AddVote(AddVoteRequestModel addVote)
 {
     try
     {
         if (addVote == null || (addVote.EvmVote == addVote.PostalVote))
         {
             return(null);
         }
         else
         {
             return(_voteRepository.AddVote(addVote));
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Example #10
0
 public async Task <bool> GiveVote(Votes votes)
 {
     try
     {
         bool res = false;
         if (votes.Id == 0)
         {
             res = await _repository.AddVote(votes);
         }
         else
         {
             res = await _repository.UpdateVote(votes);
         }
         return(res);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public bool AddVote(Vote vote)
 {
     return(_voteRepository.AddVote(vote));
 }
Example #12
0
        public async Task <AddVoteResponse> Handle(AddVoteCommand command, CancellationToken cancellationToken)
        {
            if (!IsValid(command))
            {
                return(null);
            }

            var employee = await _employeeRepository.GetEmployeeById(command.EmployeeId);

            if (employee == null)
            {
                InvalidEmployee(_notification);
            }

            if (_notification.HasNotification())
            {
                return(null);
            }

            var tasks = await _taskRepository.GetTasksById(command.TaskId);

            if (tasks == null)
            {
                InvalidTask(_notification);
            }

            if (_notification.HasNotification())
            {
                return(null);
            }

            var alreadyVoted = await _voteRepository.ValidateVoteByEmployeeId(command.EmployeeId);

            if (alreadyVoted)
            {
                EmployeeAlreadyVoted(_notification);
            }

            if (_notification.HasNotification())
            {
                return(null);
            }

            var vote = new Vote();

            vote = vote.AddVote(command.EmployeeId, command.TaskId, command.Comment, _notification);

            if (_notification.HasNotification())
            {
                return(null);
            }

            using (var uow = _unitOfWorkManager.Begin())
            {
                await _voteRepository.AddVote(vote);

                uow.Complete();
            }

            return(VoteResponse(vote));
        }
Example #13
0
        public MutationObject(
            ILinkRepository linkRepository,
            IUserRepository userRepository,
            IVoteRepository voteRepository)
        {
            this.Name        = "Mutation";
            this.Description = "The mutation type, represents all updates we can make to our data.";

            this.FieldAsync <LinkType, Link>(
                "createLink",
                "Create a new link.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <LinkInputObject> >()
            {
                Name        = "link",
                Description = "The link you want to create.",
            }),
                resolve: context =>
            {
                var link = context.GetArgument <Link>("link");
                return(linkRepository.AddLink(link));
            });

            this.FieldAsync <LinkType, Link>(
                "deleteLink",
                "Delete an existent link.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> >()
            {
                Name        = "id",
                Description = "The id of the link to delete.",
            }),
                resolve: context => linkRepository.DeleteLink(context.GetArgument <int>("id")));

            this.FieldAsync <UserType, User>(
                "createUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <UserInputObject> > {
                Name = "user"
            }
                    ),
                resolve: context =>
            {
                var user = context.GetArgument <User>("user");
                return(userRepository.AddUser(user));
            });

            this.FieldAsync <SigninUserPayloadType, SigninUserPayload>(
                "signinUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <SigninUserInputObject> > {
                Name = "signinUser"
            }
                    ),
                resolve: context =>
            {
                var signinUser = context.GetArgument <SigninUser>("signinUser");
                return(userRepository.SigninUser(signinUser));
            });

            this.FieldAsync <VoteType, Vote>(
                "createVote",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "userId"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "linkId"
            }
                    ),
                resolve: context =>
            {
                int userId = context.GetArgument <int>("userId");
                int linkId = context.GetArgument <int>("linkId");
                return(voteRepository.AddVote(userId, linkId, context.CancellationToken));
            });
        }
Example #14
0
        public MobileLoginModel PostResult(HttpRequestMessage message)
        {
            try
            {
                var postText = message.Content.ReadAsStringAsync().Result;
                if (string.IsNullOrEmpty(postText))
                {
                    return(new MobileLoginModel {
                        Message = "No data synced."
                    });
                }

                var models = JsonConvert.DeserializeObject <List <MoiblePostResult> >(postText);
                //if (model.Module > 0)
                //{
                //    return new MobileLoginModel { Message = "Something is wrong with the provided data. Please try again later" };
                //}
                List <int> ints = new List <int>();
                foreach (var model in models)
                {
                    string[] codes = model.PersonCode.Split('/');
                    var      path  = "";
                    if (model.ProofImage.Length != 0)
                    {
                        var image = Utils.ConvertToImage(model.ProofImage);
                        path = Path.Combine(HttpContext.Current.Server.MapPath("~/Images/Proof/"), model.PersonCode.Replace('/', '_') + ".jpg");
                        image.Save(path);
                    }

                    var result_id = _resultRepository.AddResult(new Result
                    {
                        Module       = model.Module,
                        RegVotes     = model.RegVotes,
                        AccredVotes  = model.AccredVotes,
                        CastVotes    = model.CastVotes,
                        InvalidVotes = model.InvVotes,
                        ReportedBy   = model.ReportedBy,
                        ProofUrl     = path,
                        State        = int.Parse(codes[0]),
                        Lga          = int.Parse(codes[1]),
                        Ward         = int.Parse(codes[2]),
                        PollingUnit  = int.Parse(codes[3])
                    });
                    if (result_id > 0)
                    {
                        foreach (var m in model.Votes)
                        {
                            _voteRepository.AddVote(new Vote
                            {
                                ResultId = result_id,
                                PartyId  = m.Party,
                                Vote1    = m.Vote
                            });
                        }

                        _voteRepository.AddBytePhoto(new Photo {
                            ResultId = result_id,
                            Image    = model.ProofImage,
                            Reporter = model.ReportedBy
                        });
                    }
                    ints.Add(model.Id);
                }

                if (ints.Count > 0)
                {
                    return(new MobileLoginModel
                    {
                        Message = "Successfully Synced",
                        Result = ints
                    });
                }
                return(new MobileLoginModel {
                    Message = "synchronization failed."
                });
            }
            catch (Exception e)
            {
                return(new MobileLoginModel {
                    Message = "Synchronization failed due to internal server error."
                });
            }
        }