Exemplo n.º 1
0
        public Project SaveProject(Project project)
        {
            #region Placeholder code

            /*
             * var projectAccess = AccessorFactory.CreateAccessor<IProjectAccess>();
             *
             * // you will need to copy properties across to the database versions of project / activity
             * // var saved = projectAccess.SaveProject(dbProject);
             * // return saved;
             *
             * // you will need to return a project, with data from the database.
             * return project; // don't return this version.
             */
            #endregion

            var projectAccess = AccessorFactory.CreateAccessor <IProjectAccess>();

            #region Updating DB Project object
            DPL.PMTool.Accessors.Shared.EntityFramework.Project dbProject = projectAccess.Project(project.Id);

            if (dbProject == null)
            {
                dbProject           = new DPL.PMTool.Accessors.Shared.EntityFramework.Project();
                dbProject.CreatedAt = DateTime.Now;
            }
            dbProject.Id        = project.Id;
            dbProject.Name      = project.Name;
            dbProject.Start     = project.Start;
            dbProject.UpdatedAt = DateTime.Now;

            DPL.PMTool.Accessors.Shared.EntityFramework.Project returnedDbProject = projectAccess.SaveProject(dbProject);
            #endregion

            #region Updating DB Activity objects
            Activity[]      activitiesList    = project.Activities;
            List <Activity> newActivitiesList = new List <Activity>();
            foreach (Activity activity in activitiesList)
            {
                DPL.PMTool.Accessors.Shared.EntityFramework.Activity dbActivity = new DPL.PMTool.Accessors.Shared.EntityFramework.Activity();

                if (activity.Id != 0)
                {
                    dbActivity = projectAccess.Activity(activity.Id);
                }
                if (dbActivity == null)
                {
                    dbActivity           = new DPL.PMTool.Accessors.Shared.EntityFramework.Activity();
                    dbActivity.CreatedAt = DateTime.Now;
                }

                dbActivity.Id           = activity.Id;
                dbActivity.TaskName     = activity.TaskName;
                dbActivity.Estimate     = activity.Estimate;
                dbActivity.Predecessors = activity.Predecessors;
                dbActivity.Resource     = activity.Resource;
                dbActivity.Priority     = activity.Priority;
                dbActivity.Start        = activity.Start;
                dbActivity.Finish       = activity.Finish;
                dbActivity.ProjectId    = returnedDbProject.Id;
                dbActivity.UpdatedAt    = DateTime.Now;

                DPL.PMTool.Accessors.Shared.EntityFramework.Activity returnedDbActivity = projectAccess.SaveActivity(dbActivity);

                activity.Id           = returnedDbActivity.Id;
                activity.TaskName     = returnedDbActivity.TaskName;
                activity.Estimate     = returnedDbActivity.Estimate;
                activity.Predecessors = returnedDbActivity.Predecessors;
                activity.Resource     = returnedDbActivity.Resource;
                activity.Priority     = returnedDbActivity.Priority;
                activity.Start        = returnedDbActivity.Start;
                activity.Finish       = returnedDbActivity.Finish;
                activity.ProjectId    = returnedDbActivity.Id;

                newActivitiesList.Add(activity);
            }
            #endregion

            #region Update Client Project object
            Project newClientProject = new Project();

            newClientProject.Id    = returnedDbProject.Id;
            newClientProject.Name  = returnedDbProject.Name;
            newClientProject.Start = returnedDbProject.Start;
            for (int i = 0; i < newActivitiesList.Count; i++)
            {
                activitiesList[i] = newActivitiesList[i];
            }
            newClientProject.Activities = activitiesList;
            #endregion

            return(newClientProject);
        }
Exemplo n.º 2
0
        public Project SaveProject(Project project)
        {
            var projectAccess             = AccessorFactory.CreateAccessor <IProjectAccess>();
            var activitiesSchedulerAccess = EngineFactory.CreateEngine <IScheduleEngine>();

            var dbProject = new DPL.PMTool.Accessors.Shared.EntityFramework.Project()
            {
                Name  = project.Name,
                Id    = project.Id,
                Start = project.Start,
            };

            var savedProject  = projectAccess.SaveProject(dbProject);
            var resultProject = new Project()
            {
                Id    = savedProject.Id,
                Start = savedProject.Start,
                Name  = savedProject.Name
            };

            var activities = new List <Activity>();
            var act        = new List <DPL.PMTool.Accessors.Shared.EntityFramework.Activity>();

            foreach (var activity in project.Activities)
            {
                var dbActivity = new DPL.PMTool.Accessors.Shared.EntityFramework.Activity()
                {
                    Id           = activity.Id,
                    Estimate     = activity.Estimate,
                    TaskName     = activity.TaskName,
                    Predecessors = activity.Predecessors,
                    Priority     = activity.Priority,
                    Finish       = activity.Finish,
                    Start        = activity.Start,
                    Resource     = activity.Resource,
                    ProjectId    = dbProject.Id
                };
                act.Add(dbActivity);
            }

            var resultActivities = activitiesSchedulerAccess.CalculateSchedule(act.ToArray(), dbProject);

            foreach (var rsa in resultActivities)
            {
                activities.Add(new Activity()
                {
                    Id           = rsa.Id,
                    Estimate     = rsa.Estimate,
                    TaskName     = rsa.TaskName,
                    Start        = rsa.Start,
                    Finish       = rsa.Finish,
                    Predecessors = rsa.Predecessors,
                    Priority     = rsa.Priority,
                    Resource     = rsa.Resource,
                });
            }

            resultProject.Activities = activities.ToArray();

            return(resultProject);
        }