public void CreatePet([FromBody] Pet pet) { var context = GeoPetContext.GetInstance(); context.Pets.Add(pet); context.SaveChanges(); }
public void Create([FromBody] Owner owner) { var context = GeoPetContext.GetInstance(); context.Owners.Add((owner)); context.SaveChanges(); }
public static void Main(string[] args) { var context = GeoPetContext.GetInstance(); GeoPetContextSeeder.SeedTestData(context); context.SaveChanges(); CreateWebHostBuilder(args).Build().Run(); }
public void Create([FromBody] LostPet request) { var context = GeoPetContext.GetInstance(); var lostPet = context.Pets.FirstOrDefault <Pet>(x => x.Name.Equals(request.Name) && x.Email.Equals(request.Email)); if (lostPet != null) { lostPet.IsLost = false; context.LostPets.Remove(request); } context.SaveChanges(); TwitterHandler.GetInstance().TweetFoundPet(request); }
public void Create([FromBody] LostPet request) { var context = GeoPetContext.GetInstance(); context.LostPets.Add(request); var pet = context.Pets.FirstOrDefault(p => p.Name.Equals(request.Name) && p.Email.Equals(request.Email)); if (pet != null) { pet.IsLost = true; } context.SaveChanges(); // Tweet lost pet TwitterHandler.GetInstance().TweetLostPet(request); }
public void TweetFoundPet(LostPet lostPet) { var context = GeoPetContext.GetInstance(); var pet = context.Pets.Where(x => x.Email.Equals(lostPet.Email) && x.Name.Equals(lostPet.Name)).SingleOrDefault(); byte[] imgBytes; using (WebClient client = new WebClient()) { imgBytes = client.DownloadData(new Uri(pet.ImageUrl)); } var publishParams = new PublishTweetOptionalParameters(); publishParams.MediaBinaries = new List <byte[]> { imgBytes }; Tweet.PublishTweet($"Encontraron a {pet.Name}!!! :)", publishParams); }
public void TweetLostPet(LostPet lostPet) { var context = GeoPetContext.GetInstance(); var pet = context.Pets.Where(x => x.Email.Equals(lostPet.Email) && x.Name.Equals(lostPet.Name)).SingleOrDefault(); byte[] imgBytes; using (WebClient client = new WebClient()) { imgBytes = client.DownloadData(new Uri(pet.ImageUrl)); } //Generate any parameters to be included var publishParams = new PublishTweetOptionalParameters(); publishParams.MediaBinaries = new List <byte[]> { imgBytes }; Tweet.PublishTweet($"Se perdiĆ³ {pet.Name} :(, ayudanos a encontrarl@", publishParams); }
public Owner Get(string email) { var context = GeoPetContext.GetInstance(); return(context.Owners.FirstOrDefault(x => x.Mail.Equals(email))); }
public List <LostPet> GetLostPets() { var context = GeoPetContext.GetInstance(); return(context.LostPets.ToList()); }
public Pet GetPetsByEmailAndName(string email, string name) { var context = GeoPetContext.GetInstance(); return(context.Pets.Where(pet => pet.Email.Equals(email) && pet.Name.Equals(name)).SingleOrDefault()); }
public List <Pet> GetPets(string email) { var context = GeoPetContext.GetInstance(); return(context.Pets.Where(x => x.Email.Equals(email)).ToList()); }