public Task Create(Task taskToCreate) { _entities.AddToTaskSet(taskToCreate); _entities.SaveChanges(); return taskToCreate; }
public void Delete(Task taskToDelete) { var originalTask = Get(taskToDelete.Id); _entities.DeleteObject(originalTask); _entities.SaveChanges(); }
public bool ValidateTask(Task taskToValidate) { //convert null values to default strings taskToValidate.Subject = taskToValidate.Subject ?? ""; if (taskToValidate.Subject.Trim().Length == 0) _validationDictionary.AddError("Task.Subject", "A Subject is required."); if (taskToValidate.StartDate < DateTime.Now) { _validationDictionary.AddError("Task.StartDate", "The Start Date must be greater or equals to current date time."); return _validationDictionary.IsValid; } if (taskToValidate.EndDate <= taskToValidate.StartDate) { _validationDictionary.AddError("Task.EndDate", "The End Date must be greater than Start date."); return _validationDictionary.IsValid; } if (taskToValidate.LimitDate < taskToValidate.StartDate || taskToValidate.LimitDate > taskToValidate.EndDate) _validationDictionary.AddError("Task.LimitDate", "The Limit Date must be within Start Date and End Date interval."); return _validationDictionary.IsValid; }
public Task Update(Task taskToUpdate) { var originalTask = Get(taskToUpdate.Id); _entities.ApplyCurrentValues(originalTask.EntityKey.EntitySetName, taskToUpdate); _entities.SaveChanges(); return taskToUpdate; }
public TaskViewModel(Task task) { //creating the elements for task status and task priority drop down lists var statuses = Enum.GetNames(typeof(TaskStatus)); var priorities = Enum.GetNames(typeof(TaskPriority)); Task = task; Statuses = new SelectList(statuses, Task.Status); Priorities = new SelectList(priorities, Task.Priority); }
public bool CreateTask(Task taskToCreate) { // Validation logic if (!ValidateTask(taskToCreate)) return false; // Database logic try { _repository.Create(taskToCreate); } catch { return false; } return true; }
public TaskViewModel() { //we round the current time like this: 13:45:0 ==> 14:00:00 DateTime current = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, (DateTime.Now.Hour + 1) % 24, 0, 0); Task = new Task { StartDate = current, LimitDate = current.AddDays(5), EndDate = current.AddDays(10) }; //creating the elements for task status and task priority drop down lists var statuses = Enum.GetNames(typeof(TaskStatus)); var priorities = Enum.GetNames(typeof(TaskPriority)); Statuses = new SelectList(statuses, Task.Status); Priorities = new SelectList(priorities, Task.Priority); }
public bool EditTask(Task taskToEdit) { // we only validate the "Subject" as the other fields( StarDate,LimitDate,EndDate) cannot // be edited once the task has been created, and 'Status' and 'Priority' don't need to. if (taskToEdit.Subject.Trim().Length == 0) { _validationDictionary.AddError("Task.Subject", "A Subject is required."); return false; } // Database logic try { _repository.Update(taskToEdit); } catch { return false; } return true; }
public bool DeleteTask(Task taskToDelete) { try { _repository.Delete(taskToDelete); } catch { return false; } return true; }
/// <summary> /// Deprecated Method for adding a new object to the TaskSet EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToTaskSet(Task task) { base.AddObject("TaskSet", task); }
/// <summary> /// Create a new Task object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="subject">Initial value of the Subject property.</param> /// <param name="status">Initial value of the Status property.</param> /// <param name="startDate">Initial value of the StartDate property.</param> /// <param name="limitDate">Initial value of the LimitDate property.</param> /// <param name="endDate">Initial value of the EndDate property.</param> /// <param name="priority">Initial value of the Priority property.</param> public static Task CreateTask(global::System.Int32 id, global::System.String subject, global::System.String status, global::System.DateTime startDate, global::System.DateTime limitDate, global::System.DateTime endDate, global::System.String priority) { Task task = new Task(); task.Id = id; task.Subject = subject; task.Status = status; task.StartDate = startDate; task.LimitDate = limitDate; task.EndDate = endDate; task.Priority = priority; return task; }
public ActionResult Delete(Task task) { if (!_taskService.DeleteTask(task)) return View(task); return RedirectToAction("Index"); }