示例#1
0
        public async Task <IHttpActionResult> UpdateBallot(BallotModel ballot)
        {
            if (ballot == null)
            {
                return(BadRequest("Please provide valid inputs!"));
            }

            if (ballot.ID == 0)
            {
                return(BadRequest("Please provide valid ballot ID!"));
            }

            if (string.IsNullOrEmpty(ballot.Location))
            {
                return(BadRequest("Please provide valid location!"));
            }

            if (await AuthService.ValidateUserAndToken(ballot.Token, ballot.UserID, ballot.Email, ballot.Location))
            {
                if (await BallotService.BallotExists(ballot))
                {
                    if (await BallotService.UpdateBallot(ballot))
                    {
                        return(Ok("Ballot Updated Successfully!"));
                    }
                    else
                    {
                        return(BadRequest("Failed To Update Ballot!"));
                    }
                }
                else
                {
                    return(BadRequest("No Such Ballot Exists!"));
                }
            }
            else
            {
                return(Unauthorized());
            }
        }
示例#2
0
        public async Task <IHttpActionResult> AddNewBallot(BallotModel ballot)
        {
            if (ballot == null)
            {
                return(BadRequest("Please provide valid inputs!"));
            }

            if (ballot.CandidateID == 0)
            {
                return(BadRequest("Please provide valid candidate ID!"));
            }

            if (string.IsNullOrEmpty(ballot.Location))
            {
                return(BadRequest("Please provide valid location!"));
            }

            if (await AuthService.ValidateUserAndToken(ballot.Token, ballot.UserID, ballot.Email, ballot.Location))
            {
                if (await BallotService.BallotExists(ballot))
                {
                    return(BadRequest("Ballot Already Exists"));
                }
                else
                {
                    if (await BallotService.AddNewBallot(ballot))
                    {
                        return(Ok("Ballot Added Successfully!"));
                    }
                    else
                    {
                        return(BadRequest("Ballot Adding Failed!"));
                    }
                }
            }
            else
            {
                return(Unauthorized());
            }
        }