public async Task <IHttpActionResult> Save([FromBody] VotingPlaceViewModel votingplace) { using (var context = new RedContext()) { var newVotingPlace = context.VotingPlaces.Add(new VotingPlace { Id = votingplace.VotingPlaceId, Name = votingplace.Name, CountryId = votingplace.CountryId, DepartmentId = votingplace.DepartmentId, CityId = votingplace.CityId, Code = votingplace.Code }); await context.SaveChangesAsync(); return(Ok(new VotingPlaceViewModel(newVotingPlace))); } }
public async Task <IHttpActionResult> Update([FromBody] VotingPlaceViewModel votingplace) { using (var context = new RedContext()) { var ExistVotingPlace = await context.VotingPlaces.FirstOrDefaultAsync(b => b.Id == votingplace.VotingPlaceId); if (ExistVotingPlace == null) { return(NotFound()); } ExistVotingPlace.Name = votingplace.Name; ExistVotingPlace.CountryId = votingplace.CountryId; ExistVotingPlace.DepartmentId = votingplace.DepartmentId; ExistVotingPlace.CityId = votingplace.CityId; ExistVotingPlace.Code = votingplace.Code; await context.SaveChangesAsync(); return(Ok(new VotingPlaceViewModel(ExistVotingPlace))); } }