public async Task <IHttpActionResult> Update([FromBody] ProblemModel model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var problemToUpdate = await ProblemCore.GetAsync(model.Id); if (problemToUpdate == null) { return(BadRequest("Problem couldn't be found")); } problemToUpdate.Name = model.Name; problemToUpdate.Description = model.Description; var result = await ProblemCore.UpdateAsync(problemToUpdate); if (result == null) { return(BadRequest("Error updating problem")); } return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } }
public async Task <IHttpActionResult> Create([FromBody] ProblemModel model) { try { if (!ModelState.IsValid || string.IsNullOrWhiteSpace(model.Name) || string.IsNullOrWhiteSpace(model.Description)) { return(BadRequest(ModelState)); } var problem = new Problem { UserId = Identity.Id, Name = model.Name, Description = model.Description }; var result = await ProblemCore.CreateAsync(problem); if (result == null) { return(BadRequest("Invalid input")); } return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } }
public async Task <IHttpActionResult> Get(Guid id) { try { var problem = await ProblemCore.GetAsync(id); if (problem == null) { return(BadRequest("No problem with the given id found")); } var result = new ProblemModel { Id = problem.Id, UserId = problem.UserId, Name = problem.Name, Description = problem.Description }; return(Ok(result)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public List <CallViewModel> GetAll() { List <CallViewModel> allVms = new List <CallViewModel>(); try { List <Call> allCalls = _model.GetAll(); foreach (Call call in allCalls) { CallViewModel cVm = new CallViewModel(); EmployeeModel employee = new EmployeeModel(); ProblemModel problem = new ProblemModel(); cVm.Id = call.Id; cVm.EmployeeId = call.EmployeeId; cVm.ProblemId = call.ProblemId; cVm.TechId = call.TechId; cVm.TechName = employee.GetById(call.TechId).LastName; cVm.EmployeeName = employee.GetById(call.EmployeeId).LastName; cVm.ProblemDescription = problem.GetById(call.ProblemId).Description; cVm.Notes = call.Notes; cVm.DateOpened = call.DateOpened; cVm.DateClosed = call.DateClosed; cVm.OpenStatus = call.OpenStatus; cVm.Timer = Convert.ToBase64String(call.Timer); allVms.Add(cVm); } } catch (Exception ex) { Console.WriteLine("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod().Name + " " + ex.Message); throw ex; } return(allVms); }
public void CreateProblem() { var problemService = A.Fake <IProblemService>(); var problemRepository = A.Fake <IProblemRepository>(); var memberRepository = A.Fake <IMemberRepository>(); var problemController = ControllerLocator.GetProblemController(memberRepository, problemService, problemRepository); var problem = _session.Single <Problem>().Get(); var member = _session.Single <Member>().Get(); var problemModel = new ProblemModel { Title = problem.Title, Text = problem.Text }; A.CallTo(() => memberRepository.Get(member.OpenId)).Returns(member); A.CallTo(() => problemService.CreateProblem(problem.Title, problem.Text.TransformLine(), member)) .WithAnyArguments() .Returns(problem); var redirect = problemController.Create(problemModel) as RedirectToRouteResult; Assert.That(redirect, Is.Not.Null); Assert.That(redirect.RouteValues["action"], Is.EqualTo("Details")); Assert.That(redirect.RouteValues["id"], Is.EqualTo(problem.Id.ToString())); }
/// <summary> /// 打乱答案顺序 /// </summary> /// <param name="paperM"></param> private void UpsetAnswer(ProblemModel problemM) { Random rd = new Random(); List <int> upsetIndex = new List <int>(); for (int i = 0; i < problemM.Answers.Count; i++) { upsetIndex.Add(i); } int Index; int TrueIndex; List <V_Answer> answers = new List <V_Answer>(); V_Answer tempM; while (upsetIndex.Count > 0) { Index = rd.Next(0, upsetIndex.Count); TrueIndex = upsetIndex[Index]; tempM = problemM.Answers[TrueIndex]; tempM.IsCorrect = false; answers.Add(tempM); upsetIndex.RemoveAt(Index); } problemM.Answers = answers; }
public ActionResult Submit(ProblemModel Problem, string ProblemID) { int pos, ContestID; bool isTwoChars = int.TryParse(ProblemID.Substring(ProblemID.Length - 1), out pos); int ID = Convert.ToInt16(Session["ID"]); if (isTwoChars) { ContestID = int.Parse(ProblemID.Substring(0, ProblemID.Length - 2)); } else { ContestID = int.Parse(ProblemID.Substring(0, ProblemID.Length - 1)); } Automate Judge = new Automate(); Judge.OpenCodeforces(Problem.ProblemCode, ProblemID); string SubmissionJson = Judge.SubmissionJsonFile("A4A_A4A", ContestID); Helpers.SubmissionHelper helper = new Helpers.SubmissionHelper(); int SubmissionID = helper.ParseSubmission(SubmissionJson, ID, Problem.ProblemContestID); return(RedirectToAction("ViewSubmission", new { SubmissionID = SubmissionID })); }
private void button4_Click(object sender, EventArgs e) { //ZAMKNIJ INTERWENCJE if (tboxDescr.Text != "" && cboxProblemType.Text != "") { while (!technicians.Contains(_tID)) { AskForID(); //ASK FOR TECHNICIAN ID } Debug.Assert(_tID != null); if (_tID != null) { //build sql query ProblemModel pm = new ProblemModel(); pm.Tester = lblTester.Text.Substring(lblTester.Text.IndexOf(':')); pm.Start = lblStartTime.Text; //conv string pm.InterventionStart = lblStartInterv.Text; //conv string pm.Stop = DateTime.Now.ToString(datetimeFormat); //conv string pm.Downtime = DateTime.Now.Subtract(_start); pm.TypeOfIssue = cboxProblemType.Text; pm.RootCause = tboxDescr.Text; pm.technicianID = _tID; pm.LoggedOperator = Environment.UserName; try { SqlDataAccess.SaveProblemSQL(pm); } catch (Exception exc) { MessageBox.Show("BRAK POLACZENIA Z BAZA DANYCH. SPRAWDZ CZY MASZ POLACZENIE Z SERWEREM."); Error2txt(errorFilePath, exc.ToString()); } ResetControls(); } } }
// [Route("{id}")] public async Task <IActionResult> Details(long?id) { var problem = _context.Problems.FirstOrDefault(p => p.Id == id); var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().UseBootstrap().Build(); var html = Markdown.ToHtml(problem.Description, pipeline); var raw = Markdown.ToPlainText(problem.Description); var author = await _userManager.FindByIdAsync(problem.AuthorId); var model = new ProblemModel { Id = problem.Id, Title = problem.Title, Description = problem.Description, ContentRaw = raw, ContentHtml = html, AuthorId = problem.AuthorId, Author = author.UserName, ExampleData = problem.ExampleData, JudgeProfile = problem.JudgeProfile, PassRate = problem.PassRate, PublishTime = problem.PublishTime }; return(View(model)); }
public async Task <IActionResult> SubmitSolutionAsync(int pid, [FromForm] string lang, [FromForm] string code) { var user = HttpContext.Session.GetString("user"); if (user is null) { return(Unauthorized("Not logged in.")); } if (code.Length > maxSolutionSize) { return(StatusCode(StatusCodes.Status413PayloadTooLarge, $"Solution size should be less than {maxSolutionSize} bytes.")); } if (!SolutionModel.LangMap.ContainsKey(lang)) { return(BadRequest("No such language.")); } var viewAll = await UserModel.Authorization.CanViewAllProblemsAsync(user); if (!viewAll) { if (await ProblemModel.IsProblemRestrictedAsync(pid)) { return(StatusCode(StatusCodes.Status403Forbidden, "This problem is private now.")); } } if (!await ProblemModel.IsProblemExists(pid)) { return(NotFound("No such problem.")); } var submit_id = await SolutionModel.SubmitProblemAsync(user, pid, SolutionModel.LangMap[lang], code); return(Ok(submit_id)); }
public async Task <IActionResult> Preview(ProblemModel model) { var problem = await _puzzleService.GetProblemByIdAsync(model.Id); if (problem == null) { return(View(new ProblemModel { MessageType = MessageType.Error, Message = "找不到这个题目", ShowContent = false })); } model.Content = problem.Content; model.Level = problem.Level; model.Script = problem.Script; model.Title = problem.Title; if (problem.Answer == model.Answer) { model.Message = "答案正确"; model.MessageType = MessageType.Success; model.ShowContent = true; model.Answer = ""; ModelState.Clear(); return(View(model)); } model.Message = "答案不正确"; model.MessageType = MessageType.Warning; model.ShowContent = true; return(View(model)); }
public Rectangle2(ProblemModel pm) { Height = pm.Height; Width = pm.Width; ComputeType = pm.ComputeType; ObjectType = pm.ObjectType; }
private void addResources() { //create a variable for each resource var firstTerm = true; Term resourceTerm = null; resources = new Dictionary <string, Decision>(); foreach (var op in AifFile.OperationTypes) { var decision = new Decision(Domain.IntegerNonnegative, op); ProblemModel.AddDecision(decision); resources[op] = decision; resourceTerm = firstTerm ? decision : resourceTerm + decision; firstTerm = false; } Log.Debug("Resource Types: " + string.Join(", ", AifFile.OperationTypes)); Log.Trace("Constraint (ResourceLowerBounds): " + ProblemModel.AddConstraints("ResourceLowerBounds", resources.Values .Select(decision => decision >= 1) .ToArray()).Expression); Log.Trace($"Resources Goal: {ProblemModel.AddGoal("resources", GoalKind.Minimize, resourceTerm).Expression}"); }
private Scoreboard.Problem MakeProblem(ScoreCellModel s, ProblemModel p, bool xcpc) { if (s == null) { return(new Scoreboard.Problem { IsPassFail = xcpc, ProblemId = $"{p.ProblemId}", Label = p.ShortName }); } else { return(new Scoreboard.Problem { IsPassFail = xcpc, FirstToSolve = s.IsFirstToSolve, NumJudged = s.JudgedCount, NumPending = s.PendingCount, ProblemId = $"{p.ProblemId}", Solved = s.Score.HasValue, Score = s.Score ?? 0, Label = p.ShortName, Time = s.Score ?? 0 }); } }
public ActionResult Single(int id) { ProblemModel problem = get(id); // problem.Posts = dbContext.Database.SqlQuery<Post>($"select*from Posts where ProblemModelId = {id}; ").ToList(); return(View(problem)); }
public ActionResult PublishProblem(ProblemModel model) { ViewBag.Title = model.Title; ViewBag.Body = model.Body; Save(model); return(Redirect("/Problem/Single/" + model.Id)); }
private void OnModelSelected(ProblemModel obj) { FunctionInputViewModel.ApplyModel(obj); ConstraintsViewModel.ApplyModel(obj); InitialVariableViewModel.ApplyModel(obj); SolutionViewModel.ApplyModel(obj); }
/// <summary> /// Primary thread of execution /// All logic starts here! /// </summary> public Core() { userModel = ModelFactory.UserModel; setModel = ModelFactory.ProblemSetModel; problemModel = ModelFactory.ProblemModel; classModel = ModelFactory.ClassModel; progressModel = ModelFactory.ProgressModel; }
public override async Task UpdateProblemAsync( ProblemModel origin, Expression <Func <ContestProblem, ContestProblem> > expression) { await base.UpdateProblemAsync(origin, expression); Expire("Problems"); }
/// <summary> /// 根据问题唯一标识获得问题视图信息 /// </summary> /// <param name="id">问题唯一标识</param> /// <returns>查询结果</returns> public ProblemModel GetProblemViewInfoByID(Guid id) { ProblemModel resM; V_Problem model = _dal.GetDBModelViewInfoByID(id); resM = new ProblemModel(model); resM.Answers = _answerDAL.GetAnswerViewInfoByProblemID(resM.ID); return(resM); }
public MResultModel GetProblemInfoByID(Guid ID) { MResultModel resM; ProblemModel listM = _problemBLL.GetProblemViewInfoByID(ID); resM = MResultModel <ProblemModel> .GetSuccessResultM(listM, "查询成功"); return(resM); }
public ActionResult ViewProblem(string ProblemID, string ProblemLink) { ProblemModel Problem = new ProblemModel { ProblemLink = ProblemLink, ProblemID = ProblemID, }; return(View(Problem)); }
public virtual async Task <IBlobInfo?> GetTestcaseAsync(ProblemModel problem, int testcaseId, string filetype) { var testcase = await Polygon.Testcases.FindAsync(testcaseId, problem.ProblemId); if (testcase == null || (!problem.Shared && testcase.IsSecret)) { return(null); } return(await Polygon.Testcases.GetFileAsync(testcase, filetype)); }
public virtual Task UpdateProblemAsync( ProblemModel origin, Expression <Func <ContestProblem, ContestProblem> > expression) { int cid = origin.ContestId, probid = origin.ProblemId; return(Db.ContestProblems .Where(oldcp => oldcp.ContestId == cid && oldcp.ProblemId == probid) .BatchUpdateAsync(expression)); }
public virtual async Task DeleteProblemAsync(ProblemModel problem) { int cid = problem.ContestId, probid = problem.ProblemId; await Db.ContestProblems .Where(cp => cp.ContestId == cid && cp.ProblemId == probid) .BatchDeleteAsync(); await FixProblemCountAsync(Contest.Id, false); }
public ActionResult PostComment(int problemId, string commentText) { var userId = (int)Session["UserId"]; Comment newComment = new Comment(commentText, 0, userId, problemId); _commentRepo.AddComment(newComment); ProblemModel pm = new ProblemModel(); pm.Getproblem(problemId); return(RedirectToAction("Detail", new { id = problemId })); }
// GET: Problem public ActionResult Index() { if ((int)Session["UserID"] == -1) { return(RedirectToAction("Login", "User")); } ProblemModel pm = new ProblemModel(); return(View(pm)); }
/// <summary> /// 根据试题ID获取问题信息 /// </summary> /// <param name="paperID">试题ID</param> /// <returns></returns> public List <ProblemModel> GetProblemInfoByPaperID(Guid paperID) { List <V_Problem> listM = _dal.GetProblemViewInfoByPaperID(paperID); List <ProblemModel> resM = ProblemModel.GetList(listM); foreach (ProblemModel item in resM) { item.Answers = _answerDAL.GetAnswerViewInfoByProblemID(item.ID); } return(resM); }
public ActionResult ViewProblem(string ProblemID, string ProblemLink, string UserName = "******", int id = 0) { ProblemModel Problem = new ProblemModel { ProblemLink = ProblemLink, ProblemID = ProblemID, }; ViewBag.ID = id; ViewBag.UserName = UserName; return(View(Problem)); }
public ActionResult Detail(int id) { if ((int)Session["UserID"] == -1) { return(RedirectToAction("Login", "User")); } ProblemModel pm = new ProblemModel(); pm.Getproblem(id); return(View(pm)); }
public void Call_ComprehensiveTest() { CallModel cmodel = new CallModel(); EmployeeModel emodel = new EmployeeModel(); ProblemModel pmodel = new ProblemModel(); Calls call = new Calls(); call.DateOpened = DateTime.Now; //call.DateClosed = null; call.OpenStatus = true; call.EmployeeId = emodel.GetByLastname("Park").Id; call.TechId = emodel.GetByLastname("Burner").Id; call.ProblemId = pmodel.GetByDescription("Hard Drive Failure").Id; call.Notes = "Jimin's drive is shot, Burner to fix it"; int newCallId = cmodel.Add(call); output.WriteLine("New Call Generated - Id = " + newCallId); call = cmodel.GetById(newCallId); byte[] oldtimer = call.Timer; output.WriteLine("New Call Retrieved"); call.Notes += "\n Ordered new drive!"; if (cmodel.Update(call) == UpdateStatus.Ok) { output.WriteLine("Call was updated " + call.Notes); } else { output.WriteLine("Call was not updated!"); } call.Timer = oldtimer; call.Notes = "doesn't matter data is stale now"; if (cmodel.Update(call) == UpdateStatus.Stale) { output.WriteLine("Call was not updated due to stale data"); } cmodel = new CallModel(); call = cmodel.GetById(newCallId); if (cmodel.Delete(newCallId) == 1) { output.WriteLine("Call was deleted!"); } else { output.WriteLine("Call was noe deleted"); } Assert.Null(cmodel.GetById(newCallId)); }