Exemple #1
0
        /// <summary>
        /// Deletes a given task.
        /// </summary>
        /// <param name="t">Receives the task that is meant to be deleted.</param>
        /// <returns>Returns the task that has been deleted.</returns>
        public static pojo.Task deleteTask(pojo.Task t)
        {
            using (var context = new synupEntities())
            {
                pojo.Task foundTask = readTask(t.code, context); //Finds the received task in the database.

                if (foundTask != null)                           //If the task has been found - meaning that it exists:
                {
                    foundTask.state = (int)TaskState.CANCELLED;
                    if (updateTask(foundTask))
                    {
                        if (commitChanges(context))
                        {
                            return(foundTask);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            return(null);
        }
Exemple #2
0
        /// <summary>
        /// Updates a given task with the new parameters of it.
        /// </summary>
        /// <param name="t">Receives the task that will be updated.</param>
        /// <returns>Returns a boolean whether the task has been updated succesfully or not.</returns>
        public static bool updateTask(pojo.Task t)
        {
            using (var context = new synupEntities())
            {
                pojo.Task modifiedTask = readTask(t.code, context);

                if (modifiedTask != null)
                {
                    //tryAttach(context, modifiedTask);
                    //tryAttach(context, modifiedTask);
                    //modifiedTask.code = t.code;
                    modifiedTask.description  = t.description;
                    modifiedTask.id_team      = t.id_team;
                    modifiedTask.localization = t.localization;
                    modifiedTask.name         = t.name;
                    modifiedTask.priorityDate = t.priorityDate;
                    modifiedTask.project      = t.project;
                    modifiedTask.priority     = t.priority;

                    return(commitChanges(context));
                }
            }

            return(false);
        }
Exemple #3
0
        private static void tryAttach(synupEntities _context, pojo.Task _task)
        {
            var entry = _context.Entry(_task);

            if (entry.State == System.Data.Entity.EntityState.Detached)
            {
                _context.Tasks.Attach(_task);
            }
        }
Exemple #4
0
        /// <summary>
        /// Creates a given task.
        /// </summary>
        /// <param name="t">Receives the object Task that will be inserted in the database</param>
        /// <returns>Returns a boolean depending in the outcome of the insert - true if it is successfull</returns>
        public static bool createTask(pojo.Task t)
        {
            pojo.Task foundTask = readTask(t.code); //Finds the received task in the database.

            if (foundTask == null)
            {
                //database.Tasks.Add(t); //If the task doesn't exist already in the database, it will be inserted.
                using (var context = new synupEntities())
                {
                    context.Tasks.Add(t);
                    return(commitChanges(context));
                }
            }

            return(false);
        }