Пример #1
0
        private async Task <ActionResult> ExecuteChampionship(ChampionshipModel model)
        {
            RPSSolver      solver      = new RPSSolver();
            Parser         parser      = new Parser();
            CompetitorData secondPlace = new CompetitorData();
            string         errorMessage;
            bool           result       = false;
            var            championship = parser.StringToCompetitors(model.Input, out errorMessage);

            if (string.IsNullOrEmpty(errorMessage))
            {
                CompetitorData[] finalists = solver.Solve(championship);
                model.Winner   = finalists[0].Name;
                model.Strategy = finalists[0].Strategy.ToString();
                secondPlace    = finalists[1];
                ApiClient client = new ApiClient();
                result = await client.SaveResult(model.Winner, secondPlace.Name);
            }
            else
            {
                model.ErrorMessage = errorMessage;
            }

            return(View("Execute", model));
        }
Пример #2
0
        public async Task <ActionResult> UploadFile(HttpPostedFileBase file)
        {
            ChampionshipModel model = new ChampionshipModel();

            if (file.ContentLength > 0)
            {
                byte[] fileContentBuff = new byte[file.ContentLength];
                file.InputStream.Read(fileContentBuff, 0, file.ContentLength);
                StringBuilder builder = new StringBuilder();
                foreach (byte character in fileContentBuff)
                {
                    builder.Append((char)character);
                }
                model.Input = builder.ToString();
            }
            return(await ExecuteChampionship(model));
        }
 public ChampionshipController(MoviesCupApiContext context)
 {
     _context    = context;
     _chpModel   = new ChampionshipModel(context);
     _movieModel = new MovieModel(context);
 }
Пример #4
0
 public async Task <ActionResult> Execute(ChampionshipModel model)
 {
     return(await ExecuteChampionship(model));
 }
Пример #5
0
        public ActionResult ChampForm()
        {
            ChampionshipModel model = new ChampionshipModel();

            return(View(model));
        }