private bool AddNewDocument()
        {
            bool res = true;
            var  nd  = new IdentificationDocument();

            nd.FirstName          = mFirstName;
            nd.LastName           = mLastName;
            nd.MiddleName         = mMiddleName;
            nd.DocumentType       = mDocumentType;
            nd.DocumentNumber     = mDocumentNumber;
            nd.DocumentSerial     = mDocumentSerial;
            nd.DocumentDate       = mDocumentDate;
            nd.DocumentIssuer     = mDocumentIssuer;
            nd.DocumentIssuerCode = mDocumentIssuerCode;
            using (var db = new IdentificationDocumentContext())
            {
                var docs = db.Documents;
                foreach (var d in docs)
                {
                    if (nd.Equals(d))
                    {
                        res = false;
                        break;
                    }
                }
                if (res)
                {
                    db.Documents.Add(nd);
                    db.SaveChanges();
                }
            }
            return(res);
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
//            <!-- connectionString="Data Source=masproject.database.windows.net;Initial Catalog=MasProject;Persist Security Info=False;User ID=s15400;Password=qV8NuTHR;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" -->
//            using (var context = new AirportContext())
//            {
            DocumentType docType;

            Enum.TryParse("Internal Passport", out docType);
            var idDoc = new IdentificationDocument
            {
                CountryOfIssuance = "Temp",
                DocumentNumber    = "123456",
                DocumentType      = docType,
                ExpirationDate    = new DateTime(2030, 10, 10),
                PassportSeries    = "ABC"
            };
            var documentId = DatabaseHelper.AddIdentificationDocument(idDoc);
            var person     = new Person
            {
                DateOfBirth = new DateTime(1998, 5, 5),
                FirstName   = "Abby",
                LastName    = "Gail"
            };
            var personId    = DatabaseHelper.AddPerson(person);
            var passengerId = DatabaseHelper.AddPassenger(documentId, personId);
//                DatabaseHelper.AddPassengerToReservation(_reservation.ReservationId, passengerId);
//                _reservation = DatabaseHelper.GetReservationById(_reservation.ReservationId);
//                _form.RefreshData();
//                Close();
//            }
        }
Esempio n. 3
0
        private void okButton_Click(object sender, EventArgs e)
        {
            DocumentType docType;

            Enum.TryParse(idTypeComboBox.SelectedText, out docType);
            var idDoc = new IdentificationDocument
            {
                CountryOfIssuance = countryTextField.Text,
                DocumentNumber    = idNumberTextBox.Text,
                DocumentType      = docType,
                ExpirationDate    = expireDatePicker.Value,
                PassportSeries    = seriesTextBox.Text
            };
            var documentId = DatabaseHelper.AddIdentificationDocument(idDoc);
            var person     = new Person
            {
                DateOfBirth = dateBirthPicker.Value,
                FirstName   = firstNameTextField.Text,
                LastName    = lastNameTextField.Text
            };
            var personId    = DatabaseHelper.AddPerson(person);
            var passengerId = DatabaseHelper.AddPassenger(documentId, personId);

            DatabaseHelper.AddPassengerToReservation(_reservation.ReservationId, passengerId);
            _reservation = DatabaseHelper.GetReservationById(_reservation.ReservationId);
            _form.RefreshData();
            Close();
        }
Esempio n. 4
0
        public static int AddIdentificationDocument(IdentificationDocument document)
        {
            using (var context = new AirportContext())
            {
                context.IdentificationDocuments.Add(document);
                context.SaveChanges();
            }

            return(document.IdentificationDocumentId);
        }
        public bool RemoveIdentificationDocument(int id_persona, int id_documento)
        {
            IdentificationDocument doc = db.Registry_GetIdentificationDocument(id_documento, id_persona);
            var list = db.GetList <IdentificationDocument>(id_persona);

            if (doc == null || list.Count <= 1)
            {
                return(false);
            }
            doc.SetAttivo(false);
            return(db.UpdateDataFileItem(doc));
        }
        public Response <int> AddDocument([FromBody] IdentificationDocument document)
        {
            var checkCode = CheckLoginAndPerson(document);

            if (checkCode != ResponseCode.OK)
            {
                return(CreateResponse <int>(-1, checkCode));
            }
            bool res = persons.AddIdentificationDocument(document);

            return(CreateResponse(res ? document.Id : -1, res ? ResponseCode.OK : ResponseCode.FAIL));
        }
        public async Task <IdentificationDocument> CreateIdentificationDocument(int enrolleeId, Guid documentGuid, string filename)
        {
            var identificationDocument = new IdentificationDocument
            {
                DocumentGuid = documentGuid,
                EnrolleeId   = enrolleeId,
                Filename     = filename,
                UploadedDate = DateTimeOffset.Now
            };

            _context.IdentificationDocuments.Add(identificationDocument);

            await _context.SaveChangesAsync();

            return(identificationDocument);
        }
        // Aggiunge o aggiorna un documento
        public bool AddIdentificationDocument(IdentificationDocument document)
        {
            var file_ext = document.GetFileExtension();

            byte[] file = file_ext.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase) ?
                          Convert.FromBase64String(document.FileUpload.FirstOrDefault()) :
                          FileUtils.ConvertB64ImagesToPDF(document.FileUpload.ToArray());

            // Crea oggetto documento
            bool isUpdate = document.Id > 0;

            // Salvataggio file e generazione nome
            string filename = string.Format("{0:D6}_{1:D2}_{2}_{3}", document.PersonId, (int)document.Type, StringUtils.RandomString(), document.Filename);

            document.Filename = filename;
            if (FileUtils.WriteFile(StudioServicesConfig.IDENTIFICATIONS_FOLDER, document.PersonId.ToString("D6"), filename, file))
            {
                document.SetAttivo(true);
                if (db.Save(document))
                {
                    return(true);
                }
                else
                {
                    if (!isUpdate) // cancella il file solo se è un nuovo inserimento
                    {
                        FileUtils.Delete(StudioServicesConfig.IDENTIFICATIONS_FOLDER, filename);
                    }
                    return(false);
                }
            }
            else
            {
                // Impossibile salvare il file
                return(false);
            }
        }
Esempio n. 9
0
        public static void Configure(IMapperConfigurationExpression cfg)
        {
            cfg.CreateMap <PostalAddress, PostalAddress>();
            cfg.CreateMap <Coordinates, Coordinates>();
            cfg.CreateMap <ApplicationDocument, GdprApplicationDocument>();
            cfg.CreateMap <JObject, IndividualParty>()
            .ForMember(dest => dest.GivenName, opt => opt.MapFrom(obj => obj["given-name"].ToString()))
            .ForMember(dest => dest.Surname, opt => opt.MapFrom(obj => obj["surname"].ToString()))
            .ForMember(dest => dest.ParentName, opt => opt.MapFrom(obj => obj["parent-name"].ToString()))
            .ForMember(dest => dest.CustomerName, opt => opt.MapFrom(obj => obj["customer-name"].ToString()))
            .ForMember(dest => dest.CustomerNumber, opt => opt.MapFrom(obj => obj["party-number"].ToString()))
            .ForMember(dest => dest.ProfileImageUrl, opt => opt.MapFrom(obj => obj["profile-image-url"].ToString()))
            .ForMember(dest => dest.IdentificationNumber, opt => opt.MapFrom(obj => obj["primary-id"]["number"].ToString()))
            .ForMember(dest => dest.CustomerSegment, opt => opt.MapFrom(obj => obj["customer"]["segment"].ToString()))
            .ForMember(dest => dest.PrimarySegment, opt => opt.MapFrom(obj => obj["customer"]["segment"].ToString()))
            .ForMember(dest => dest.MaritalStatus, opt => opt.MapFrom(obj => obj["marital-status"].ToString()))
            .ForMember(dest => dest.PlaceOfBirth, opt => opt.MapFrom(obj => obj["place-of-birth"].ToString()))
            .ForMember(dest => dest.DateOfBirth, opt => opt.MapFrom(obj => DateTime.Parse(obj["birth-date"].ToString())))
            .AfterMap((src, dest) =>
            {
                var cp           = ((JArray)src["contact-points"]).ToList();
                var legalAddress = cp.Where(x => x["method"].ToString().Equals("postal") && x["usage"].ToString().Equals("legal")).FirstOrDefault();
                if (legalAddress != null)
                {
                    var coordinates     = dest.LegalAddress.Coordinates;
                    var legalAddressObj = (PostalAddress)CaseUtil.ConvertFromJsonToObject(legalAddress["address"].ToString(), typeof(PostalAddress));
                    var newCoordinates  = AutoMapper.Mapper.Map(legalAddressObj.Coordinates, coordinates, typeof(Coordinates), typeof(Coordinates));
                    AutoMapper.Mapper.Map(legalAddressObj, dest.LegalAddress, typeof(PostalAddress), typeof(PostalAddress));
                    dest.LegalAddress.Coordinates = coordinates;
                }
                var contactAddress = cp.Where(x => x["method"].ToString().Equals("postal") && x["usage"].ToString().Equals("home")).FirstOrDefault();
                if (contactAddress != null)
                {
                    var coordinates       = dest.ContactAddress.Coordinates;
                    var contactAddressObj = (PostalAddress)CaseUtil.ConvertFromJsonToObject(contactAddress["address"].ToString(), typeof(PostalAddress));
                    var newCoordinates    = AutoMapper.Mapper.Map(contactAddressObj.Coordinates, coordinates, typeof(Coordinates), typeof(Coordinates));
                    AutoMapper.Mapper.Map(contactAddressObj, dest.ContactAddress, typeof(PostalAddress), typeof(PostalAddress));
                    dest.ContactAddress.Coordinates = coordinates;
                }
                var identificationKind = EnumUtils.ToEnum <IdentificationKind>(src["primary-id"]["kind"].ToString());
                if (identificationKind != null)
                {
                    dest.IdentificationNumberKind = identificationKind.Value;
                }

                var gender = EnumUtils.ToEnum <Gender>(src["gender"].ToString());
                if (gender != null)
                {
                    dest.Gender = gender.Value;
                }
                if (src["customer"]["kind"].ToString().EndsWith("resident"))
                {
                    dest.ResidentialStatus = src["customer"]["kind"].ToString();
                }
                var mobilePhone = cp.Where(x => x["method"].ToString().Equals("gsm") && x["usage"].ToString().Equals("default")).FirstOrDefault();
                if (mobilePhone != null)
                {
                    dest.MobilePhone = mobilePhone["address"]["formatted"].ToString();
                }
                var homePhoneNumber = cp.Where(x => x["method"].ToString().Equals("pstn") && x["usage"].ToString().Equals("default")).FirstOrDefault();
                if (homePhoneNumber != null)
                {
                    dest.HomePhoneNumber = homePhoneNumber["address"]["formatted"].ToString();
                }
                var email = cp.Where(x => x["method"].ToString().Equals("email") && x["usage"].ToString().Equals("default")).FirstOrDefault();
                if (email != null)
                {
                    dest.EmailAddress = email["address"]["formatted"].ToString();
                }
                if (src["contact-preference"] != null && src["contact-preference"].HasValues)
                {
                    dest.PreferredCulture = src["contact-preference"]?["preferred-language"]?.ToString() ?? "sr-Latn-RS";
                }
                else
                {
                    dest.PreferredCulture = "sr-Latn-RS";
                }

                var employmentData = new EmploymentData();

                //var employmentStatus = EnumUtils.ToEnum<EmploymentStatus>(src["employment-status"]?.ToString());
                //if (employmentStatus != null)
                //{
                //    employmentData.EmploymentStatus = employmentStatus.Value;
                //}

                var employmentStatus = src["employment-status"]?.ToString();
                if (employmentStatus != null)
                {
                    employmentData.EmploymentStatus = employmentStatus;
                }
                ;


                var employmentDataSource = src["employment"];
                if (employmentDataSource != null && employmentDataSource.HasValues)
                {
                    var employmentInfo = new EmploymentInfo();
                    var employer       = src["employment"]["employer"]?.ToString();

                    var employerId = src["employment"]["employer-id"]?.ToString();

                    var positionCategory = src["employment"]["employment-position"]?.ToString();
                    if (!string.IsNullOrEmpty(employer))
                    {
                        employmentInfo.EmployerName = employer;
                    }
                    if (!string.IsNullOrEmpty(employerId))
                    {
                        employmentInfo.CompanyIdNumber = employerId;
                    }
                    if (!string.IsNullOrEmpty(positionCategory))
                    {
                        employmentInfo.PositionCategory = positionCategory;
                    }
                    employmentData.Employments = new List <EmploymentInfo> {
                        employmentInfo
                    };

                    var employmentDateString = src["employment"]["employment-date"]?.ToString();
                    if (!string.IsNullOrEmpty(employmentDateString))
                    {
                        var employmentDate = DateTime.Parse(employmentDateString);
                        employmentData.EmploymentStatusDate = employmentDate;
                        employmentInfo.EmploymentStartDate  = employmentDate;
                        // employmentData.Employments = new List<EmploymentInfo> { employmentInfo };
                        var periodBuilder  = new PeriodBuilder();
                        var durationStruct = periodBuilder.ToString(new TimeSpan(Utility.DaysBetween(employmentDate) * 24, 0, 0));
                        // employmentData.TotalWorkPeriod = durationStruct;
                        int numberOfYears = 0;
                        numberOfYears     = Years(employmentDate, DateTime.Now);

                        int Years(DateTime start, DateTime end)
                        {
                            return((end.Year - start.Year - 1) +
                                   (((end.Month > start.Month) ||
                                     ((end.Month == start.Month) && (end.Day >= start.Day))) ? 1 : 0));
                        };
                        var dateForMonths = employmentDate.AddYears(numberOfYears);
                        //var durationMonths = periodBuilder.ToString(new TimeSpan(Utility.MonthsBetween(dateForMonths) * 24, 0, 0));
                        int numberOfMonths = 0;
                        numberOfMonths     = GetMonthsBetween(dateForMonths, DateTime.Now);
                        var dateForDays    = dateForMonths.AddMonths(numberOfMonths);
                        int numberOfDays   = 0;
                        numberOfDays       = Utility.DaysBetween(dateForDays);

                        int GetMonthsBetween(DateTime from, DateTime to)
                        {
                            if (from > to)
                            {
                                return(GetMonthsBetween(to, from));
                            }

                            var monthDiff = Math.Abs((to.Year * 12 + (to.Month - 1)) - (from.Year * 12 + (from.Month - 1)));

                            if (from.AddMonths(monthDiff) > to || to.Day < from.Day)
                            {
                                return(monthDiff - 1);
                            }
                            else
                            {
                                return(monthDiff);
                            }
                        }


                        employmentData.TotalWorkPeriod = "P" + numberOfYears + "Y" + numberOfMonths + "M" + numberOfDays + "D";
                    }
                }
                dest.EmploymentData = employmentData;


                try
                {
                    var relationships = ((JArray)src["relationships"]).ToList();

                    var rels = new List <Relationship>();
                    foreach (var item in relationships)
                    {
                        Relationship relation = new Relationship
                        {
                            Kind    = item["kind"].ToString(),
                            Role    = item["role"].ToString(),
                            ToParty = new ToParty
                            {
                                Name   = item["to-party"]["name"].ToString(),
                                Number = item["to-party"]["number"].ToString()
                            }
                        };

                        if (Enum.TryParse(typeof(PartyKind), item["to-party"]["kind"].ToString(), true, out object kind))
                        {
                            relation.ToParty.Kind = (PartyKind)kind;
                        }
                        else
                        {
                            relation.ToParty.Kind = PartyKind.Individual;
                        }
                        rels.Add(relation);
                    }
                    dest.Relationships = rels;
                }
                catch
                {
                    // Just ignore it
                }

                var ids = ((JArray)src["id-documents"])?.ToList();
                if (ids != null && ids.Count > 0)
                {
                    IdentificationDocument idDocument = new IdentificationDocument
                    {
                        Kind             = ids[0]["kind"]?.ToString(),
                        SerialNumber     = ids[0]["serial-number"]?.ToString(),
                        IssuedDate       = DateTime.Parse(ids[0]["issued"]?.ToString()),
                        ValidUntil       = DateTime.Parse(ids[0]["valid-until"]?.ToString()),
                        Status           = ids[0]["status"]?.ToString(),
                        PlaceOfIssue     = ids[0]["place-of-issue"]?.ToString(),
                        IssuingAuthority = ids[0]["issuing-authority"]?.ToString(),
                        ContentUrls      = ids[0]["content-url"]?.ToString()
                    };
                    dest.IdentificationDocument = idDocument;
                }
            });
        }
Esempio n. 10
0
        public async Task <ResponseMessage <int> > Person_AddDocumentAsync(IdentificationDocument document)
        {
            var address = $"{WS_ADDRESS}/api/person/document";

            return(await SendRequestAsync <int>(address, HttpMethod.POST, document));
        }