Exemplo n.º 1
0
        public bool UpdateProject(Project project)
        {
            foreach (var d in project.ProjectDirection)
            {
                if (d.Id == 0)
                {
                    d.ProjectId = project.Id;
                    _projectDal.AddDirection(d);
                }
            }


            var prevProject = _projectDal.GetById(project.Id);

            if (project.ProjectDirection.Count != prevProject.ProjectDirection.Count)
            {
                var except = prevProject.ProjectDirection.Except(project.ProjectDirection, new DirectionComparer());
                foreach (var d in except)
                {
                    _projectDal.DeleteDirection(d);
                }
            }
            else
            {
                foreach (var d in project.ProjectDirection)
                {
                    _projectDal.UpdateDirection(d);
                }
            }

            _projectDal.UpdateProject(project);
            return(true);
        }