public Voter UpdateVoter(int voterId, VoterDataRequest voterDataRequest, int adminId)
        {
            Voter voter = this.dBContext.voters.FirstOrDefault(linq => linq.VoterId == voterId && linq.IsDeleted == false);

            if (voter != null)
            {
                voter.VoterFirstName     = voterDataRequest.VoterFirstName;
                voter.VoterLastName      = voterDataRequest.VoterLastName;
                voter.VoterContactNUmber = voterDataRequest.VoterContactNUmber;
                voter.Modified           = DateTime.Now;
                var voterData = this.dBContext.voters.Attach(voter);
                voterData.State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                this.dBContext.SaveChanges();
                if (voterData.State != 0)
                {
                    var data = new AdminVoter
                    {
                        VoterId = voterId,
                        AdminId = adminId
                    };
                    this.dBContext.adminVoters.Add(data);
                    this.dBContext.SaveChanges();
                    voter.AdminResponses = Adminresponse(voterId);
                }

                return(voter);
            }
            return(null);
        }
Exemplo n.º 2
0
        public IActionResult UpdateVoter(int voterId, [FromBody] VoterDataRequest voterDataRequest)
        {
            try
            {
                var    user = HttpContext.User;
                string message;
                bool   status;
                if (user.HasClaim(linq => linq.Type == "AdminId"))
                {
                    int adminId = Convert.ToInt32(user.Claims.FirstOrDefault(linq => linq.Type == "AdminId").Value);
                    var data    = this.voterBusiness.UpdateVoter(voterId, voterDataRequest, adminId);
                    if (data != null)
                    {
                        status  = true;
                        message = "voter updated successfully";
                        return(this.Ok(new { status, message, data }));
                    }
                }

                status  = false;
                message = "voter doesn't exists";
                return(this.BadRequest(new { status, message }));
            }
            catch (Exception e)
            {
                return(this.BadRequest(e.Message));
            }
        }
Exemplo n.º 3
0
 public Voter UpdateVoter(int voterId, VoterDataRequest voterDataRequest, int adminId)
 {
     if (voterId != 0 && voterDataRequest != null && adminId != 0)
     {
         return(this.voterRepository.UpdateVoter(voterId, voterDataRequest, adminId));
     }
     return(null);
 }