public void InsertOrUpdate(TaskDay taskday)
 {
     if (taskday.Id == default(int)) {
         // New entity
         context.TaskDays.Add(taskday);
     } else {
         // Existing entity
         context.Entry(taskday).State = EntityState.Modified;
     }
 }
 public ActionResult Create(TaskDay taskday)
 {
     if (ModelState.IsValid) {
         taskdayRepository.InsertOrUpdate(taskday);
         taskdayRepository.Save();
         return RedirectToAction("Index");
     } else {
         return View();
     }
 }
Exemplo n.º 3
0
 public void InsertOrUpdate(TaskDay taskday)
 {
     if (taskday.Id == default(int))
     {
         // New entity
         context.TaskDays.Add(taskday);
     }
     else
     {
         // Existing entity
         context.Entry(taskday).State = EntityState.Modified;
     }
 }
 public bool SaveTask(TaskDetail task)
 {
     DateTime targetDay = new DateTime(task.Starts.Year, task.Starts.Month, task.Starts.Day);
     TaskDay day = _taskDay.All.FirstOrDefault<TaskDay>(_ => _.Day == targetDay);
     if (day == null)
     {
         day = new TaskDay
         {
             Day = new DateTime(task.Starts.Year, task.Starts.Month, task.Starts.Day),
             Tasks = new List<TaskDetail>()
         };
         _taskDay.InsertOrUpdate(day);
         _taskDay.Save();
         task.ParentTaskId = day.Id;
     }
     else
     {
         task.ParentTaskId = day.Id;
         task.ParentTask = null;
     }
     _taskDetail.InsertOrUpdate(task);
     _taskDetail.Save();
     return true;
 }