Created
June 19, 2013 14:36
-
-
Save renatocantarino/5814813 to your computer and use it in GitHub Desktop.
Implementação do Service.svc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Globalization; | |
using System.Linq; | |
using System.ServiceModel; | |
using System.ServiceModel.Activation; | |
namespace appRest | |
{ | |
[AspNetCompatibilityRequirements | |
(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] | |
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] | |
public class Service1 : IRestService | |
{ | |
private readonly List<Pessoa> _listaPessoa = new List<Pessoa>(); | |
private int _personCount = 0; | |
public Pessoa CriarPessoa(Pessoa createPerson) | |
{ | |
createPerson.Id = (++_personCount).ToString(CultureInfo.InvariantCulture); | |
_listaPessoa.Add(createPerson); | |
return createPerson; | |
} | |
public List<Pessoa> ObterTodasPessoas() | |
{ | |
return _listaPessoa.ToList(); | |
} | |
public Pessoa ObterPessoaId(string id) | |
{ | |
return _listaPessoa.FirstOrDefault(e => e.Id.Equals(id)); | |
} | |
public Pessoa UpdatePessoa(string id, Pessoa updatePerson) | |
{ | |
Pessoa p = _listaPessoa.FirstOrDefault(e => e.Id.Equals(id)); | |
p.Name = updatePerson.Name; | |
p.Age = updatePerson.Age; | |
return p; | |
} | |
public void DeletarPessoa(string id) | |
{ | |
_listaPessoa.RemoveAll(e => e.Id.Equals(id)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment