public async Task <IActionResult> Edit(int id, [Bind("safetyRatingID,safetyRating")] SafetyRating safetyRating) { if (id != safetyRating.safetyRatingID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(safetyRating); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SafetyRatingExists(safetyRating.safetyRatingID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(safetyRating)); }
public async Task <IActionResult> Create([Bind("safetyRatingID,safetyRating")] SafetyRating safetyRating) { if (ModelState.IsValid) { _context.Add(safetyRating); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(safetyRating)); }
public void PostRandomImage() { if (Images.Count < 1) { PopulateImages(); } ImageResult result = Images[(int)(RNG.RandomUInt32() % Images.Count)]; Images.Remove(result); SaveCache(); SafetyRating maxRating = Config.Get(ConfigSection, "MaxRating", SafetyRating.Safe); if (result.FileHash.Trim().Length < 1 || result.FileExtension.Trim().Length < 1) { throw new BotException("Result was empty"); } Log.Add($"Hash: {result.FileHash}{result.FileExtension}"); byte[] image = new byte[0]; try { image = result.Download(); } catch (Exception ex) { throw new BotException(ex.Message, ex); } if (image.Length < 1) { throw new BotException("File was empty"); } string savePath = Config.Get($"Bot.{Name}", "SavePath", string.Empty).Trim(); if (savePath.Length > 0) { savePath = Path.Combine(savePath, result.FileHash + result.FileExtension); File.WriteAllBytes(savePath, image); Log.Add($"Saved file to {savePath}"); } if (result.Rating > maxRating) { throw new BotException($"Rating was too high: {result.Rating}"); } Post(image, result.PostUrl); }
// Post public bool CreateRating(RatingCreate model) { var entity = new SafetyRating() { HousingId = model.HousingId, //ApplicantId = model.ApplicantId, Rating = model.Rating, Posted = DateTime.Now }; using (var ctx = new ApplicationDbContext()) { entity.ApplicantUser = ctx.Users.Where(e => e.Id == _userId).First(); ctx.SafetyRatings.Add(entity); return(ctx.SaveChanges() == 1); } }
public DiscordEmbed GetLocationEmbed( List <string> foundHiddenLocations = null, string entranceId = null, int exploreCount = -1) { var builder = new DiscordEmbedBuilder() .WithTitle(DisplayName); var desc = new System.Text.StringBuilder(Description); // Hostility Colors switch (SafetyRating.ToLower()) { case "sanctuary": builder.WithColor(DiscordColor.Gold); break; case "friendly": builder.WithColor(DiscordColor.SpringGreen); break; case "neutral": builder.WithColor(DiscordColor.CornflowerBlue); break; case "caution": builder.WithColor(DiscordColor.Orange); break; case "dangerous": builder.WithColor(DiscordColor.IndianRed); break; case "hostile": builder.WithColor(DiscordColor.Red); break; default: builder.WithColor(DiscordColor.White); break; } // Buildings if (Buildings?.Count > 0) { builder.AddField("Buildings", string.Join(", ", Buildings.Select(b => b.Name))); } // Exits var exits = new List <string>(); if (LocationConnections.Keys.Count > 0) { // Always show all exits for the starting location if (exploreCount >= ExploresNeeded || Id == Realm.GetSetting <string>("startinglocation")) { exits.AddRange(LocationConnections.Keys); } else { exits.Add(LocationConnections.FirstOrDefault(l => l.Value.Equals(entranceId, System.StringComparison.OrdinalIgnoreCase)).Key); } } // Include hidden exits (if found) if (HiddenLocationConnections.Keys.Count > 0 && foundHiddenLocations != null) { var toInclude = HiddenLocationConnections .Where(l => foundHiddenLocations.Contains(l.Value)) .Select(l => l.Key); exits.AddRange(toInclude); } builder.AddField("Exits", string.Join(", ", exits)); // Location Inventory if (LocationInventory?.Count > 0) { var items = LocationInventory.Select(inv => $"{inv.DisplayName} (x{inv.Amount})"); builder.AddField("Items", string.Join(", ", items)); } builder.WithDescription(desc.ToString()); return(builder.Build()); }