//Default Constructor
        public EditResourceModel()
        {
            ResourceStructures = new List <ResourceStructureModel>();

            ResourceStructureAttributeValues = new List <ResourceStructureAttributeValueModel>();
            TextValues = new List <Models.ResourceStructure.TextValueModel>();
            FileValues = new List <Models.ResourceStructure.FileValueModel>();

            using (ResourceStructureManager manager = new ResourceStructureManager()){
                Parent = new ResourceModel();
                foreach (RS.ResourceStructure rs in manager.GetAllResourceStructures().ToList())
                {
                    ResourceStructures.Add(new ResourceStructureModel(rs));
                }

                //BookingTimeGranularity
                Duration       = new TimeDuration();
                Duration.Value = 1;
                TimeUnits      = Enum.GetValues(typeof(SystemDefinedUnit)).Cast <SystemDefinedUnit>().ToList();


                ResourceConstraintModel = new ResourceConstraintModel();
                ResourceConstraints     = new List <ResourceConstraintModel>();
                DependencyConstraints   = new List <DependencyConstraintModel>();
                BlockingConstraints     = new List <BlockingConstraintModel>();
                QuantityConstraints     = new List <QuantityConstraintModel>();
            }
        }
        public EditResourceModel(R.SingleResource resource, List <ResourceStructureAttributeValueModel> valuesModel, List <TextValueModel> textValues, List <FileValueModel> fileValues)
        {
            Id                = resource.Id;
            Name              = resource.Name;
            Description       = resource.Description;
            Quantity          = resource.Quantity;
            ResourceStructure = new ResourceStructureModel(resource.ResourceStructure);
            ResourceStructureAttributeValues = valuesModel;
            ResourceStructures = new List <ResourceStructureModel>();
            Color                 = resource.Color;
            WithActivity          = resource.WithActivity;
            ResourceConstraints   = new List <Resource.ResourceConstraintModel>();
            DependencyConstraints = new List <DependencyConstraintModel>();
            BlockingConstraints   = new List <BlockingConstraintModel>();
            QuantityConstraints   = new List <QuantityConstraintModel>();
            //TextValues = new List<TextValueModel>();
            //FileValues = new List<FileValueModel>();

            TextValues = textValues;
            FileValues = fileValues;

            //BookingTimeGranularity
            Duration  = new TimeDuration();
            Duration  = resource.Duration.Self;
            TimeUnits = Enum.GetValues(typeof(SystemDefinedUnit)).Cast <SystemDefinedUnit>().ToList();

            using (ResourceStructureManager manager = new ResourceStructureManager())
            {
                foreach (RS.ResourceStructure rs in manager.GetAllResourceStructures().ToList())
                {
                    ResourceStructures.Add(new ResourceStructureModel(rs));
                }
            }
            //BookingTimeGranularity = resource.BookingTimeGranularity;

            ResourceConstraintModel = new ResourceConstraintModel();

            if (resource.ResourceConstraints != null)
            {
                foreach (ResourceConstraint c in resource.ResourceConstraints)
                {
                    if (c is DependencyConstraint)
                    {
                        DependencyConstraintModel dcModel = new DependencyConstraintModel((DependencyConstraint)c);
                        dcModel.Id    = c.Id;
                        dcModel.Index = c.Index;
                        DependencyConstraints.Add(dcModel);
                        ResourceConstraints.Add(dcModel);
                    }

                    if (c is BlockingConstraint)
                    {
                        BlockingConstraintModel bcModel = new BlockingConstraintModel((BlockingConstraint)c);
                        bcModel.Id    = c.Id;
                        bcModel.Index = c.Index;
                        BlockingConstraints.Add(bcModel);
                        ResourceConstraints.Add(bcModel);
                    }

                    if (c is QuantityConstraint)
                    {
                        QuantityConstraintModel qcModel = new QuantityConstraintModel((QuantityConstraint)c);
                        qcModel.Id    = c.Id;
                        qcModel.Index = c.Index;
                        QuantityConstraints.Add(qcModel);
                        ResourceConstraints.Add(qcModel);
                    }
                }
                //Sort by Index
                ResourceConstraints = ResourceConstraints.OrderBy(x => x.Index).ToList();
            }
        }