Esempio n. 1
0
        public static Project ToDtoObject(this Trex.Server.Core.Model.Project project, bool includeParent, bool includeTasks, bool includeTimeEntries)
        {
            var dtoProject = new Project();

            if (includeParent)
            {
                dtoProject.Company = project.Customer.ToDtoObject(false, false, false, false);
            }

            dtoProject.CompanyId          = project.Customer.Id;
            dtoProject.CreateDate         = project.CreateDate;
            dtoProject.CreatedBy          = project.CreatedBy.ToDtoObject(false);
            dtoProject.Guid               = project.Guid;
            dtoProject.Id                 = project.Id;
            dtoProject.Inactive           = project.Inactive;
            dtoProject.Name               = project.Name;
            dtoProject.IsEstimatesEnabled = project.IsEstimatesEnabled;

            if (includeTasks)
            {
                dtoProject.Tasks = project.Tasks.ToDtoObjects(includeParent, true, includeTimeEntries);
            }

            return(dtoProject);
        }
Esempio n. 2
0
        public Project SaveProject(Project project)
        {
            try
            {
                var projectFactory    = ObjectFactory.GetInstance <IProjectFactory>();
                var companyRepository = ObjectFactory.GetInstance <ICustomerRepository>();
                var userRepository    = ObjectFactory.GetInstance <IUserRepository>();
                var projectRepository = ObjectFactory.GetInstance <IProjectRepository>();
                var customer          = companyRepository.GetByID(project.CompanyId);
                var user = userRepository.GetByUserID(project.CreatedBy.UserId);

                if (project.Id == 0)
                {
                    var newProject = projectFactory.Create(project.Name, customer, user, project.IsEstimatesEnabled);
                    projectRepository.Update(newProject);
                    project.Id   = newProject.Id;
                    project.Guid = newProject.Guid;
                }
                else
                {
                    var originalProject = projectRepository.GetByID(project.Id);
                    originalProject.Name               = project.Name;
                    originalProject.Customer           = customer;
                    originalProject.Inactive           = project.Inactive;
                    originalProject.CreatedBy          = user;
                    originalProject.CreateDate         = project.CreateDate;
                    originalProject.IsEstimatesEnabled = project.IsEstimatesEnabled;

                    projectRepository.Update(originalProject);
                }

                return(project);
            }
            catch (Exception ex)
            {
                OnError(ex);
                throw;
            }
        }