Exemplo n.º 1
0
        public void Handle(CreateDeepGeographicExpertise command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var person = _entities.Get <Person>().SingleOrDefault(p => p.User.Name == command.Principal.Identity.Name);

            if (person == null)
            {
                string message = string.Format("Person {0} not found.", command.Principal.Identity.Name);
                throw new Exception(message);
            }

            var createExpertiseCommand = new CreateGeographicExpertise(command.Principal)
            {
                Description = command.Description
            };

            _createGeographicExpertise.Handle(createExpertiseCommand);

            foreach (var placeId in command.PlaceIds)
            {
                var createExpertiseLocationCommand = new CreateGeographicExpertiseLocation(
                    command.Principal,
                    createExpertiseCommand.CreatedGeographicExpertise.RevisionId,
                    placeId);

                _createGeographicExpertiseLocation.Handle(createExpertiseLocationCommand);
            }

            if (!command.NoCommit)
            {
                _unitOfWork.SaveChanges();
            }

            command.CreatedGeographicExpertise   = createExpertiseCommand.CreatedGeographicExpertise;
            command.CreatedGeographicExpertiseId = command.CreatedGeographicExpertise.RevisionId;
        }
Exemplo n.º 2
0
        public void Seed()
        {
            /* ----- USF People GeographicExpertises ----- */

            { // Douglas Corarito
                Person person = _entities.Get <Person>().SingleOrDefault(x => x.FirstName == "Douglas" && x.LastName == "Corarito");
                if (person == null)
                {
                    throw new Exception("USF person Douglas Corarito not found");
                }

                User user = _entities.Get <User>().SingleOrDefault(x => x.Person.RevisionId == person.RevisionId);
                if (user == null)
                {
                    throw new Exception("USF person Douglas Corarito has no User.");
                }

                var developerRoles = new[]
                {
                    RoleName.AuthorizationAgent,
                    RoleName.EstablishmentLocationAgent,
                    RoleName.EstablishmentAdministrator,
                    RoleName.ElmahViewer,
                    RoleName.AgreementManager,
                    RoleName.AgreementSupervisor,
                    RoleName.EmployeeProfileManager,
                };
                var identity  = new GenericIdentity(user.Name);
                var principal = new GenericPrincipal(identity, developerRoles);

                CreateGeographicExpertise         createGeographicExpertiseCommand;
                CreateGeographicExpertiseLocation createGeographicExpertiseLocationCommand;
                Place  place;
                string placeName;

                // GEOGRAPHIC EXPERTISE 1
                var  entityId        = new Guid("82A4789E-7B60-489F-B0FF-79AA6BA24E19");
                bool expertiseExists = _entities.Get <GeographicExpertise>().Count(x => x.EntityId == entityId) > 0;
                if (!expertiseExists)
                {
                    createGeographicExpertiseCommand = new CreateGeographicExpertise(principal)
                    {
                        EntityId    = entityId,
                        Description = "Justo altera ut eam, sit ei cibo porro homero, verear convenire constituto id duo. Ea natum ipsum liberavisse eum. Eu mei nisl ancillae, ei quando ridens volutpat eos. Sit cu eleifend deseruisse."
                    };

                    _createGeographicExpertise.Handle(createGeographicExpertiseCommand);

                    placeName = "Brazil";
                    place     = _entities.Get <Place>().FirstOrDefault(x => x.OfficialName == placeName);
                    if (place == null)
                    {
                        string message = String.Format("{0} not found", placeName);
                        throw new Exception(message);
                    }
                    createGeographicExpertiseLocationCommand = new CreateGeographicExpertiseLocation(principal, createGeographicExpertiseCommand.CreatedGeographicExpertise.RevisionId, place.RevisionId);
                    _createGeographicExpertiseLocation.Handle(createGeographicExpertiseLocationCommand);

                    placeName = "Argentina";
                    place     = _entities.Get <Place>().FirstOrDefault(x => x.OfficialName == placeName);
                    if (place == null)
                    {
                        string message = String.Format("{0} not found", placeName);
                        throw new Exception(message);
                    }
                    createGeographicExpertiseLocationCommand = new CreateGeographicExpertiseLocation(principal, createGeographicExpertiseCommand.CreatedGeographicExpertise.RevisionId, place.RevisionId);
                    _createGeographicExpertiseLocation.Handle(createGeographicExpertiseLocationCommand);

                    _unitOfWork.SaveChanges();
                } // GEOGRAPHIC EXPERTISE 1

                // GEOGRAPHIC EXPERTISE 2
                entityId        = new Guid("8E0CE863-B3D0-44AC-87A7-8F774731CCA9");
                expertiseExists = _entities.Get <GeographicExpertise>().Count(x => x.EntityId == entityId) > 0;
                if (!expertiseExists)
                {
                    createGeographicExpertiseCommand = new CreateGeographicExpertise(principal)
                    {
                        EntityId    = entityId,
                        Description = "Vocent oblique comprehensam sit id, quo nisl corpora molestie ea. Prima liberavisse qui ne, invidunt elaboraret ullamcorper eos et, volumus qualisque hendrerit nam ut."
                    };

                    _createGeographicExpertise.Handle(createGeographicExpertiseCommand);

                    placeName = "Uruguay";
                    place     = _entities.Get <Place>().FirstOrDefault(x => x.OfficialName == placeName);
                    if (place == null)
                    {
                        string message = String.Format("{0} not found", placeName);
                        throw new Exception(message);
                    }
                    createGeographicExpertiseLocationCommand = new CreateGeographicExpertiseLocation(principal, createGeographicExpertiseCommand.CreatedGeographicExpertise.RevisionId, place.RevisionId);
                    _createGeographicExpertiseLocation.Handle(createGeographicExpertiseLocationCommand);

                    placeName = "Colombia";
                    place     = _entities.Get <Place>().FirstOrDefault(x => x.OfficialName == placeName);
                    if (place == null)
                    {
                        string message = String.Format("{0} not found", placeName);
                        throw new Exception(message);
                    }
                    createGeographicExpertiseLocationCommand = new CreateGeographicExpertiseLocation(principal, createGeographicExpertiseCommand.CreatedGeographicExpertise.RevisionId, place.RevisionId);
                    _createGeographicExpertiseLocation.Handle(createGeographicExpertiseLocationCommand);

                    placeName = "Peru";
                    place     = _entities.Get <Place>().FirstOrDefault(x => x.OfficialName == placeName);
                    if (place == null)
                    {
                        string message = String.Format("{0} not found", placeName);
                        throw new Exception(message);
                    }
                    createGeographicExpertiseLocationCommand = new CreateGeographicExpertiseLocation(principal, createGeographicExpertiseCommand.CreatedGeographicExpertise.RevisionId, place.RevisionId);
                    _createGeographicExpertiseLocation.Handle(createGeographicExpertiseLocationCommand);

                    _unitOfWork.SaveChanges();
                } // GEOGRAPHIC EXPERTISE 2
            }     // Douglas Corarito
        }
Exemplo n.º 3
0
        public void Handle(UpdateGeographicExpertise command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            /* Retrieve the expertise to update. */
            var target = _entities.Get <GeographicExpertise>().SingleOrDefault(a => a.RevisionId == command.Id);

            if (target == null)
            {
                string message = String.Format("GeographicExpertise Id {0} not found.", command.Id);
                throw new Exception(message);
            }

            /* Retrieve the expertise locations to update. */
            var targetLocations = _entities.Get <GeographicExpertiseLocation>().Where(a => a.ExpertiseId == target.RevisionId).ToArray();

            /* If target fields equal new field values, we do not proceed. */
            if ((target.Description == command.Description) &&
                targetLocations.SequenceEqual(command.Locations))
            {
                return;
            }

            /* Run through all new locations and attempt to find same in target.  If not found, create.*/
            foreach (var location in command.Locations.ToList())
            {
                var targetLocation = target.Locations.SingleOrDefault(x => x.PlaceId == location.PlaceId);
                if (targetLocation == null)
                {
                    var createGeographicExpertiseLocation = new CreateGeographicExpertiseLocation(
                        command.Principal, target.RevisionId, location.PlaceId)
                    {
                        NoCommit = true
                    };

                    _createGeographicExpertiseLocation.Handle(createGeographicExpertiseLocation);
                }
            }

            /* Delete activity locations. Run through the targets list of locations and try to find
             *  a matching one in the updated list.  If not found, it must have been deleted. */
            foreach (var location in target.Locations.ToList())
            {
                var updateLocation = command.Locations.SingleOrDefault(x => x.PlaceId == location.PlaceId);
                if (updateLocation == null)
                {
                    var deleteGeographicExpertiseLocationCommand = new DeleteGeographicExpertiseLocation(
                        command.Principal, location.RevisionId)
                    {
                        NoCommit = true
                    };

                    _deleteGeographicExpertiseLocation.Handle(deleteGeographicExpertiseLocationCommand);
                }
            }

            /* Update fields */
            target.Description        = command.Description;
            target.UpdatedOnUtc       = command.UpdatedOn.ToUniversalTime();
            target.UpdatedByPrincipal = command.Principal.Identity.Name;

            _entities.Update(target);

            if (!command.NoCommit)
            {
                _unitOfWork.SaveChanges();
            }
        }
        public void Seed()
        {
            /* ----- USF People GeographicExpertises ----- */

            { // Douglas Corarito
                Person person = _entities.Get<Person>().SingleOrDefault(x => x.FirstName == "Douglas" && x.LastName == "Corarito");
                if (person == null) throw new Exception("USF person Douglas Corarito not found");

                User user = _entities.Get<User>().SingleOrDefault(x => x.Person.RevisionId == person.RevisionId);
                if (user == null) throw new Exception("USF person Douglas Corarito has no User.");

                string[] developerRoles = new string[]
                    {
                        RoleName.AuthorizationAgent,
                        RoleName.EstablishmentLocationAgent,
                        RoleName.EstablishmentAdministrator,
                        RoleName.ElmahViewer,
                        RoleName.InstitutionalAgreementManager,
                        RoleName.InstitutionalAgreementSupervisor,
                        RoleName.EmployeeProfileManager,
                    };
                GenericIdentity identity = new GenericIdentity(user.Name);
                GenericPrincipal principal = new GenericPrincipal(identity, developerRoles);

                CreateGeographicExpertise createGeographicExpertiseCommand;
                CreateGeographicExpertiseLocation createGeographicExpertiseLocationCommand;
                Place place;
                string placeName;

                // GEOGRAPHIC EXPERTISE 1
                Guid entityId = new Guid("82A4789E-7B60-489F-B0FF-79AA6BA24E19");
                bool expertiseExists = _entities.Get<GeographicExpertise>().Count(x => x.EntityId == entityId) > 0;
                if (!expertiseExists)
                {
                    createGeographicExpertiseCommand = new CreateGeographicExpertise(principal)
                    {
                        EntityId = entityId,
                        Description = "Justo altera ut eam, sit ei cibo porro homero, verear convenire constituto id duo. Ea natum ipsum liberavisse eum. Eu mei nisl ancillae, ei quando ridens volutpat eos. Sit cu eleifend deseruisse."

                    };

                    _createGeographicExpertise.Handle(createGeographicExpertiseCommand);

                    placeName = "Brazil";
                    place = _entities.Get<Place>().FirstOrDefault(x => x.OfficialName == placeName);
                    if (place == null)
                    {
                        string message = String.Format("{0} not found", placeName);
                        throw new Exception(message);
                    }
                    createGeographicExpertiseLocationCommand = new CreateGeographicExpertiseLocation(principal, createGeographicExpertiseCommand.CreatedGeographicExpertise.RevisionId, place.RevisionId);
                    _createGeographicExpertiseLocation.Handle(createGeographicExpertiseLocationCommand);

                    placeName = "Argentina";
                    place = _entities.Get<Place>().FirstOrDefault(x => x.OfficialName == placeName);
                    if (place == null)
                    {
                        string message = String.Format("{0} not found", placeName);
                        throw new Exception(message);
                    }
                    createGeographicExpertiseLocationCommand = new CreateGeographicExpertiseLocation(principal, createGeographicExpertiseCommand.CreatedGeographicExpertise.RevisionId, place.RevisionId);
                    _createGeographicExpertiseLocation.Handle(createGeographicExpertiseLocationCommand);

                    _unitOfWork.SaveChanges();
                } // GEOGRAPHIC EXPERTISE 1

                // GEOGRAPHIC EXPERTISE 2
                entityId = new Guid("8E0CE863-B3D0-44AC-87A7-8F774731CCA9");
                expertiseExists = _entities.Get<GeographicExpertise>().Count(x => x.EntityId == entityId) > 0;
                if (!expertiseExists)
                {
                    createGeographicExpertiseCommand = new CreateGeographicExpertise(principal)
                    {
                        EntityId = entityId,
                        Description = "Vocent oblique comprehensam sit id, quo nisl corpora molestie ea. Prima liberavisse qui ne, invidunt elaboraret ullamcorper eos et, volumus qualisque hendrerit nam ut."
                    };

                    _createGeographicExpertise.Handle(createGeographicExpertiseCommand);

                    placeName = "Uruguay";
                    place = _entities.Get<Place>().FirstOrDefault(x => x.OfficialName == placeName);
                    if (place == null)
                    {
                        string message = String.Format("{0} not found", placeName);
                        throw new Exception(message);
                    }
                    createGeographicExpertiseLocationCommand = new CreateGeographicExpertiseLocation(principal, createGeographicExpertiseCommand.CreatedGeographicExpertise.RevisionId, place.RevisionId);
                    _createGeographicExpertiseLocation.Handle(createGeographicExpertiseLocationCommand);

                    placeName = "Colombia";
                    place = _entities.Get<Place>().FirstOrDefault(x => x.OfficialName == placeName);
                    if (place == null)
                    {
                        string message = String.Format("{0} not found", placeName);
                        throw new Exception(message);
                    }
                    createGeographicExpertiseLocationCommand = new CreateGeographicExpertiseLocation(principal, createGeographicExpertiseCommand.CreatedGeographicExpertise.RevisionId, place.RevisionId);
                    _createGeographicExpertiseLocation.Handle(createGeographicExpertiseLocationCommand);

                    placeName = "Peru";
                    place = _entities.Get<Place>().FirstOrDefault(x => x.OfficialName == placeName);
                    if (place == null)
                    {
                        string message = String.Format("{0} not found", placeName);
                        throw new Exception(message);
                    }
                    createGeographicExpertiseLocationCommand = new CreateGeographicExpertiseLocation(principal, createGeographicExpertiseCommand.CreatedGeographicExpertise.RevisionId, place.RevisionId);
                    _createGeographicExpertiseLocation.Handle(createGeographicExpertiseLocationCommand);

                    _unitOfWork.SaveChanges();
                } // GEOGRAPHIC EXPERTISE 2

            } // Douglas Corarito
        }