Skip to content

Commit

Permalink
Version 1.4
Browse files Browse the repository at this point in the history
Synced the latest code from the TFS: changeset 2334 build 3579
  • Loading branch information
NikolayIT committed May 1, 2014
1 parent 877b685 commit cd89885
Show file tree
Hide file tree
Showing 46 changed files with 615 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public bool HasSubmissionTimeLimitPassedForParticipant(int participantId, int li
var lastSubmission =
this.All()
.Where(x => x.ParticipantId == participantId)
.OrderBy(x => x.CreatedOn)
.OrderByDescending(x => x.CreatedOn)
.Select(x => new { x.Id, x.CreatedOn })
.FirstOrDefault();
if (lastSubmission != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ImportActionTests()
[TestMethod]
public void ImportActionShouldShowProperRedirectAndMessageWithIncorrectProblemId()
{
var redirectResult = this.TestsController.Import("invalid", null, false) as RedirectToRouteResult;
var redirectResult = this.TestsController.Import("invalid", null, false, false) as RedirectToRouteResult;
Assert.IsNotNull(redirectResult);

Assert.AreEqual(GlobalConstants.Index, redirectResult.RouteValues["action"]);
Expand All @@ -41,7 +41,7 @@ public void ImportActionShouldShowProperRedirectAndMessageWithIncorrectProblemId
[TestMethod]
public void ImportActionShouldShowProperRedirectAndMessageWhenProblemDoesNotExist()
{
var redirectResult = this.TestsController.Import("100", null, false) as RedirectToRouteResult;
var redirectResult = this.TestsController.Import("100", null, false, false) as RedirectToRouteResult;
Assert.IsNotNull(redirectResult);

Assert.AreEqual(GlobalConstants.Index, redirectResult.RouteValues["action"]);
Expand All @@ -56,7 +56,7 @@ public void ImportActionShouldShowProperRedirectAndMessageWhenProblemDoesNotExis
[TestMethod]
public void ImportActionShouldShowProperRedirectAndMessageWhenFileIsNull()
{
var redirectResult = this.TestsController.Import("1", null, false) as RedirectToRouteResult;
var redirectResult = this.TestsController.Import("1", null, false, false) as RedirectToRouteResult;
Assert.IsNotNull(redirectResult);

Assert.AreEqual("Problem", redirectResult.RouteValues["action"]);
Expand All @@ -74,7 +74,7 @@ public void ImportActionShouldShowProperRedirectAndMessageWhenFileContentIsZero(
{
this.File.Setup(x => x.ContentLength).Returns(0);

var redirectResult = this.TestsController.Import("1", this.File.Object, false) as RedirectToRouteResult;
var redirectResult = this.TestsController.Import("1", this.File.Object, false, false) as RedirectToRouteResult;
Assert.IsNotNull(redirectResult);

Assert.AreEqual("Problem", redirectResult.RouteValues["action"]);
Expand All @@ -93,7 +93,7 @@ public void ImportActionShouldShowProperRedirectAndMessageWhenFileIsNotZip()
this.File.Setup(x => x.ContentLength).Returns(1);
this.File.Setup(x => x.FileName).Returns("filename.invalid");

var redirectResult = this.TestsController.Import("1", this.File.Object, false) as RedirectToRouteResult;
var redirectResult = this.TestsController.Import("1", this.File.Object, false, false) as RedirectToRouteResult;
Assert.IsNotNull(redirectResult);

Assert.AreEqual("Problem", redirectResult.RouteValues["action"]);
Expand All @@ -118,7 +118,7 @@ public void ImportActionShouldDeleteAllPreviousTestsIfSettingsAreSetToTrue()

try
{
this.TestsController.Import("1", this.File.Object, true);
this.TestsController.Import("1", this.File.Object, false, true);
}
catch (Exception)
{
Expand All @@ -134,7 +134,7 @@ public void ImportActionShouldReturnProperRedirectAndMessageIfZipFileIsNotValid(
this.File.Setup(x => x.FileName).Returns("filename.zip");
this.File.Setup(x => x.InputStream).Returns(new MemoryStream());

var redirectResult = this.TestsController.Import("1", this.File.Object, false) as RedirectToRouteResult;
var redirectResult = this.TestsController.Import("1", this.File.Object, false, false) as RedirectToRouteResult;
Assert.IsNotNull(redirectResult);

Assert.AreEqual("Problem", redirectResult.RouteValues["action"]);
Expand Down Expand Up @@ -166,7 +166,7 @@ public void ImportActionShouldAddTestsToProblemIfZipFileIsCorrect()
this.File.Setup(x => x.FileName).Returns("file.zip");
this.File.Setup(x => x.InputStream).Returns(zipStream);

var redirectResult = this.TestsController.Import("1", this.File.Object, false) as RedirectToRouteResult;
var redirectResult = this.TestsController.Import("1", this.File.Object, false, false) as RedirectToRouteResult;
Assert.IsNotNull(redirectResult);

Assert.AreEqual("Problem", redirectResult.RouteValues["action"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void GetAllowedSubmissionTypesWhenRequestIsValidShouldReturnSubmissionTyp
{
IsSelectedByDefault = true,
Name = "java type",
CompilerType = CompilerType.Java
CompilerType = CompilerType.Java,
};

var csharpSubmissionType = new SubmissionType
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,16 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Answer_required" xml:space="preserve">
<value>Изберете отговор от падащото меню</value>
</data>
<data name="Name" xml:space="preserve">
<value>Име</value>
</data>
<data name="Password" xml:space="preserve">
<value>Password</value>
<value>Парола</value>
</data>
<data name="Question" xml:space="preserve">
<value>Question</value>
<value>Въпрос</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,16 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Answer_required" xml:space="preserve">
<value>Select an answer from the dropdown menu</value>
</data>
<data name="Name" xml:space="preserve">
<value>Name</value>
</data>
<data name="Password" xml:space="preserve">
<value>Парола</value>
<value>Password</value>
</data>
<data name="Question" xml:space="preserve">
<value>Въпрос</value>
<value>Question</value>
</data>
</root>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
<data name="Not_all_questions_answered" xml:space="preserve">
<value>Моля, отговорете на всички въпроси</value>
</data>
<data name="Select_dropdown_answer" xml:space="preserve">
<value>Изберете отговор</value>
</data>
<data name="Submit" xml:space="preserve">
<value>Изпрати</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
<data name="Not_all_questions_answered" xml:space="preserve">
<value>Please answer all questions</value>
</data>
<data name="Select_dropdown_answer" xml:space="preserve">
<value>Select an answer</value>
</data>
<data name="Submit" xml:space="preserve">
<value>Submit</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,7 @@
<data name="User" xml:space="preserve">
<value>Потребител</value>
</data>
<data name="UserFullName" xml:space="preserve">
<value>Име</value>
</data>
</root>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,7 @@
<data name="User" xml:space="preserve">
<value>User</value>
</data>
<data name="UserFullName" xml:space="preserve">
<value>Name</value>
</data>
</root>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,7 @@
<data name="User" xml:space="preserve">
<value>Потребител</value>
</data>
<data name="UserFullName" xml:space="preserve">
<value>Име</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,7 @@
<data name="User" xml:space="preserve">
<value>User</value>
</data>
<data name="UserFullName" xml:space="preserve">
<value>Name</value>
</data>
</root>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@
<value>Open Judge System (OJS)</value>
</data>
<data name="SystemVersion" xml:space="preserve">
<value>1.3.3534.20140419</value>
<value>1.4.3578.20140501</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
using OJS.Web.Controllers;

using DatabaseModelType = OJS.Data.Models.ContestQuestion;
using DatabaseAnswerModelType = OJS.Data.Models.ContestQuestionAnswer;
using ViewModelType = OJS.Web.Areas.Administration.ViewModels.ContestQuestion.ContestQuestionViewModel;
using System.Collections.Generic;
using OJS.Data.Models;

public class ContestQuestionsController : KendoGridAdministrationController
{
Expand Down Expand Up @@ -82,5 +85,66 @@ public JsonResult DeleteQuestionFromContest([DataSourceRequest]DataSourceRequest
this.Data.SaveChanges();
return this.GridOperation(request, model);
}

public ActionResult CopyFromAnotherContest(int id)
{
var contests = this.Data.Contests
.All()
.OrderByDescending(c => c.CreatedOn)
.Select(c => new { Text = c.Name, Value = c.Id });

ViewBag.ContestId = id;

return this.PartialView("_CopyQuestionsFromContest", contests);
}

public void CopyTo(int id, int contestFrom, bool? deleteOld)
{
var copyFromContest = this.Data.Contests.GetById(contestFrom);
var copyToContest = this.Data.Contests.GetById(id);

if (deleteOld.HasValue && deleteOld.Value)
{
var oldQuestions = copyToContest.Questions.Select(q => q.Id).ToList();
this.DeleteQuestions(oldQuestions);
}

var questionsToCopy = copyFromContest.Questions.ToList();
this.CopyQuestionsToContest(copyToContest, questionsToCopy);
}

private void DeleteQuestions(IEnumerable<int> questions)
{
foreach (var question in questions)
{
this.Data.ContestQuestions.Delete(question);
}

this.Data.SaveChanges();
}

private void CopyQuestionsToContest(Contest contest, IEnumerable<ContestQuestion> questions)
{
foreach (var question in questions)
{
var newQuestion = new DatabaseModelType
{
Text = question.Text,
Type = question.Type,
AskOfficialParticipants = question.AskOfficialParticipants,
AskPracticeParticipants = question.AskPracticeParticipants,
RegularExpressionValidation = question.RegularExpressionValidation
};

foreach (var answer in question.Answers)
{
newQuestion.Answers.Add(new DatabaseAnswerModelType { Text = answer.Text });
}

contest.Questions.Add(newQuestion);
}

this.Data.SaveChanges();
}
}
}
Loading

0 comments on commit cd89885

Please sign in to comment.