public bool Create() { try { if (Id == -1) { log.Error("Se intentó crear Tarea inválida. ID: " + Id); throw new Exception(); } else { if (Id > 0 && IsPredefined) { //En caso que esté intentando crear una predeterminada return(true); } else { Data.TASK task = new Data.TASK(); task.NAME = Name; task.DESCRIPTION = Description; task.ISPREDEFINED = StaticHelper.BoolToShort(IsPredefined); task.ISACTIVE = StaticHelper.BoolToShort(IsActive); if (SuperiorTask != null) { task.ID_SUPERIOR_TASK = SuperiorTask.Id; } else { task.ID_SUPERIOR_TASK = null; } if (DependentTask != null) { task.ID_DEPENDENT_TASK = DependentTask.Id; } else { task.ID_DEPENDENT_TASK = null; } Connection.ProcessSA_DB.TASK.Add(task); Connection.ProcessSA_DB.SaveChanges(); Id = (int)task.ID; return(true); } } } catch (Exception e) { log.Error("Ha ocurrido un error durante la creación de Tarea de nombre: " + Name, e); return(false); } }
public bool HaveChilds() { try { Data.TASK task = Connection.ProcessSA_DB.TASK.First(tsk => tsk.ID_SUPERIOR_TASK == Id); return(true); } catch (Exception e) { return(false); } }
public bool ReadById() { try { Data.TASK task = Connection.ProcessSA_DB.TASK.First(tsk => tsk.ID == Id); Id = (int)task.ID; Name = task.NAME; Description = task.DESCRIPTION; IsPredefined = StaticHelper.ShortToBool(task.ISPREDEFINED); IsActive = StaticHelper.ShortToBool(task.ISACTIVE); if (task.ID_SUPERIOR_TASK != null) { SuperiorTask = new Task() { Id = (int)task.ID_SUPERIOR_TASK }; SuperiorTask.ReadById(); } else { SuperiorTask = null; } if (task.ID_DEPENDENT_TASK != null) { DependentTask = new Task() { Id = (int)task.ID_DEPENDENT_TASK }; DependentTask.ReadById(); } else { DependentTask = null; } return(true); } catch (Exception e) { log.Error("Ha ocurrido un error durante la lectura de Tarea de Id: " + Id, e); return(false); } }
public bool Update() { try { Data.TASK task = Connection.ProcessSA_DB.TASK.First(tsk => tsk.ID == Id); task.NAME = Name; task.DESCRIPTION = Description; task.ISPREDEFINED = StaticHelper.BoolToShort(IsPredefined); task.ISACTIVE = StaticHelper.BoolToShort(IsActive); task.ID_SUPERIOR_TASK = SuperiorTask.Id; task.ID_DEPENDENT_TASK = DependentTask.Id; Connection.ProcessSA_DB.SaveChanges(); return(true); } catch (Exception e) { log.Error("Ha ocurrido un error durante el update de Tarea de Id: " + Id, e); return(false); } }