Esempio n. 1
0
        /// <summary>
        /// Update the project number for the specified 'project' with the specified 'projectNumber'.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="project"></param>
        /// <param name="projectNumber"></param>
        public static void UpdateProjectNumber(this PimsContext context, Project project, string projectNumber)
        {
            project.ProjectNumber = projectNumber;
            context.Update(project);

            project.Properties.ForEach(p =>
            {
                context.Update(p.UpdateProjectNumber(projectNumber));
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Dispose properties from project, during the disposed workflow status.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="project"></param>
        /// <returns></returns>
        public static void DisposeProjectProperties(this PimsContext context, Entity.Project project)
        {
            var disposed = context.PropertyClassifications.Find(4) ?? throw new KeyNotFoundException("Classification 'Disposed' not found.");

            project.Properties.ForEach(p =>
            {
                switch (p.PropertyType)
                {
                case (Entity.PropertyTypes.Land):
                    if (p.Parcel == null)
                    {
                        throw new InvalidOperationException("Unable to update parcel status.");
                    }
                    p.Parcel.ClassificationId = disposed.Id;
                    p.Parcel.AgencyId         = null;
                    break;

                case (Entity.PropertyTypes.Building):
                    if (p.Building == null)
                    {
                        throw new InvalidOperationException("Unable to update building status.");
                    }
                    p.Building.ClassificationId = disposed.Id;
                    p.Building.AgencyId         = null;
                    break;
                }
                context.Update(p);
            });
        }
Esempio n. 3
0
 /// <summary>
 /// Release properties from project, such as during the deny or cancelled statuses
 /// </summary>
 /// <param name="context"></param>
 /// <param name="project"></param>
 /// <returns></returns>
 public static void ReleaseProjectProperties(this PimsContext context, Entity.Project project)
 {
     project.Properties.ForEach(p =>
     {
         context.Update(p.UpdateProjectNumber(null));
     });
 }
Esempio n. 4
0
        /// <summary>
        /// Dispose properties from project, during the disposed workflow status.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="project"></param>
        /// <returns></returns>
        public static void DisposeProjectProperties(this PimsContext context, Entity.Project project)
        {
            var disposed      = context.PropertyClassifications.AsNoTracking().FirstOrDefault(c => c.Name == "Disposed") ?? throw new KeyNotFoundException("Classification 'Disposed' not found.");
            var parentParcels = GetSubdivisionParentParcels(project);

            DisposeSubdivisionParentParcels(context, parentParcels);
            project.Properties.Where(p => !parentParcels.Any(pp => pp.Id == p.Id)).ForEach(p =>
            {
                switch (p.PropertyType)
                {
                case (Entity.PropertyTypes.Land):
                    if (p.Parcel == null)
                    {
                        throw new InvalidOperationException("Unable to update parcel status.");
                    }
                    p.Parcel.ClassificationId = disposed.Id;
                    p.Parcel.AgencyId         = null;
                    p.Parcel.PropertyTypeId   = (int)PropertyTypes.Land; // all subdivisions should be transitioned to parcels after they are disposed.
                    p.Parcel.Parcels.Clear();                            // remove all references to parent parcels.
                    break;

                case (Entity.PropertyTypes.Building):
                    if (p.Building == null)
                    {
                        throw new InvalidOperationException("Unable to update building status.");
                    }
                    p.Building.ClassificationId = disposed.Id;
                    p.Building.AgencyId         = null;
                    break;
                }
                context.Update(p);
            });
        }
Esempio n. 5
0
 /// <summary>
 /// Transfer Project properties to a new agency with updated classifications
 /// </summary>
 /// <param name="context"></param>
 /// <param name="originalProject"></param>
 /// <param name="project"></param>
 /// <returns></returns>
 public static void TransferProjectProperties(this PimsContext context, Entity.Project originalProject, Entity.Project project)
 {
     originalProject.Properties.ForEach(p =>
     {
         var matchingProperty = project.Properties.First(property => p.Id == property.Id);
         context.Update(p.UpdateProjectProperty(matchingProperty));
     });
 }
Esempio n. 6
0
        /// <summary>
        /// Update the project number for the specified 'project' with the specified 'projectNumber'.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="project"></param>
        /// <param name="projectNumber"></param>
        public static void UpdateProjectNumber(this PimsContext context, Project project, string projectNumber)
        {
            project.ProjectNumber = projectNumber;
            context.Update(project);

            project.Properties.ForEach(p =>
            {
                if (p.PropertyType == PropertyTypes.Land && p.Parcel == null)
                {
                    p.Parcel = context.Parcels.Find(p.ParcelId);
                }
                else if (p.PropertyType == PropertyTypes.Building && p.Building == null)
                {
                    p.Building = context.Buildings.Find(p.BuildingId);
                }

                context.Update(p.UpdateProjectNumber(projectNumber));
            });
        }
Esempio n. 7
0
        /// <summary>
        /// Disposes parent parcels of subdivisions by setting the classification to subdivided
        /// </summary>
        /// <param name="context"></param>
        /// <param name="parentParcels"></param>
        public static void DisposeSubdivisionParentParcels(this PimsContext context, IEnumerable <Parcel> parentParcels)
        {
            var subdivided = context.PropertyClassifications.AsNoTracking().FirstOrDefault(c => c.Name == "Subdivided") ?? throw new KeyNotFoundException("Classification 'Subdivided' not found.");

            parentParcels.ForEach(parentParcel =>
            {
                parentParcel.ClassificationId = subdivided.Id;
                context.Update(parentParcel);
            });
        }
Esempio n. 8
0
        /// <summary>
        /// Transfer Project properties to a new agency with updated classifications
        /// </summary>
        /// <param name="context"></param>
        /// <param name="originalProject"></param>
        /// <param name="project"></param>
        /// <returns></returns>
        public static void TransferProjectProperties(this PimsContext context, Entity.Project originalProject, Entity.Project project)
        {
            var parentParcels = originalProject.GetSubdivisionParentParcels();

            context.DisposeSubdivisionParentParcels(parentParcels);
            var propertiesWithNoSubdivisions = originalProject.Properties.Where(p => !parentParcels.Any(pp => p.Parcel?.Id == pp.Id));

            propertiesWithNoSubdivisions.ForEach(p =>
            {
                var matchingProperty = project.Properties.First(property => p.Id == property.Id);
                context.Update(p.UpdateProjectProperty(matchingProperty));
            });
        }