public Task Handle(GetPoems message, IMessageHandlerContext context) { try { using (var db = new LimeContext()) { Console.WriteLine("Start GetPoems"); var poems = db.Poems.ToList(); var response = new ResponseGetPoems { Poems = poems }; return(context.Reply(response)); } } catch (Exception e) { Console.WriteLine(e); return(context.Reply(new ResponseGetPoems { Error = e })); } finally { Console.WriteLine("End GetPoems"); } }
public Task Handle(GetPeoples message, IMessageHandlerContext context) { Console.WriteLine("Start GetPeoples"); try { using (var db = new LimeContext()) { var peoples = db.Peoples.ToList(); var response = new ResponseGetPeoples() { Peoples = peoples }; return(context.Reply(response)); } } catch (Exception e) { Console.WriteLine(e); var response = new ResponseGetPeoples() { Error = e }; return(context.Reply(response)); } finally { Console.WriteLine("End GetPeoples"); } }
public async Task Handle(GetInfo message, IMessageHandlerContext context) { try { Console.WriteLine("Start GetInfo"); using (var client = new HttpClient()) using (var db = new LimeContext()) { var response = await client.GetAsync("https://randomuser.me/api/"); var json = await response.Content.ReadAsStringAsync(); var userPeople = JsonConvert.DeserializeObject <UserPeople>(json).Results; if (userPeople.Count > 0) { var user = userPeople[0]; var people = new Data.Entity.People { Address = $"{user.Location.City} {user.Location.Street}", Email = user.Email, Gender = user.Gender, PictureMedium = user.Picture.Medium, LastName = user.Name.Last, FirstName = user.Name.First, }; db.Peoples.Add(people); db.SaveChanges(); response = await client.GetAsync("https://geek-jokes.sameerkumar.website/api"); json = await response.Content.ReadAsStringAsync(); people.Quote = json; db.Peoples.AddOrUpdate(people); db.SaveChanges(); var command = new GetPoem { PeopleId = people.Id }; await context.Publish(command).ConfigureAwait(false); } } } catch (Exception e) { Console.WriteLine(e); } finally { Console.WriteLine("End GetInfo"); } }
public async Task Handle(GetPoem message, IMessageHandlerContext context) { try { Console.WriteLine("Start GetPoem"); using (var client = new HttpClient()) using (var db = new LimeContext()) { var response = await client.GetAsync("https://www.poemist.com/api/v1/randompoems"); var json = await response.Content.ReadAsStringAsync(); var poems = JsonConvert.DeserializeObject <List <PoemsModel> >(json); if (poems.Count > 0) { var poem = new Poem { Author = poems[0].Poet.Name, Content = poems[0].Content, Title = poems[0].Title, Url = poems[0].Url, People_Id = message.PeopleId }; var sentences = poems[0].Content.Split('.'); var number = 0; double distance = 0; while (number != sentences.Length - 1 && !string.IsNullOrEmpty(sentences[number + 1])) { distance = distance + JaroWinkler.RateSimilarity(sentences[number], sentences[++number]); } distance = distance != 0 && number != 0 ? distance / number : 0; poem.Distance = distance; db.Poems.Add(poem); await db.SaveChangesAsync(); } } } catch (Exception e) { Console.WriteLine(e); } finally { Console.WriteLine("End GetPoem"); } }
public AccountRepository( LimeContext context, UserManager <IdentityUser> userManager, SignInManager <IdentityUser> signInManager, RoleManager <IdentityRole> roleManager, IdentityDbContext identityDbContext ) { this.userManager = userManager; this.signInManager = signInManager; this.roleManager = roleManager; this.identityDbContext = identityDbContext; this.context = context; }
public Repository(LimeContext context, UserManager <IdentityUser> userManager) { this.context = context; this.userManager = userManager; }