public ActionResult Create(Task item) { if(ModelState.IsValid) { _taskRepo.Create(item); } return RedirectToAction("Index"); }
private TaskCompleteViewModel createTaskViewModel(Task task) { TaskCompleteViewModel tcvm = new TaskCompleteViewModel() { TaskName = task.Name, TaskDescription = task.Description, TaskToken = task.Token }; return tcvm; }
//Adds a task to the user. private void addTaskToUser(UserProfile user, Task task) { CompletedTask cTask = new CompletedTask() { Task = task, TaskID = task.ID, UserProfile = user, UserProfileID = user.ID, CompletedDate = DateTime.Now, }; if (task.CompletedBy.Count < task.MaxBonusAwards) cTask.AwardedPoints = task.Points + task.BonusPoints; else cTask.AwardedPoints = task.Points; user.CompletedTask.Add(cTask); task.CompletedBy.Add(cTask); _taskRepo.Update(task); _userRepo.Update(user); }
//Verifies that the fields are valid and returns the status. private string commonCompleteTask(UserProfile user, Task task, string solution = null) { string status; if (user == null) { //Ensure we have a user. status = "User not found"; } else if (task == null) { //Ensure we have a task. status = "Task not found"; } else if (DateTime.Now < task.StartTime || DateTime.Now > task.EndTime) { //Verify that this task can be completed. status = "Task is not availible at this time"; } else { //Complete the task. if (!string.IsNullOrEmpty(task.Solution)) { if (solution == task.Solution) { addTaskToUser(user, task); status = "Correct!"; } else { status = "Incorrect solution."; } } else { addTaskToUser(user, task); status = "Task Completed"; } } return status; }
public ActionResult Create(Task item) { if(ModelState.IsValid) { item.Token = new Guid().ToString(); _taskRepo.Create(item); } return RedirectToAction("Index"); }