public ResourceAttributeValueModel(R.SingleResource resource)
        {
            AttributeIds = new List <long>();
            //get only Id if attr has domain constraint
            foreach (ResourceAttributeUsage u in resource.ResourceStructure.ResourceAttributeUsages)
            {
                if (u.IsFileDataType == false)
                {
                    if (u.ResourceStructureAttribute.Constraints.Count > 0)
                    {
                        AttributeIds.Add(u.ResourceStructureAttribute.Id);
                    }
                }
            }
            //AttributeIds = resource.ResourceStructure.ResourceAttributeUsages.Select(a => a.ResourceStructureAttribute.Id).ToList();

            Values = new List <string>();
            using (ResourceStructureAttributeManager rsaManager = new ResourceStructureAttributeManager())
            {
                List <RS.ResourceAttributeValue> valueList = rsaManager.GetValuesByResource(resource);
                foreach (RS.ResourceAttributeValue v in valueList)
                {
                    if (v is TextValue)
                    {
                        TextValue tv = (TextValue)v;
                        Values.Add(tv.Value);
                    }
                    //Values = valueList.Select(a => a.Value).ToList();
                    Resource = resource;
                }
            }
        }
 public ShowResourceModel(R.SingleResource resource, List <ResourceStructureAttributeValueModel> valuesModel)
 {
     Id                               = resource.Id;
     Name                             = resource.Name;
     Description                      = resource.Description;
     Quantity                         = resource.Quantity;
     Duration                         = resource.Duration.Value;
     TimeUnit                         = resource.Duration.TimeUnit.ToString();
     ResourceStructureName            = resource.ResourceStructure.Name;
     ResourceStructureAttributeValues = valuesModel;
     //ResourceStructure = new ResourceStructureModel(resource.ResourceStructure);
 }
 public ResourceModel Convert(R.SingleResource resource)
 {
     return(new ResourceModel()
     {
         Id = resource.Id,
         Name = resource.Name,
         Description = resource.Description,
         ResourceStatus = resource.ResourceStatus,
         ResourceStructure = resource.ResourceStructure,
         Color = resource.Color,
         TimeUnits = Enum.GetValues(typeof(SystemDefinedUnit)).Cast <SystemDefinedUnit>().ToList()
     });
 }
예제 #4
0
        public R.Resource UpdateResource(R.SingleResource resource)
        {
            Contract.Requires(resource != null);
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <R.SingleResource> repo = uow.GetRepository <R.SingleResource>();
                repo.Merge(resource);
                var merged = repo.Get(resource.Id);
                repo.Put(merged);
                uow.Commit();
            }

            return(resource);
        }
        public ResourceModel(R.SingleResource resource)
        {
            Id                    = resource.Id;
            Name                  = resource.Name;
            Description           = resource.Description;
            ResourceStatus        = resource.ResourceStatus;
            ResourceStructureName = resource.ResourceStructure.Name;
            ResourceStructure     = resource.ResourceStructure;
            Color                 = resource.Color;

            TimeUnits = Enum.GetValues(typeof(SystemDefinedUnit)).Cast <SystemDefinedUnit>().ToList();

            //ResourceStructureAttributeValue
        }
예제 #6
0
        public bool DeleteResource(R.SingleResource resource)
        {
            Contract.Requires(resource != null);
            Contract.Requires(resource.Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <R.SingleResource> repo = uow.GetRepository <R.SingleResource>();
                resource = repo.Reload(resource);
                repo.Delete(resource);
                uow.Commit();
            }

            return(true);
        }
        public ResourceManagerModel(R.SingleResource resource)
        {
            Id                    = resource.Id;
            Name                  = resource.Name;
            Description           = resource.Description;
            ResourceStructureName = resource.ResourceStructure.Name;
            if (resource.Quantity == 0)
            {
                Quantity = "no limitation";
            }
            else
            {
                Quantity = resource.Quantity.ToString();
            }

            InUse = false;
        }
예제 #8
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;
                            }
                        }
                    }
                }
            }
        }
예제 #9
0
        public R.SingleResource CreateResource(string name, string description, int quantity, string color, bool withActivity, RS.ResourceStructure resourceStructure,
                                               TimeDuration duration)
        {
            //default status is created. In this status it is not visible.
            Status   status           = Status.created;
            DateTime statusChangeDate = DateTime.Now;

            R.SingleResource resource = new R.SingleResource(resourceStructure);

            //resource.BookingTimeGranularity = bookingTimeGranularity;


            resource.Name             = name;
            resource.Description      = description;
            resource.Quantity         = quantity;
            resource.ResourceStatus   = status;
            resource.Duration         = duration;
            resource.Color            = color;
            resource.WithActivity     = withActivity;
            resource.StatusChangeDate = statusChangeDate;
            resource.ResourceStatus   = status;

            //bookingTimeGranularity.Resource = resource;

            //bookingTimeGranularity.Resource = resource;

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <R.SingleResource> repo = uow.GetRepository <R.SingleResource>();
                //IRepository<R.BookingTimeGranularity> repoB = uow.GetRepository<R.BookingTimeGranularity>();
                //resource.BookingTimeGranularity = this.CreateBookingTimeGranularity(bookingTimeGranularity.Duration, bookingTimeGranularity.LargeUnitOfTime, bookingTimeGranularity.StartTime);
                //repoB.Put(bookingTimeGranularity);
                repo.Put(resource);
                uow.Commit();
            }

            return(resource);
        }
        public Schedule CreateSchedule(DateTime startDate, DateTime endDate, BookingEvent thisEvent, R.SingleResource resource, Person forPerson, Person byPerson, IEnumerable <long> activities, int quantity, int index)
        {
            Schedule schedule = new Schedule();

            schedule.Activities   = new List <Activity>();
            schedule.StartDate    = startDate.Date;
            schedule.EndDate      = endDate.Date;
            schedule.BookingEvent = thisEvent;
            schedule.Resource     = resource;
            //schedule.Activities = activities;
            schedule.Index    = index;
            schedule.Quantity = quantity;

            if (forPerson is PersonGroup)
            {
                PersonGroup pGroup = (PersonGroup)forPerson;
                schedule.ForPerson = pGroup;
            }
            else
            {
                IndividualPerson iPerson = (IndividualPerson)forPerson;
                schedule.ForPerson = iPerson;
            }

            IndividualPerson iPersonBy = (IndividualPerson)byPerson;

            schedule.ByPerson = iPersonBy;

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                //load activites

                activities.ToList().ForEach(a => schedule.Activities.Add(uow.GetReadOnlyRepository <Activity>().Get(a)));

                IRepository <Schedule> repo = uow.GetRepository <Schedule>();
                repo.Put(schedule);
                uow.Commit();
            }

            return(schedule);
        }
예제 #11
0
 public R.SingleResource GetResourceById(long id)
 {
     R.SingleResource resource = new R.SingleResource();
     return(resource = SingleResourceRepo.Query(u => u.Id == id).FirstOrDefault());
 }
        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();
            }
        }