public int Save(Task task) { TodoListDbEntities db = new TodoListDbEntities(); Task dbTask; if (task.Id > 0) { dbTask = db.Tasks.Find(task.Id); if (dbTask != null) { dbTask.Name = task.Name; dbTask.DueDate = task.DueDate; dbTask.IsCompleted = task.IsCompleted; dbTask.Priority = task.Priority; dbTask.ProjectId = task.ProjectId; dbTask.Changed = DateTime.Now; } } else { task.Created = DateTime.Now; task.Changed = DateTime.Now; dbTask = db.Tasks.Add(task); } db.SaveChanges(); UpdateProjectCount(task.ProjectId, db); return dbTask.Id; }
public ResponseModel Post(Task task) { TaskService service = new TaskService(); ResponseModel responseModel; try { bool completed = service.MarkCompleter(task); responseModel = new ResponseModel(isSuccess: completed); } catch (Exception exception) { responseModel = new ResponseModel(isSuccess: false,exception:exception,message:"Couldn't mark complete the task"); } return responseModel; }
public ResponseModel Post(Task task) { ResponseModel response; try { task.Project = null; int id = _taskService.Save(task); response = id > 0 ? new ResponseModel(id) : new ResponseModel(null, false, "Couldn't save"); } catch (Exception exception) { response = new ResponseModel(null, false, "Error occurred", exception); } return response; }
public bool MarkCompleter(Task task) { todoListDbEntities db = new todoListDbEntities(); var dbTask = db.Tasks.Find(task.Id); if (dbTask!=null) { dbTask.isCompleted = true; db.SaveChanges(); int projectId = dbTask.ProjectId; UpdateProjectCount(projectId, db); } return true; }