public AjaxFormResult SaveTip([TipBinder(Fetch = true)] Tip tip) { var response = new AjaxFormResult(); try { if (ViewData.ModelState.IsValid && tip.IsValid()) { if (tip.Id == 0) { tipRepository.SaveOrUpdate(tip); response.ExtraParams["newID"] = tip.Id.ToString(); response.ExtraParams["name"] = tip.Name; } response.Success = true; } else { response.Success = false; response.Errors.Add(new FieldError("Tip_Id", "The TipID field is required")); tipRepository.DbContext.RollbackTransaction(); } } catch (Exception e) { response.Success = false; response.ExtraParams["msg"] = e.ToString(); } return(response); }
public ActionResult Create([TaskBinder(Fetch = false)] Task task) { if (ViewData.ModelState.IsValid && task.IsValid()) { task.Game = User.Game; task.GroupTag = 0; Tip tip = new Tip(); tip.Name = "Здесь должен быть текст задания..."; tip.SuspendTime = 0; tip.Task = task; task.Tips.Add(tip); taskRepository.SaveOrUpdate(task); tipsRepository.SaveOrUpdate(tip); Message = "Задание успешно создано."; return this.RedirectToAction(c => c.Edit(task.Id)); } TaskFormViewModel viewModel = TaskFormViewModel.CreateTaskFormViewModel(); viewModel.Task = task; return View(viewModel); }
public static Team AssignTip(this Team team, Tip tip) { team.TeamGameState.ActiveTaskState.AcceptedTips.Add(new AcceptedTip { Tip = tip, TeamTaskState = team.TeamGameState.ActiveTaskState }); return team; }
public void CanCompareTips() { Tip instance = new Tip(); instance.Name = "New tip"; Tip instanceToCompareTo = new Tip(); instanceToCompareTo.Name = "New tip"; instance.ShouldEqual(instanceToCompareTo); }
/// <summary> /// Creates a valid, transient Tip; typical of something retrieved back from a form submission /// </summary> public static Tip CreateTransientTip() { Tip tip = new Tip() { Name = "New tip", SuspendTime = 30, Task = new Task() }; return tip; }
public AjaxStoreResult CreateTask() { Task task = new Task(); Tip tip = new Tip { Name = "Здесь должен быть текст задания...", SuspendTime = 0, Task = task }; task.Tips.Add(tip); return(new AjaxStoreResult(new List <Task> { task }, 1)); }
public AjaxStoreResult CreateTip(int taskId) { Tip tip = new Tip() { Name = "Новая подсказка" }; Task task = taskRepository.Get(taskId); tip.SuspendTime = task.Tips.Count * task.Game.TimePerTip; return(new AjaxStoreResult(new List <Tip> { tip }, 1)); }
public AjaxResult DeleteTip(int id) { try { Tip tip = tipRepository.Get(id); tipRepository.Delete(tip); return(new AjaxResult()); } catch (Exception e) { return(new AjaxResult { ErrorMessage = e.Message }); } }
public void CanAssignNewTaskTipTest() { DateTime recalcTime = DateTime.Now; Expect.Call(acceptedTipRepository.SaveOrUpdate(null)).IgnoreArguments(); mocks.ReplayAll(); var service = new TaskService(taskRepository, teamTaskStateRepository, acceptedCodeRepository, acceptedBadCodeRepository, acceptedTipRepository, dispatcherFactory); var teamTaskState = new TeamTaskState { TeamGameState = new TeamGameState { Game = game, Team = team } }; var tip = new Tip(); service.AssignNewTaskTip(teamTaskState, tip, recalcTime); mocks.VerifyAll(); Assert.AreEqual(1, teamTaskState.AcceptedTips.Count()); Assert.AreEqual(recalcTime, teamTaskState.AcceptedTips[0].AcceptTime); Assert.AreEqual(tip, teamTaskState.AcceptedTips[0].Tip); Assert.AreEqual(teamTaskState, teamTaskState.AcceptedTips[0].TeamTaskState); }
public AjaxFormResult SaveTask([TaskBinder(Fetch = true)] Task task) { var response = new AjaxFormResult(); try { if (ViewData.ModelState.IsValid && task.IsValid()) { if (task.Id == 0) { task.Game = User.Game; Tip tip = new Tip { Name = "Здесь должен быть текст задания...", SuspendTime = 0, Task = task }; task.Tips.Add(tip); tipRepository.SaveOrUpdate(tip); response.ExtraParams["newID"] = task.Id.ToString(); response.ExtraParams["name"] = task.Name; } response.Success = true; } else { response.Success = false; response.Errors.Add(new FieldError("Task_ID", "The CustomerID field is required")); taskRepository.DbContext.RollbackTransaction(); } } catch (Exception e) { response.Success = false; response.ExtraParams["msg"] = e.ToString(); } return(response); }
public AjaxStoreResult CreateTip(int taskId) { Tip tip = new Tip() { Name = "Новая подсказка" }; Task task = taskRepository.Get(taskId); tip.SuspendTime = task.Tips.Count * task.Game.TimePerTip; return new AjaxStoreResult(new List<Tip> { tip }, 1); }
public void SetUp() { mocks = new MockRepository(); gameService = mocks.DynamicMock<IGameService>(); repository = mocks.DynamicMock<IRepository<Game>>(); service = new RecalcGameStateService(1, repository, gameService); game = new Game { GameState = GameStates.Started, GameDate = new DateTime(2010, 1, 1, 21, 0, 0), TotalTime = 540, TimePerTask = 90, TimePerTip = 30 }; task1 = new Task(); task1Tip0 = new Tip { SuspendTime = 0, Task = task1 }; task1Tip1 = new Tip { SuspendTime = 30, Task = task1 }; task1Tip2 = new Tip { SuspendTime = 60, Task = task1 }; task1.Tips.Add(task1Tip0); task1.Tips.Add(task1Tip1); task1.Tips.Add(task1Tip2); task1.Codes.Add(new Code { Name = "1", Task = task1 }); game.Tasks.Add(task1); }
/// <summary> /// Отправить команде подсказку. /// </summary> /// <param name="teamTaskState"></param> /// <param name="tip"></param> public void AssignNewTaskTip(TeamTaskState teamTaskState, Tip tip) { taskService.AssignNewTaskTip(teamTaskState, tip); }
public void AssignNewTaskTip(TeamTaskState teamTaskState, Tip tip, DateTime recalcTime) { AcceptedTip acceptedTip = new AcceptedTip { AcceptTime = recalcTime, Tip = tip, TeamTaskState = teamTaskState }; //Подсказку дадим только в том случае, если такая еще не выдавалась. if (!teamTaskState.AcceptedTips.Any(x => x.Tip == tip)) { teamTaskState.AcceptedTips.Add(acceptedTip); acceptedTipRepository.SaveOrUpdate(acceptedTip); } }
public void ShouldNotAssignDuodleTipTest() { DateTime recalcTime = DateTime.Now; DoNotExpect.Call(acceptedTipRepository.SaveOrUpdate(null)); mocks.ReplayAll(); var service = new TaskService(taskRepository, teamTaskStateRepository, acceptedCodeRepository, acceptedBadCodeRepository, acceptedTipRepository, dispatcherFactory); var teamTaskState = new TeamTaskState { TeamGameState = new TeamGameState { Game = game, Team = team } }; var tip = new Tip { Name = "Tip 0", SuspendTime = 0 }; teamTaskState.AcceptedTips.Add(new AcceptedTip { Tip = tip }); service.AssignNewTaskTip(teamTaskState, tip, recalcTime); mocks.VerifyAll(); Assert.AreEqual(1, teamTaskState.AcceptedTips.Count()); }
public void CanEnsureTipCreationIsValid() { Tip tipFromForm = new Tip(); ViewResult result = controller.Create(tipFromForm).AssertViewRendered(); result.ViewData.Model.ShouldNotBeNull(); result.ViewData.Model.ShouldBeOfType(typeof(TipsController.TipFormViewModel)); }
private void TransferFormValuesTo(Tip tipToUpdate, Tip tipFromForm) { tipToUpdate.Name = tipFromForm.Name; tipToUpdate.SuspendTime = tipFromForm.SuspendTime; tipToUpdate.Task = tipFromForm.Task; }
public AjaxFormResult SaveTask([TaskBinder(Fetch = true)] Task task) { var response = new AjaxFormResult(); try { if (ViewData.ModelState.IsValid && task.IsValid()) { if (task.Id == 0) { task.Game = User.Game; Tip tip = new Tip { Name = "Здесь должен быть текст задания...", SuspendTime = 0, Task = task }; task.Tips.Add(tip); tipRepository.SaveOrUpdate(tip); response.ExtraParams["newID"] = task.Id.ToString(); response.ExtraParams["name"] = task.Name; } response.Success = true; } else { response.Success = false; response.Errors.Add(new FieldError("Task_ID", "The CustomerID field is required")); taskRepository.DbContext.RollbackTransaction(); } } catch(Exception e) { response.Success = false; response.ExtraParams["msg"] = e.ToString(); } return response; }
/// <summary> /// Отправить команде подсказку. /// </summary> /// <param name="teamTaskState"></param> /// <param name="tip"></param> /// <param name="dateTimeNow"></param> public void AssignNewTaskTip(TeamTaskState teamTaskState, Tip tip, DateTime dateTimeNow) { taskService.AssignNewTaskTip(teamTaskState, tip, dateTimeNow); }
public AjaxStoreResult CreateTask() { Task task = new Task(); Tip tip = new Tip { Name = "Здесь должен быть текст задания...", SuspendTime = 0, Task = task }; task.Tips.Add(tip); return new AjaxStoreResult(new List<Task> { task }, 1); }
public void SetUp() { mocks = new MockRepository(); taskService = mocks.DynamicMock<ITaskService>(); gameRepository = mocks.DynamicMock<IRepository<Game>>(); teamRepository = mocks.DynamicMock<IRepository<Team>>(); teamGameStateRepository = mocks.DynamicMock<IRepository<TeamGameState>>(); dbContext = mocks.DynamicMock<IDbContext>(); task1 = new Task(); task1Tip0 = new Tip { SuspendTime = 0, Task = task1 }; task1Tip1 = new Tip { SuspendTime = 30, Task = task1 }; task1Tip2 = new Tip { SuspendTime = 60, Task = task1 }; task1.Tips.Add(task1Tip0); task1.Tips.Add(task1Tip1); task1.Tips.Add(task1Tip2); task1.Codes.Add(new Code { Name = "1", Task = task1 }); service = new GameService(gameRepository, teamRepository, teamGameStateRepository, taskService); }
public void SetUp() { mocks = new MockRepository(); gameService = mocks.DynamicMock<IGameService>(); repository = mocks.DynamicMock<IRepository<Game>>(); dbContext = mocks.DynamicMock<IDbContext>(); service = new RecalcGameStateService(1, repository, gameService); game = new Game { GameState = GameStates.Started, GameDate = new DateTime(2010, 1, 1, 21, 0, 0), TotalTime = 540, TimePerTask = 90, TimePerTip = 30 }; task1 = new Task(); task1Tip0 = new Tip { SuspendTime = 0, Task = task1 }; task1Tip1 = new Tip { SuspendTime = 30, Task = task1 }; task1Tip2 = new Tip { SuspendTime = 60, Task = task1 }; task1.Tips.Add(task1Tip0); task1.Tips.Add(task1Tip1); task1.Tips.Add(task1Tip2); task1.Codes.Add(new Code { Name = "1", Task = task1 }); game.Tasks.Add(task1); Expect.Call(repository.DbContext).Return(dbContext).Repeat.Any(); Expect.Call(dbContext.BeginTransaction()).Repeat.Any(); Expect.Call(() => dbContext.CommitTransaction()).Repeat.Any(); }