Exemplo n.º 1
0
        public Offhire CreateOffhire(
            long referenceNumber,
            DateTime startDateTime,
            DateTime endDateTime,
            Company introducer,
            VesselInCompany vesselInCompany,
            Voyage voyage,
            ActivityLocation offhireLocation,
            DateTime voucherDate,
            Currency voucherCurrency)
        {
            var offhire = new Offhire(
                referenceNumber,
                startDateTime,
                endDateTime,
                introducer,
                vesselInCompany,
                voyage,
                offhireLocation,
                voucherDate,
                voucherCurrency,
                this.offhireDomainService,
                this.offhireManagementSystemDomainService,
                this.vesselDomainService,
                this.voyageDomainService,
                this.companyDomainService,
                this.activityLocationDomainService,
                this.currencyDomainService);

            var init = this.workflowRepository.Single(c => c.WorkflowEntity == WorkflowEntities.Offhire && c.CurrentWorkflowStage == WorkflowStages.Initial);
            if (init == null)
                throw new ObjectNotFound("OffhireInitialStep");

            var offhireWorkflow = new OffhireWorkflowLog(offhire, WorkflowEntities.Offhire, DateTime.Now, WorkflowActions.Init,
                //TODO: Fake ActorId
                    1101, "", init.Id, true);

            offhire.ApproveWorkflows.Add(offhireWorkflow);

            offhireConfigurator.Configure(offhire);

            return offhire;
        }
        public async Task SetAsync(Guid activityId, ActivityLocation location)
        {
            var oldLocation = await _locationRepository
                              .AsQueryable()
                              .SingleOrDefaultAsync(l => l.ActivityId == activityId);

            if (oldLocation is null)
            {
                if (location is null)
                {
                    return;
                }

                var newLocation = new ActivityLocationEntity()
                {
                    ActivityId   = activityId,
                    Address      = location.Address,
                    ShortAddress = location.ShortAddress
                };

                await _locationRepository.AddAsync(newLocation);
            }
            else
            {
                if (location?.Address == null || location.ShortAddress == null)
                {
                    await _locationRepository.DeleteAsync(oldLocation.Id);
                }
                else
                {
                    oldLocation.Address      = location.Address;
                    oldLocation.ShortAddress = location.ShortAddress;
                    await _locationRepository.UpdateAsync(oldLocation);
                }
            }
        }
        public void Set(Guid activityId, ActivityLocation location)
        {
            var oldLocation = _locationRepository
                              .AsQueryable()
                              .SingleOrDefault(l => l.ActivityId == activityId);

            if (oldLocation is null)
            {
                if (location is null)
                {
                    return;
                }

                var newLocation = new ActivityLocationEntity()
                {
                    ActivityId   = activityId,
                    Address      = location.Address,
                    ShortAddress = location.ShortAddress
                };

                _locationRepository.Add(newLocation);
            }
            else
            {
                if (location?.Address == null || location.ShortAddress == null)
                {
                    _locationRepository.Delete(oldLocation);
                }
                else
                {
                    oldLocation.Address      = location.Address;
                    oldLocation.ShortAddress = location.ShortAddress;
                    _locationRepository.Update(oldLocation);
                }
            }
        }
Exemplo n.º 4
0
        private bool AddNewManualViolationToCDS(ManualViolationDTO manualViolation)
        {
            try
            {
                if (manualViolation == null)
                {
                    corruptedRowsCount++;
                    return(true);
                }

                var oldManualViolation = GetManualViolationFromCDS(manualViolation.ViolationNumber);

                if (oldManualViolation != null)
                {
                    duplicatedRowsCount++;
                    return(true);
                }

                var activityReason            = context.ActivityReasonDIMs.Where(x => x.Description == manualViolation.Reason.Trim()).FirstOrDefault();
                var activityCategory          = context.ActivityCategoryDIMs.Where(x => x.Description == "Manual Violation").FirstOrDefault();
                var source                    = context.Sources.Where(x => x.SourceName == "ManualViolation").FirstOrDefault();
                var itemRegistrationAuthority = context.ItemRegistrationAuthorityDIMs.Where(x => x.Description == ((manualViolation.PlateSource != null && manualViolation.PlateSource.Trim().Length > 0) ? manualViolation.PlateSource : "Undefined")).FirstOrDefault();
                var itemRegistrationKind      = context.ItemRegistrationPlateKindDIMs.Where(x => x.Description == ((manualViolation.PlateKind != null && manualViolation.PlateKind.Trim().Length > 0) ? manualViolation.PlateKind : "Undefined")).FirstOrDefault();
                var itemRegistrationCategory  = context.ItemRegistrationPlateCategoryDIMs.Where(x => x.Description == "Undefined").FirstOrDefault();
                var itemRegistrationCode      = context.ItemRegistrationPlateCodeDIMs.Where(x => x.Description == "Undefined").FirstOrDefault();
                var itemCategory              = context.ItemCategoryDIMs.Where(x => x.Description == (manualViolation.VehicleType.Trim().Length > 0 ? manualViolation.VehicleType : "Undefined")).FirstOrDefault();
                var itemInvolvement           = context.ItemInvolvementDIMs.Where(x => x.Description == "Manual Violation Vehicle").FirstOrDefault();
                var personInvolvement         = context.PersonInvolvementDIMs.Where(x => x.Description == "Manual Violation Vehicle").FirstOrDefault();
                var locationInvolvement       = context.LocationInvolvementDIMs.Where(x => x.Description == "Manual Violation Vehicle").FirstOrDefault();
                var personCategory            = context.PersonCategoryDIMs.Where(x => x.Description == (manualViolation.AgeClass.Trim().Length > 0 ? manualViolation.AgeClass : "Undefined")).FirstOrDefault();
                var personGender              = context.PersonGenderDIMs.Where(x => x.Description == (manualViolation.Gender.Trim().Length > 0 ? manualViolation.Gender : "Undefined")).FirstOrDefault();
                var location                  = context.Locations.Where(x => x.LocationName == (manualViolation.StreetName.Trim().Length > 0 ? manualViolation.StreetName : "Undefined")).FirstOrDefault();
                var educationCategory         = context.EducationCategoryDIMs.Where(x => x.Description == (manualViolation.LevelOfEducation.Trim().Length > 0 ? manualViolation.LevelOfEducation : "Undefined")).FirstOrDefault();
                var educationDegree           = context.EducationDegreeDIMs.Where(x => x.Description == "Undefined").FirstOrDefault();
                var organization              = context.Organizations.Where(x => x.Name == "Undefined").FirstOrDefault();
                var educationStatus           = context.EducationStatusDIMs.Where(x => x.Description == "Undefined").FirstOrDefault();
                var locationDatum             = context.LocationDatumDIMs.Where(x => x.Description == "Undefined").FirstOrDefault();
                var locationCategory          = context.LocationCategoryDIMs.Where(x => x.Description == "Undefined").FirstOrDefault();
                var status                    = context.StatusDIMs.Where(x => x.Description == "Undefined").FirstOrDefault();


                if (activityReason == null)
                {
                    activityReason = new ActivityReasonDIM
                    {
                        Code        = "MVR-" + manualViolation.ReasonCode.ToString(),
                        Description = manualViolation.Reason
                    };

                    activityReason = context.ActivityReasonDIMs.Add(activityReason);
                    context.SaveChanges();
                }

                if (activityCategory == null)
                {
                    activityCategory = new ActivityCategoryDIM
                    {
                        Description = "Manual Violation",
                        Code        = "MANUALVIOLATION"
                    };

                    activityCategory = context.ActivityCategoryDIMs.Add(activityCategory);
                    context.SaveChanges();
                }

                if (source == null)
                {
                    source = new Source()
                    {
                        Description      = "ManualViolation",
                        SourceName       = "ManualViolation",
                        SourcePolicyId   = 1,
                        SourceCategoryId = 1
                    };

                    source = context.Sources.Add(source);
                    context.SaveChanges();
                }

                if (itemRegistrationAuthority == null)
                {
                    itemRegistrationAuthority = new ItemRegistrationAuthorityDIM
                    {
                        Description = (manualViolation.PlateSource != null && manualViolation.PlateSource.Trim().Length > 0) ? manualViolation.PlateSource : "Undefined",
                        Code        = GetRandomNumber()
                    };

                    itemRegistrationAuthority = context.ItemRegistrationAuthorityDIMs.Add(itemRegistrationAuthority);
                    context.SaveChanges();
                }

                if (itemRegistrationKind == null)
                {
                    itemRegistrationKind = new ItemRegistrationPlateKindDIM
                    {
                        Description = (manualViolation.PlateKind != null && manualViolation.PlateKind.Trim().Length > 0) ? manualViolation.PlateKind : "Undefined",
                        Code        = GetRandomNumber()
                    };

                    itemRegistrationKind = context.ItemRegistrationPlateKindDIMs.Add(itemRegistrationKind);
                    context.SaveChanges();
                }

                if (itemRegistrationCategory == null)
                {
                    itemRegistrationCategory = new ItemRegistrationPlateCategoryDIM
                    {
                        Description = "Undefined",
                        Code        = GetRandomNumber()
                    };

                    itemRegistrationCategory = context.ItemRegistrationPlateCategoryDIMs.Add(itemRegistrationCategory);
                    context.SaveChanges();
                }

                if (itemRegistrationCode == null)
                {
                    itemRegistrationCode = new ItemRegistrationPlateCodeDIM
                    {
                        Description = "Undefined",
                        Code        = GetRandomNumber()
                    };

                    itemRegistrationCode = context.ItemRegistrationPlateCodeDIMs.Add(itemRegistrationCode);
                    context.SaveChanges();
                }

                if (itemCategory == null)
                {
                    itemCategory = new ItemCategoryDIM
                    {
                        Description = manualViolation.VehicleType.Trim().Length > 0 ? manualViolation.VehicleType : "Undefined",
                        Code        = GetRandomNumber()
                    };

                    itemCategory = context.ItemCategoryDIMs.Add(itemCategory);
                    context.SaveChanges();
                }

                if (itemInvolvement == null)
                {
                    itemInvolvement = new ItemInvolvementDIM
                    {
                        Description = "Manual Violation Vehicle",
                        Code        = GetRandomNumber()
                    };

                    itemInvolvement = context.ItemInvolvementDIMs.Add(itemInvolvement);
                    context.SaveChanges();
                }

                if (personInvolvement == null)
                {
                    personInvolvement = new PersonInvolvementDIM
                    {
                        Description = "Manual Violation Vehicle",
                        Code        = GetRandomNumber()
                    };

                    personInvolvement = context.PersonInvolvementDIMs.Add(personInvolvement);
                    context.SaveChanges();
                }

                if (locationInvolvement == null)
                {
                    locationInvolvement = new LocationInvolvementDIM
                    {
                        Description = "Manual Violation Vehicle",
                        Code        = GetRandomNumber()
                    };

                    locationInvolvement = context.LocationInvolvementDIMs.Add(locationInvolvement);
                    context.SaveChanges();
                }

                var item = new Item
                {
                    ItemCategoryId = itemCategory.ItemCategoryId,
                    SourceId       = source.SourceId,
                };

                item = context.Items.Add(item);
                context.SaveChanges();

                var itemReg = new ItemRegistration
                {
                    ItemRegistrationAuthorityId     = itemRegistrationAuthority.ItemRegistrationAuthorityId,
                    ItemRegistrationPlateCategoryId = itemRegistrationCategory.ItemRegistrationPlateCategoryId,
                    ItemRegistrationPlateCodeId     = itemRegistrationCode.ItemRegistrationPlateCodeId,
                    ItemRegistrationPlateKindId     = itemRegistrationKind.ItemRegistrationPlateKindId,
                    SourceId            = source.SourceId,
                    PlateIdentification = "Undefiend",
                    ItemId = item.ItemId
                };

                itemReg = context.ItemRegistrations.Add(itemReg);
                context.SaveChanges();

                if (personCategory == null)
                {
                    personCategory = new PersonCategoryDIM
                    {
                        Code        = GetRandomNumber(),
                        Description = manualViolation.AgeClass.Trim().Length > 0 ? manualViolation.AgeClass : "Undefined"
                    };

                    personCategory = context.PersonCategoryDIMs.Add(personCategory);
                    context.SaveChanges();
                }

                if (personGender == null)
                {
                    personGender = new PersonGenderDIM
                    {
                        Code        = GetRandomNumber(),
                        Description = (manualViolation.Gender.Trim().Length > 0 ? manualViolation.Gender : "Undefined")
                    };

                    personGender = context.PersonGenderDIMs.Add(personGender);
                    context.SaveChanges();
                }

                if (educationCategory == null)
                {
                    educationCategory = new EducationCategoryDIM
                    {
                        Code        = GetRandomNumber(),
                        Description = manualViolation.LevelOfEducation.Trim().Length > 0 ? manualViolation.LevelOfEducation : "Undefined"
                    };

                    educationCategory = context.EducationCategoryDIMs.Add(educationCategory);
                    context.SaveChanges();
                }

                if (educationDegree == null)
                {
                    educationDegree = new EducationDegreeDIM
                    {
                        Code        = GetRandomNumber(),
                        Description = "Undefined"
                    };

                    educationDegree = context.EducationDegreeDIMs.Add(educationDegree);
                    context.SaveChanges();
                }

                if (educationStatus == null)
                {
                    educationStatus = new EducationStatusDIM
                    {
                        Code        = GetRandomNumber(),
                        Description = "Undefined"
                    };

                    educationStatus = context.EducationStatusDIMs.Add(educationStatus);
                    context.SaveChanges();
                }

                if (organization == null)
                {
                    organization = new Organization
                    {
                        Name        = "Undefined",
                        Description = "Undefined",
                        SourceId    = source.SourceId
                    };

                    organization = context.Organizations.Add(organization);
                    context.SaveChanges();
                }

                Person person = new Person
                {
                    SourceId         = source.SourceId,
                    LastName         = manualViolation.OwnerName,
                    OriginalIdent    = manualViolation.OwnerTCFNumber,
                    PersonCategoryId = personCategory.PersonCategoryId,
                    PersonGenderId   = personGender.PersonGenderId,
                    Age = manualViolation.Age
                };

                person = context.People.Add(person);
                context.SaveChanges();

                var personDriverLicense = new PersonDriverLicense
                {
                    EffectiveDate = manualViolation.LicenseIssueDate,
                    PersonDriverLicenseDescription = manualViolation.LicenseSource,
                    PersonId = person.PersonId,
                    SourceId = source.SourceId
                };

                personDriverLicense = context.PersonDriverLicenses.Add(personDriverLicense);
                context.SaveChanges();

                var levelOfEducation = new PersonEducation
                {
                    PersonEducationDescription = manualViolation.LevelOfEducation.Trim().Length > 0 ? manualViolation.LevelOfEducation : "Undefined",
                    PersonId                = person.PersonId,
                    SourceId                = source.SourceId,
                    EducationCategoryId     = educationCategory.EducationCategoryId,
                    EducationDegreeId       = educationDegree.EducationDegreeId,
                    EducationStatusId       = educationStatus.EducationStatusId,
                    EducationOrganizationId = organization.OrganizationId
                };

                levelOfEducation = context.PersonEducations.Add(levelOfEducation);
                context.SaveChanges();

                if (locationDatum == null)
                {
                    locationDatum = new LocationDatumDIM
                    {
                        Code        = GetRandomNumber(),
                        Description = "Undefined"
                    };

                    locationDatum = context.LocationDatumDIMs.Add(locationDatum);
                    context.SaveChanges();
                }

                if (locationCategory == null)
                {
                    locationCategory = new LocationCategoryDIM
                    {
                        Code        = GetRandomNumber(),
                        Description = "Undefined"
                    };

                    locationCategory = context.LocationCategoryDIMs.Add(locationCategory);
                    context.SaveChanges();
                }

                //GeoPoint
                var geoPoint = DbGeometry.FromText(
                    "POINT(" + (manualViolation.Lon) + " " +
                    (manualViolation.Lat) + ")", 4326);

                if (location == null)
                {
                    location = new Location
                    {
                        Latitude           = manualViolation.Lat,
                        Longitude          = manualViolation.Lon,
                        OrgLat             = manualViolation.Lat.ToString(),
                        OrgLong            = manualViolation.Lon.ToString(),
                        GeoPoint           = geoPoint,
                        Address1           = (manualViolation.StreetName.Trim().Length > 0 ? manualViolation.StreetName : "Undefined"),
                        LocationName       = (manualViolation.StreetName.Trim().Length > 0 ? manualViolation.StreetName : "Undefined"),
                        Description        = (manualViolation.StreetName.Trim().Length > 0 ? manualViolation.StreetName : "Undefined"),
                        SourceId           = source.SourceId,
                        locationDatumId    = locationDatum.LocationDatumId,
                        LocationCategoryId = locationCategory.LocationCategoryId
                    };

                    location = context.Locations.Add(location);
                    context.SaveChanges();
                }

                if (status == null)
                {
                    status = new StatusDIM
                    {
                        Code        = GetRandomNumber(),
                        Description = "Undefined"
                    };

                    status = context.StatusDIMs.Add(status);
                    context.SaveChanges();
                }

                Activity activity = new Activity()
                {
                    ActivityDate       = manualViolation.ViolationDate,
                    OriginalIdent      = manualViolation.ViolationNumber,
                    SourceId           = source.SourceId,
                    ActivityReasonId   = activityReason.ActivityReasonId,
                    ActivityCategoryId = activityCategory.ActivityCategoryId,
                    StatusId           = status.StatusId
                };

                activity = context.Activities.Add(activity);
                context.SaveChanges();

                var activityLocation = new ActivityLocation()
                {
                    LocationId                  = location.LocationId,
                    ActivityId                  = activity.ActivityId,
                    CreateDateTimeStamp         = DateTime.Now,
                    ModifiedDateTimeStamp       = DateTime.Now,
                    ActivityLocationDescription = "Manual Violation Location",
                    SourceId = source.SourceId,
                    LocationInvolvementId = locationInvolvement.LocationInvolvementId
                };

                context.ActivityLocations.Add(activityLocation);
                context.SaveChanges();

                var activityItem = new ActivityItem
                {
                    ItemId                = item.ItemId,
                    ActivityId            = activity.ActivityId,
                    CreateDateTimeStamp   = DateTime.Now,
                    ModifiedDateTimeStamp = DateTime.Now,
                    ItemInvolvementId     = itemInvolvement.ItemInvolvementId,
                    SourceId              = source.SourceId
                };

                context.ActivityItems.Add(activityItem);
                context.SaveChanges();

                var activityPerson = new ActivityPerson
                {
                    PersonId              = person.PersonId,
                    ActivityId            = activity.ActivityId,
                    CreateDateTimeStamp   = DateTime.Now,
                    ModifiedDateTimeStamp = DateTime.Now,
                    SourceId              = source.SourceId,
                    PersonInvolvementId   = personInvolvement.PersonInvolvementId
                };

                context.ActivityPersons.Add(activityPerson);
                context.SaveChanges();

                insertedRowsCount++;

                return(true);
            }

            catch (DbEntityValidationException ex)
            {
                Utility.WriteLog(ex);
                corruptedRowsCount++;
                return(false);
            }
            catch (DbUpdateException ex)
            {
                Utility.WriteLog(ex);
                corruptedRowsCount++;
                return(false);
            }
            catch (EntityCommandCompilationException ex)
            {
                Utility.WriteLog(ex);
                corruptedRowsCount++;
                return(false);
            }
            catch (EntityCommandExecutionException ex)
            {
                Utility.WriteLog(ex);
                corruptedRowsCount++;
                return(false);
            }
            catch (Exception ex)
            {
                Utility.WriteLog(ex);
                corruptedRowsCount++;
                return(false);
            }
        }
Exemplo n.º 5
0
 public virtual ActionResult HeaderLink(ActivityLocation location)
 {
     return(PartialView(LocationHeaderLinkViewPath, location));
 }