Exemplo n.º 1
0
        public VotersDTO UpdateVoter(VotersDTO givenVoter)
        {
            Voter voterToUpdate = DB.Voters.Where(p => p.VoterID == givenVoter.id).SingleOrDefault();

            if (voterToUpdate == null)
            {
                return(null);
            }
            voterToUpdate.FirstName             = givenVoter.firstName;
            voterToUpdate.LastName              = givenVoter.lastName;
            voterToUpdate.City                  = givenVoter.city;
            voterToUpdate.SocialNumber          = givenVoter.socialNumber;
            voterToUpdate.SocialNumberIssueDate = givenVoter.socialNumberIssueDate;
            voterToUpdate.Email                 = givenVoter.email;
            voterToUpdate.Phone                 = givenVoter.phone;
            voterToUpdate.Gender                = givenVoter.gender;

            if (givenVoter.votedTo != null)
            {
                voterToUpdate.PartyID = givenVoter.votedTo.id;
            }
            else
            {
                voterToUpdate.PartyID = null;
            }


            DB.SaveChanges();
            return(givenVoter);
        }
Exemplo n.º 2
0
 public HttpResponseMessage AddVoters(VotersDTO givenVoter)
 {
     try
     {
         using (logic)
         {
             VotersDTO addedVoter = logic.addVoter(givenVoter);
             return(Request.CreateResponse(HttpStatusCode.Created, addedVoter));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
     }
 }
Exemplo n.º 3
0
 public HttpResponseMessage UpdateVoters(VotersDTO givenVoter, int id)
 {
     try
     {
         using (logic)
         {
             givenVoter.id = id;
             VotersDTO updatedVoter = logic.UpdateVoter(givenVoter);
             if (updatedVoter == null)
             {
                 return(Request.CreateResponse(HttpStatusCode.NotFound));
             }
             return(Request.CreateResponse(HttpStatusCode.OK, updatedVoter));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMeesage(ex)));
     }
 }
Exemplo n.º 4
0
        public VotersDTO addVoter(VotersDTO givenVoter)
        {
            Voter voterToAdd = new Voter
            {
                FirstName             = givenVoter.firstName,
                LastName              = givenVoter.lastName,
                City                  = givenVoter.city,
                SocialNumber          = givenVoter.socialNumber,
                SocialNumberIssueDate = givenVoter.socialNumberIssueDate,
                Email                 = givenVoter.email,
                Phone                 = givenVoter.phone,
                Gender                = givenVoter.gender,
                PartyID               = null
            };

            DB.Voters.Add(voterToAdd);
            DB.SaveChanges();
            givenVoter.id = voterToAdd.VoterID;
            return(givenVoter);
        }