public async Task <int> AddNewResult(AddResult addResult, string userId)
        {
            var Result = new Domain.Result.Result(addResult.enemy, addResult.set1, addResult.set2, addResult.set3, addResult.league);
            int Id     = await _resultRepository.AddResult(Result, userId);

            return(Id);
        }
 public void AddResult(Result result)
 {
     if (result != null)
     {
         repository.AddResult(result);
     }
 }
        public async Task <IActionResult> AddResult(List <ResultForAddDto> model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _response = await _repo.AddResult(model);

            return(Ok(_response));
        }
Exemple #4
0
        public async Task <IActionResult> UploadFile(IFormFile file, string titles, string paperName, string refsName,
                                                     string criterionName = null)
        {
            if (file == null)
            {
                return(new PartialViewResult());
            }

            var uploadFile = new UploadFile
            {
                FileName   = file.FileName,
                Length     = file.Length,
                DataStream = new MemoryStream()
            };

            await file.CopyToAsync(uploadFile.DataStream);

            ResultCriterion criterion = null;

            try
            {
                var criteria = await _context.GetCriteria();

                criterion = criteria.First(c => c.Name == criterionName);
            }
            catch (Exception)
            {
                //Возможно только во время выполнения теста
            }

            ResultScoreSettings settings = null;

            if (criterion != null)
            {
                settings = new ResultScoreSettings
                {
                    ErrorCost = criterion.ErrorCost,
                    KeyWordsCriterionFactor     = criterion.KeyWordsCriterionFactor,
                    KeyWordsCriterionLowerBound = criterion.KeyWordsCriterionLowerBound,
                    KeyWordsCriterionUpperBound = criterion.KeyWordsCriterionUpperBound,
                    WaterCriterionFactor        = criterion.WaterCriterionFactor,
                    WaterCriterionLowerBound    = criterion.WaterCriterionLowerBound,
                    WaterCriterionUpperBound    = criterion.WaterCriterionUpperBound,
                    ZipfFactor           = criterion.ZipfFactor,
                    ZipfFactorLowerBound = criterion.ZipfFactorLowerBound,
                    ZipfFactorUpperBound = criterion.ZipfFactorUpperBound
                };
            }
            else
            {
                //Возможно только во время выполнения теста
                settings = new ResultScoreSettings()
                {
                    ErrorCost = 2,
                    KeyWordsCriterionFactor     = 35,
                    KeyWordsCriterionUpperBound = 6,
                    KeyWordsCriterionLowerBound = 14,
                    WaterCriterionFactor        = 35,
                    WaterCriterionLowerBound    = 14,
                    WaterCriterionUpperBound    = 20,
                    ZipfFactor           = 30,
                    ZipfFactorLowerBound = 5.5,
                    ZipfFactorUpperBound = 9.5
                };
            }

            PaperAnalysisResult result;

            try
            {
                result = _analyzeService.GetAnalyze(uploadFile, titles, paperName, refsName, settings);
            }
            catch (Exception ex)
            {
                result = new PaperAnalysisResult(new List <Section>(), new List <Criterion>(),
                                                 new List <AnalyzeResults.Errors.Error>())
                {
                    Error = ex.Message
                };

                return(Error(ex.Message));
            }

            AnalysisResult analysisResult = null;

            if (criterion != null)
            {
                analysisResult = new AnalysisResult
                {
                    Id           = Guid.NewGuid().ToString(),
                    Result       = result,
                    StudentLogin = User.Identity.Name,
                    TeacherLogin = criterion.TeacherLogin,
                    Criterion    = criterion.Name
                };
            }
            else
            {
                analysisResult = new AnalysisResult
                {
                    Id           = Guid.NewGuid().ToString(),
                    Result       = result,
                    StudentLogin = null,
                    TeacherLogin = null,
                    Criterion    = null
                };
            }

            Repository.AddResult(analysisResult);
            return(Ok(analysisResult.Id));
        }
 public Guid Handle(AddResultCommand command)
 {
     _resultRepository.AddResult(command.Id, command.HomeScore, command.AwayScore);
     return(command.Id);
 }
Exemple #6
0
        public MobileLoginModel PostResult(HttpRequestMessage message)
        {
            try
            {
                var postText = message.Content.ReadAsStringAsync().Result;
                if (string.IsNullOrEmpty(postText))
                {
                    return(new MobileLoginModel {
                        Message = "No data synced."
                    });
                }

                var models = JsonConvert.DeserializeObject <List <MoiblePostResult> >(postText);
                //if (model.Module > 0)
                //{
                //    return new MobileLoginModel { Message = "Something is wrong with the provided data. Please try again later" };
                //}
                List <int> ints = new List <int>();
                foreach (var model in models)
                {
                    string[] codes = model.PersonCode.Split('/');
                    var      path  = "";
                    if (model.ProofImage.Length != 0)
                    {
                        var image = Utils.ConvertToImage(model.ProofImage);
                        path = Path.Combine(HttpContext.Current.Server.MapPath("~/Images/Proof/"), model.PersonCode.Replace('/', '_') + ".jpg");
                        image.Save(path);
                    }

                    var result_id = _resultRepository.AddResult(new Result
                    {
                        Module       = model.Module,
                        RegVotes     = model.RegVotes,
                        AccredVotes  = model.AccredVotes,
                        CastVotes    = model.CastVotes,
                        InvalidVotes = model.InvVotes,
                        ReportedBy   = model.ReportedBy,
                        ProofUrl     = path,
                        State        = int.Parse(codes[0]),
                        Lga          = int.Parse(codes[1]),
                        Ward         = int.Parse(codes[2]),
                        PollingUnit  = int.Parse(codes[3])
                    });
                    if (result_id > 0)
                    {
                        foreach (var m in model.Votes)
                        {
                            _voteRepository.AddVote(new Vote
                            {
                                ResultId = result_id,
                                PartyId  = m.Party,
                                Vote1    = m.Vote
                            });
                        }

                        _voteRepository.AddBytePhoto(new Photo {
                            ResultId = result_id,
                            Image    = model.ProofImage,
                            Reporter = model.ReportedBy
                        });
                    }
                    ints.Add(model.Id);
                }

                if (ints.Count > 0)
                {
                    return(new MobileLoginModel
                    {
                        Message = "Successfully Synced",
                        Result = ints
                    });
                }
                return(new MobileLoginModel {
                    Message = "synchronization failed."
                });
            }
            catch (Exception e)
            {
                return(new MobileLoginModel {
                    Message = "Synchronization failed due to internal server error."
                });
            }
        }