Exemplo n.º 1
0
        public async Task <ActionResult> Edit(int id = -1)
        {
            if (id == -1)
            {
                return(RedirectToAction("Index"));
            }
            var model = await _repository.GetAsync(id);

            model.Instances = await _instance.GetAllAsync();

            return(View(model));
        }
        /// <summary>
        /// Checks that the encounters for the specified boss fight are the correct length
        /// i.e. the encounter stopped when the boss died
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private async Task Check_Encounter_Length(int id)
        {
            // Add some bossfight specific parsing here to get us through until this is refactored and the parser does it instead

            var bossFight = await _bossFightRepository.GetAsync(id);

            if (bossFight == null)
            {
                return;
            }

            var encounters = _encounterRepository.GetSuccessfulEncounters(id)
                             .Where(e => e.ValidForRanking)
                             //.OrderBy(e => e.Duration).Take(10)
                             .ToList();

            foreach (var encounter in encounters)
            {
                var encDeaths = await _encounterRepository.GetNpcDeathsAsync(encounter.Id);

                switch (bossFight.Name)
                {
                case "Azranel":
                    // Stop the parse after Azranel dies
                    var azranelDeath = encDeaths.FirstOrDefault(d => d.TargetNpcName == "Azranel");
                    if (azranelDeath == null)
                    {
                        break;
                    }

                    if (encounter.Duration.TotalSeconds > azranelDeath.SecondsElapsed)
                    {
                        Debug.WriteLine($"Need to update the encounter length for encounter {encounter.Id} as it's " +
                                        $"currently {encounter.Duration.TotalSeconds} seconds long but the boss died at {azranelDeath.SecondsElapsed} seconds.");

                        var updateResult =
                            await _encounterRepository.ModifyEncounterDuration(encounter.Id,
                                                                               azranelDeath.SecondsElapsed);

                        if (updateResult.Success)
                        {
                            Debug.WriteLine("Successfully updated the duration.");
                        }
                        else
                        {
                            Debug.WriteLine($"*** Couldn't update the duration: {updateResult.Message}");
                        }
                    }
                    else
                    {
                        Debug.WriteLine($"The duration for encounter {encounter.Id} is correct - {encounter.Duration.TotalSeconds} seconds.");
                    }

                    break;
                }
            }
        }