Exemple #1
0
        public ScheduleEventModel(R.SingleResource resource)
        {
            ResourceId          = resource.Id;
            ResourceName        = resource.Name;
            ResourceDescription = resource.Description;
            WithActivity        = resource.WithActivity;
            ResourceQuantity    = resource.Quantity;

            ScheduleDurationModel scheduleDurationModel = new ScheduleDurationModel();

            scheduleDurationModel.DurationValue = resource.Duration.Value;
            scheduleDurationModel.TimeUnit      = resource.Duration.TimeUnit;
            ScheduleDurationModel = scheduleDurationModel;

            //ByPerson = new PersonInSchedule();
            ForPersons = new List <PersonInSchedule>();
            Contact    = new PersonInSchedule();
            Activities = new List <ActivityEventModel>();
            Files      = new List <FileValueModel>();

            //Get File to Resource if exsist
            foreach (ResourceAttributeUsage usage in resource.ResourceStructure.ResourceAttributeUsages)
            {
                if (usage.IsFileDataType)
                {
                    using (ResourceStructureAttributeManager valueManager = new ResourceStructureAttributeManager())
                    {
                        ResourceAttributeValue value = valueManager.GetValueByUsageAndResource(usage.Id, resource.Id);
                        if (value is FileValue)
                        {
                            FileValue      fileValue = (FileValue)value;
                            FileValueModel fvm       = new FileValueModel(fileValue);
                            Files.Add(fvm);
                            //if (!usage.IsValueOptional)
                            if (fvm.Data != null)
                            {
                                ResourceHasFiles = true;
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public ScheduleEventModel(Schedule schedule)
        {
            ScheduleId              = schedule.Id;
            ResourceId              = schedule.Resource.Id;
            ResourceName            = schedule.Resource.Name;
            ResourceDescription     = schedule.Resource.Description;
            ResourceAttributeValues = schedule.Resource.ResourceAttributeValues;
            Files        = new List <FileValueModel>();
            WithActivity = schedule.Resource.WithActivity;

            //Get File to Resource if exsist
            foreach (ResourceAttributeUsage usage in schedule.Resource.ResourceStructure.ResourceAttributeUsages)
            {
                if (usage.IsFileDataType)
                {
                    using (ResourceStructureAttributeManager valueManager = new ResourceStructureAttributeManager())
                    {
                        ResourceAttributeValue value = valueManager.GetValueByUsageAndResource(usage.Id, schedule.Resource.Id);
                        if (value is FileValue)
                        {
                            FileValue      fileValue = (FileValue)value;
                            FileValueModel fvm       = new FileValueModel(fileValue);
                            Files.Add(fvm);
                            if (!usage.IsValueOptional)
                            {
                                ResourceHasFiles = true;
                            }
                        }
                    }
                }
            }

            ScheduleDurationModel scheduleDurationModel = new ScheduleDurationModel();

            scheduleDurationModel.StartDate     = schedule.StartDate;
            scheduleDurationModel.EndDate       = schedule.EndDate;
            scheduleDurationModel.DurationValue = schedule.Resource.Duration.Value;
            scheduleDurationModel.TimeUnit      = schedule.Resource.Duration.TimeUnit;

            ScheduleDurationModel = scheduleDurationModel;
            ScheduleQuantity      = schedule.Quantity;
            ResourceQuantity      = schedule.Resource.Quantity;
            Status = schedule.Resource.ResourceStatus.ToString();

            //get Persons
            ForPersons = new List <PersonInSchedule>();

            if (schedule.ForPerson.Self is PersonGroup)
            {
                PersonGroup pGroup = (PersonGroup)schedule.ForPerson.Self;

                Contact     = new PersonInSchedule(pGroup.Id, pGroup.Contact, true);
                ContactName = pGroup.Contact.DisplayName;

                foreach (User u in pGroup.Users)
                {
                    if (u.Id == pGroup.Contact.Id)
                    {
                        ForPersons.Add(new PersonInSchedule(pGroup.Id, u, true));
                    }
                    else
                    {
                        ForPersons.Add(new PersonInSchedule(pGroup.Id, u, false));
                    }
                }
            }
            else if (schedule.ForPerson.Self is IndividualPerson)
            {
                IndividualPerson iPerson = (IndividualPerson)schedule.ForPerson.Self;
                Contact     = new PersonInSchedule(iPerson.Id, iPerson.Contact, true);
                ContactName = iPerson.Contact.DisplayName;

                ForPersons.Add(new PersonInSchedule(iPerson.Id, iPerson.Person, true));
            }

            if (schedule.ByPerson.Self is IndividualPerson)
            {
                IndividualPerson iPersonBy = (IndividualPerson)schedule.ByPerson.Self;

                ByPerson = iPersonBy.Person.DisplayName;
            }
        }