Example #1
0
        /// <summary>
        /// Checks the Employee foreign keys and performs an update on their values.
        /// </summary>
        /// <param name="_employee">The employee object we want to check</param>
        /// <returns>Returns a boolean with the outcome of the update operation</returns>
        public static bool checkRelations(Employee _employee)
        {
            using (var context = new synupEntities())
            {
                //Finds all the Teams the employee is in.
                var query = from th in context.TeamHistories
                            where th.id_employee.Equals(_employee.nif)
                            select th;

                //Deletes all the relations with teams the employee might have.
                foreach (var member in query)
                {
                    if (TeamHistoryConnection.deleteTeamHistory(member.id_employee, member.id_team) == null)
                    {
                        return(false);
                    }
                }

                //Finds all the tasks the employee has been given.
                //If the task is not finished, it will be abandonned. If the task is ongoing, it will be abandonned and therefore given a finishdate.
                var query2 = from th in context.TaskHistories
                             where th.id_employee.Equals(_employee.nif) && (th.isFinished == 0 || th.finishDate == null)
                             select th;

                //For each TaskHistories register found.
                foreach (var q in query2)
                {
                    //It will find the tasks tied to it.
                    var qu = from task in context.Tasks
                             where task.code.Equals(q.id_task)
                             select task;

                    //Will update the state of the found tasks to ABANDONNED.
                    foreach (var ta in qu)
                    {
                        ta.state = (int)TaskState.ABANDONED;
                        TaskConnection.updateTask(ta);
                    }

                    //Will set the finish date to todays date.
                    q.finishDate = DateTime.Now;
                }

                //Returns whether the update has been done sucesfully or not.
                return(commitChanges(context));
            }
        }
Example #2
0
        /// <summary>
        /// CHECK THAT THE TEAM THAT IS DELETED WONT HAVE ANY FOREIGN KEYS THAT REFERENCE IT
        /// </summary>
        /// <param name="team"></param>
        private static bool checkTeamMembers(Team team)
        {
            using (var _context = new synupEntities())
            {
                var query = from th in _context.TeamHistories
                            where th.id_team.Equals(team.code)
                            select th;

                foreach (var member in query)
                {
                    if (TeamHistoryConnection.deleteTeamHistory(member.id_employee, member.id_team) == null)
                    {
                        return(false);
                    }
                }

                var query2 = from task in _context.Tasks
                             where task.id_team.Equals(team.code)
                             select task;

                foreach (var task in query2)
                {
                    task.id_team = null;
                    task.state   = (int)TaskState.UNSELECTED;
                    task.Team    = null;
                    if (!TaskConnection.updateTask(task))
                    {
                        return(false);
                    }
                }

                /*team.Tasks = null;
                 * team.TeamHistories = null;*/

                return(commitChanges(_context));
            }
        }