/// <returns>A MemoryStream of the newly generated image file.</returns> public async Task <MemoryStream> FromEntryResponse(EntryResponse entry, string?playerCountryCode, int width = 1100) { string baseFlagPath = Path.Combine(AppContext.BaseDirectory, "Data", "Flags"); string flagPath = Path.Combine(baseFlagPath, $"{playerCountryCode}.png"); if (string.IsNullOrEmpty(playerCountryCode) || !File.Exists(flagPath)) { flagPath = Path.Combine(baseFlagPath, "00.png"); } if (OperatingSystem.IsWindows()) { flagPath = "file:///" + flagPath; } string ddinfoStyleHtml = await File.ReadAllTextAsync(Path.Combine(AppContext.BaseDirectory, "Data", "DdinfoStyle.txt")); string formattedHtml = string.Format( ddinfoStyleHtml, entry.Rank, flagPath, HttpUtility.HtmlEncode(entry.Username), $"{entry.Time / 10000d:0.0000}"); return(await FromHtml(formattedHtml, width)); }
public async Task <(bool Success, string Message)> RegisterUser(uint lbId, SocketGuildUser user) { try { uint[] playerRequest = { lbId }; EntryResponse lbPlayer = (await _webService.GetLbPlayers(playerRequest))[0]; DdUser newDdUser = new(user.Id, lbPlayer.Id); using IServiceScope scope = _scopeFactory.CreateScope(); await using DbService dbContext = scope.ServiceProvider.GetRequiredService <DbService>(); await dbContext.AddAsync(newDdUser); await dbContext.SaveChangesAsync(); return(true, string.Empty); } catch (Exception ex) { return(ex switch { CustomException => (false, ex.Message), HttpRequestException => (false, "DD servers are most likely down."), IOException => (false, "IO error."), _ => (false, "No reason specified."), });
public async Task <ActionResult <EntryResponse> > Get([FromQuery] int id) { try { IEnumerable <EntryDto> expenses = await UnitOfWork.ExpenseRepository.GetByInboxIdAsync(id); IEnumerable <EntryDto> payments = await UnitOfWork.PaymentRepository.GetByInboxIdAsync(id); IEnumerable <EntryDto> entries = expenses.Union(payments); EntryResponse entryResponse = new EntryResponse { Entries = entries, Expenses = entries.Where(x => x.ExpenseId.HasValue && !x.PaymentId.HasValue) .Sum(x => x.TotalAmount), Payments = entries.Where(x => x.PaymentId.HasValue && !x.ExpenseId.HasValue) .Sum(x => x.TotalAmount) }; return(Ok(entryResponse)); } catch (Exception ex) { return(InternalServerError(ex.InnerExceptionMessage())); } }
//works to populate public IActionResult Edit(int movieId) { EntryResponse movie = _context.Entries.Where(m => m.MovieId == movieId).FirstOrDefault(); ViewBag.EntryResponse = movie; return(View("Edit", ViewBag.EntryResponse)); }
//deleting from the list public IActionResult Delete(string title) { EntryResponse movie = _context.Entries.Where(m => m.Title == title).FirstOrDefault(); _context.Entries.Remove(movie); _context.SaveChanges(); //EntryResponse entry = TempStorage.AllMovies.Where(e => e.Title == title).FirstOrDefault(); //TempStorage.Delete(entry); return(RedirectToAction("MovieList")); }
private IEnumerator RequestEntry() { UnityWebRequest www = UnityWebRequest.Get("http://18.191.101.1:8080/guestbook/getRandomGuestbookMessage"); yield return(www.SendWebRequest()); EntryResponse response = JsonUtility.FromJson <EntryResponse>(www.downloadHandler.text); ShowFireworkMessage(response.name, response.message); }
public IActionResult ResForm(EntryResponse appResponse) { if (ModelState.IsValid) { TempStorage.AddEntry(appResponse); return(View("Confirmation", appResponse)); } else { return(View()); } }
//add a movie to the list public IActionResult MovieForm(EntryResponse appResponse) { if (ModelState.IsValid) { _context.Entries.Add(appResponse); _context.SaveChanges(); //TempStorage.Create(appResponse); return(View("Confirmation", appResponse)); } else { return(View()); } }
public static void queryEntry(Action <EntryResponse> callBack) { string route = "gate.gateHandler.queryEntry"; JsonObject param = new JsonObject(); ServiceGate.getInstance().request(route, param, ((JsonObject obj) => { // Debug.Log("obj = " + obj); EntryResponse model = new EntryResponse(obj); if (callBack != null) { callBack(model); } ServiceGate.disconnect(); })); }
private static Dictionary <string, AttributeValue> Map(EntryResponse entry) { return(new Dictionary <string, AttributeValue> { { Keys.Id, new AttributeValue { S = entry.Id } }, { Keys.User, new AttributeValue { S = entry.User } }, { Keys.Text, new AttributeValue { S = entry.Text } }, }); }
private async Task <object> Save(string user, string text) { var entry = new EntryResponse { Id = Guid.NewGuid().ToString("N"), User = user, Text = text }; await _dynamo.PutItemAsync(new PutItemRequest { TableName = _tableName, Item = Map(entry) }); return(entry); }
public void Mapping_SpecialRate_ToEntryResponse_IsCorrect() { //arrange var specialRate = new SpecialRate { TotalPrice = 10, Name = "Test Rate Name", Type = "Test Rate Type" }; var entryRequest = BuildEntryRequest(DateTime.Now.AddHours(-1).ToString(), DateTime.Now.ToString()); //act var result = EntryResponse.FromSpecialRate(specialRate, entryRequest); //assert Assert.AreEqual(specialRate.TotalPrice, result.Amount, "Amount not match"); Assert.AreEqual(specialRate.Type, result.RateType, "Rate Type not match"); Assert.AreEqual(specialRate.Name, result.RateName, "Rate Name not match"); Assert.AreEqual(entryRequest.RegistrationNo, result.RegistrationNo, "Registration No not match"); Assert.AreEqual(entryRequest.EntryTime, result.EntryTime, "Entry Time not match"); Assert.AreEqual(entryRequest.ExitTime, result.ExitTime, "Exit Time not match"); }
private static IEntryResponse CalculateWeekdayParkingFee(IEntryRequest request) { var daysDifference = GetDaysDifference(request.EntryTimeLocal, request.ExitTimeLocal); if (daysDifference < 2) { var specialRates = JsonConvert.DeserializeObject <List <SpecialRate> >(Resources.specialrates).Where(r => !r.Weekend); var applicableSpecialRate = specialRates.SingleOrDefault(r => request.EntryTimeLocal.TimeOfDay >= TimeSpan.Parse(r.EntryPeriodStart) && request.EntryTimeLocal.TimeOfDay <= TimeSpan.Parse(r.EntryPeriodEnd) && request.ExitTimeLocal.TimeOfDay >= TimeSpan.Parse(r.ExitPeriodStart) && request.ExitTimeLocal.TimeOfDay <= TimeSpan.Parse(r.ExitPeriodEnd)); if (applicableSpecialRate != null) { return(EntryResponse.FromSpecialRate(applicableSpecialRate, request)); } } // Standard Rates StandardRate applicableStandardRate; var standardRates = JsonConvert.DeserializeObject <List <StandardRate> >(Resources.standardrates); if (daysDifference == 0) { applicableStandardRate = standardRates.SingleOrDefault(r => request.ExitTimeLocal.TimeOfDay.Subtract(request.EntryTimeLocal.TimeOfDay).TotalMinutes > r.MinimumHours * 60 && request.ExitTimeLocal.TimeOfDay.Subtract(request.EntryTimeLocal.TimeOfDay).TotalMinutes <= r.MaximumHours * 60); } else { applicableStandardRate = standardRates.OrderByDescending(r => r.MaximumHours).FirstOrDefault(); applicableStandardRate.TotalPrice = applicableStandardRate.TotalPrice * daysDifference; } return(EntryResponse.FromStandardRate(applicableStandardRate, request)); }
public IActionResult Edit2(EntryResponse entry) { _context.Entries.Update(entry); _context.SaveChanges(); return(RedirectToAction("MovieList")); }
/// <summary> /// Determines whether the specified <see cref="EntryResponse"/> is /// equal to the current <see cref="EntryResponse"/>. /// </summary> /// <param name="other"> /// The <see cref="EntryResponse"/> to compare with the current /// <see cref="EntryResponse"/>. /// </param> /// <returns> /// <c>true</c> if the specified <see cref="EntryResponse"/> is /// equal to the current <see cref="EntryResponse"/>; otherwise, /// <c>false</c>. /// </returns> private bool Equals(EntryResponse other) { return(this.Status == other.Status && object.Equals(this.Request, other.Request)); }
private static IEntryResponse CalculateWeekendParkingFee(IEntryRequest request) { var weekendRate = JsonConvert.DeserializeObject <List <SpecialRate> >(Resources.specialrates).Single(r => r.Weekend); return(EntryResponse.FromSpecialRate(weekendRate, request)); }