public JsonResult GetGuides(int?bossId) { var context = new DatabaseModels.Saren_BotContext(); if (bossId == 0) { bossId = null; } var list = (from g in context.Guides where g.Status == "Active" && g.BossId == bossId orderby g.CreatedAt descending select new Models.GuideModel { guideId = g.GuideId, title = g.Title, comment = g.Comment, imageUrl = g.ImageUrl, createdAt = g.CreatedAt }).ToList(); return(Json(new { message = "Success", list = JsonSerializer.Serialize(list) })); }
public JsonResult CreateNewGuide(string title, string comment, int eventId, int bossId) { try { var file = Request.Form.Files["image"]; var folderPath = Path.Combine("uploads", "img"); var pathToSave = Path.Combine(_env.WebRootPath, folderPath); string dbPath = null; if (file != null && file.Length > 0) { var ext = Path.GetExtension(file.FileName); if (ext != ".jpg" && ext != ".png" && ext != ".gif" && ext != ".jpeg") { return(Json(new { message = "Error: 图像格式无法识别" })); } var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); //var fullPath = Path.Combine(pathToSave, fileName); string renameFile = Convert.ToString(Guid.NewGuid()) + "." + fileName.Split('.').Last(); var fullPath = Path.Combine(pathToSave, renameFile); dbPath = Path.Combine(folderPath, renameFile); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); } } var context = new DatabaseModels.Saren_BotContext(); var newGuide = new DatabaseModels.Guides(); if (bossId == 0) { newGuide.EventId = null; newGuide.BossId = null; } else { newGuide.EventId = eventId; newGuide.BossId = bossId; } newGuide.Title = title; newGuide.Comment = comment; newGuide.ImageUrl = dbPath; context.Guides.Add(newGuide); context.SaveChanges(); } catch (Exception ex) { return(Json(new { message = "Error: " + ex.Message })); } return(Json(new { message = "Success" })); }
//在线轴共享 public IActionResult GuidePage() { var context = new DatabaseModels.Saren_BotContext(); var viewModel = context.Parameters.Select(p => new Models.EventModel { eventId = p.EventId, eventName = p.EventName, status = p.Status }).ToList(); return(View(viewModel)); }
public JsonResult GetSummary(int eventId) { var context = new DatabaseModels.Saren_BotContext(); var eve = context.Parameters.Where(p => p.EventId == eventId).FirstOrDefault(); var startDate = eve.EventStartTime; var endDate = eve.EventEndTime; var nextDay = startDate.AddDays(1); var summaryByMember = new Dictionary <string, List <Models.SummaryModelByDay> >(); var nicknameList = (from b in context.Battles join p in context.Parameters on b.EventId equals p.EventId join m in context.Member on b.MemberId equals m.MemberId where b.EventId == eventId && b.Status != "Abandoned" select m.Nickname).Distinct().ToList(); foreach (var nickname in nicknameList) { summaryByMember.Add(nickname, new List <Models.SummaryModelByDay>()); } var dateList = new List <DateTime>(); while (startDate < endDate) { var damageList = (from b in context.Battles join m in context.Member on b.MemberId equals m.MemberId where b.RecordTime > startDate && b.RecordTime < nextDay && b.Status != "Abandoned" group b by m.Nickname into g select new Models.SummaryModel { nickname = g.Key, damageSum = g.Sum(b => b.Damage) }).ToList(); foreach (var day in damageList) { var newModel = new Models.SummaryModelByDay(); newModel.date = startDate; newModel.damageSum = day.damageSum; summaryByMember[day.nickname].Add(newModel); } dateList.Add(startDate); startDate = nextDay; nextDay = nextDay.AddDays(1); } return(Json(new { message = "Success", damageList = JsonSerializer.Serialize(summaryByMember), nicknameList = JsonSerializer.Serialize(nicknameList), dateList = JsonSerializer.Serialize(dateList) })); }
public JsonResult SetupTabs(int eventId) { var context = new DatabaseModels.Saren_BotContext(); var list = context.Boss.Where(b => b.EventId == eventId).Select(b => new Models.BossTabModel { bossId = b.BossId, bossName = b.BossName }).OrderBy(o => o.bossId).ToList(); return(Json(new { message = "Success", list = JsonSerializer.Serialize(list) })); }
public void Init(int eventId) { var context = new DatabaseModels.Saren_BotContext(); var activeEventId = context.Parameters.Where(p => p.Status == "Active").FirstOrDefault().EventId; var bossList = (from b in context.Boss where b.EventId == eventId select b.BossName).ToList(); bossNames = GenerateSearchOptionValue(bossList); var nicknameList = (from b in context.Battles join p in context.Parameters on b.EventId equals p.EventId join m in context.Member on b.MemberId equals m.MemberId where b.EventId == eventId select m.Nickname).Distinct().ToList(); nicknames = GenerateSearchOptionValue(nicknameList); }
public JsonResult RemoveGuides(int guideId) { var context = new DatabaseModels.Saren_BotContext(); try { var guide = context.Guides.Where(g => g.GuideId == guideId).FirstOrDefault().Status = "Inactive"; context.SaveChanges(); } catch (Exception ex) { return(Json(new { message = "Error: " + ex.Message })); } return(Json(new { message = "Success" })); }
public JsonResult EditRecord(int battleId, string nickname, string bossName, int?damage) { var context = new DatabaseModels.Saren_BotContext(); try { var battle = context.Battles.Where(b => b.BattleId == battleId).FirstOrDefault(); battle.MemberId = context.Member.Where(m => m.Nickname == nickname).FirstOrDefault().MemberId; battle.BossId = context.Boss.Where(b => b.BossName == bossName).FirstOrDefault().BossId; battle.Damage = damage; context.SaveChanges(); } catch (Exception e) { return(Json(new { message = "Error: " + e.Message })); } return(Json(new { message = "Success" })); }
public RecordModel(IQueryCollection query) { var context = new DatabaseModels.Saren_BotContext(); var eventId = Convert.ToInt32(query["eventId"].ToString()); baseQuery = (from r in context.Battles join m in context.Member on r.MemberId equals m.MemberId join b in context.Boss on r.BossId equals b.BossId where r.EventId == eventId && (r.Status == "Finished" || r.Status == "Last_Hit" || r.Status == "OffTree") select new Model { battleId = r.BattleId, nickname = m.Nickname, bossName = b.BossName, cycleNumber = r.CycleNumber, damage = r.Damage, status = r.Status, recordTime = r.RecordTime }); }
public DailyRecord(String date) { var todayChina = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("China Standard Time")); if (todayChina < DateTime.ParseExact(todayChina.ToString("MM/dd/yyyy") + " 05:00", "MM/dd/yyyy HH:mm", null)) { todayChina = todayChina.AddDays(-1); } var context = new DatabaseModels.Saren_BotContext(); var activeEvent = context.Parameters.Where(p => p.Status == "active").FirstOrDefault(); if (activeEvent == null) { return; } var startDate = activeEvent.EventStartTime; //var dayEnd = startDate.AddDays(1); dateRange = new List <string>(); while (startDate < todayChina && startDate < activeEvent.EventEndTime) { dateRange.Add(startDate.ToString("MM/dd/yyyy")); startDate = startDate.AddDays(1); } if (date == null || date == "") { selectedDate = dateRange[dateRange.Count - 1]; } else { selectedDate = date; } var startTime = DateTime.ParseExact(selectedDate + " 05:00", "MM/dd/yyyy HH:mm", null); var endTime = startTime.AddDays(1); var parameter = context.Parameters.Where(p => p.EventStartTime <= startTime && p.EventEndTime > startTime).FirstOrDefault(); //if (parameter == null) //{ // currentBoss = null; // return; //} //currentBoss = context.Boss.Where(b => b.BossId == parameter.CurrentBossId).FirstOrDefault().BossName; //currentHealth = parameter.CurrentBossHealth; //currentRound = parameter.CurrentCycle; var recordList = (from b in context.Battles join o in context.Boss on b.BossId equals o.BossId join m in context.Member on b.MemberId equals m.MemberId join pl in context.Member on b.PlayerId equals pl.MemberId into plView from p in plView.DefaultIfEmpty() where b.RecordTime >= startTime && b.RecordTime < endTime && b.Status != "Abandoned" select new IndividualRecord.Battle { battleId = b.BattleId, bossId = (o.BossId % 5 == 0)?5: o.BossId % 5, bossName = o.BossName, roundNumber = b.CycleNumber, memberId = m.MemberId, memberName = m.Nickname, playerName = p.Nickname, damage = b.Damage, type = b.Status, recordTime = b.RecordTime }).ToList(); var memberList = context.Member.Where(m => m.Role != "inactive").Select(m => m).ToList(); var slRecords = context.SlRecord.Where(s => s.RecordTime >= startTime && s.RecordTime < endTime).Select(m => m.MemberId).Distinct().ToHashSet(); recordSet = new Dictionary <long, IndividualRecord>(); foreach (var member in memberList) { IndividualRecord record = new IndividualRecord(); record.name = member.Nickname; record.memberId = member.MemberId; record.battles = new IndividualRecord.Battle[6]; record.pointer = 0; //True for used sl if (slRecords.Contains(member.MemberId)) { record.slUsed = true; } else { record.slUsed = false; } recordSet.Add(member.MemberId, record); } foreach (var record in recordList) { var list = recordSet[record.memberId]; if (record.type == "Finished") { list.battles[list.pointer] = record; list.pointer += 1; if (list.pointer % 2 == 1) { list.pointer += 1; } } else if (record.type == "Last_Hit") { list.battles[list.pointer] = record; list.pointer += 1; } } var groupSets = recordList.GroupBy(g => (g.bossId, g.roundNumber)).Select(s => s.OrderBy(o => (o.roundNumber, o.bossId)).ToList()).ToList(); var roundGroup = new Dictionary <int?, RoundRecord>(); foreach (var boss in groupSets) { if (boss.Count <= 0) { continue; } var bossRec = new RoundRecord.BossRecord(); bossRec.bossId = boss[0].bossId; bossRec.bossName = boss[0].bossName; bossRec.trySpend = boss.Where(b => b.type == "Finished").Count(); bossRec.totalDamage = boss.Sum(b => b.damage); RoundRecord rec; if (roundGroup.ContainsKey(boss[0].roundNumber)) { rec = roundGroup[boss[0].roundNumber]; } else { rec = new RoundRecord(); rec.boss = new RoundRecord.BossRecord[5]; rec.roundNumber = boss[0].roundNumber; roundGroup.Add(rec.roundNumber, rec); } rec.boss[bossRec.bossId - 1] = bossRec; } roundList = roundGroup.OrderBy(r => r.Key).Select(s => s.Value).ToList(); foreach (var r in roundList) { r.totalTrySpend = 0; foreach (var b in r.boss) { if (b != null) { r.totalTrySpend += b.trySpend; } } } }