Ejemplo n.º 1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (string.IsNullOrEmpty(_Business.Name) || (_Business.Type == (int)Business.EType.Unknown))
            {
                return(Page());
            }

            if (!string.IsNullOrEmpty(_ZipCode))
            {
                _ZipCode = Address.StripZip(_ZipCode);
            }

            Address adr = new Address();

            adr.Street  = _Street;
            adr.Town    = _Town;
            adr.ZipCode = _ZipCode;
            adr.Phone   = _Phone;
            adr.State   = _State;
            adr.Fax     = _Fax;
            adr.Country = "USA";

            if (!string.IsNullOrEmpty(adr.Phone) || !string.IsNullOrEmpty(adr.Fax))
            {
                if (!AddressMgr.Validate(ref adr))
                {
                    if (string.IsNullOrEmpty(adr.Street))
                    {
                        adr.Street = "<missing>";
                    }
                    if (string.IsNullOrEmpty(adr.Town))
                    {
                        adr.Town = "<missing>";
                    }
                    if (string.IsNullOrEmpty(adr.State))
                    {
                        adr.State = "NY";
                    }
                    if (string.IsNullOrEmpty(adr.ZipCode))
                    {
                        adr.ZipCode = "11111";
                    }
                }
            }

            int?id = Address.UpdateAddress(_context, adr);

            if (id.HasValue && (id.Value > 0))
            {
                _Business.AddressId = id;
                _Business.Address   = null;
            }
            else
            {
                _Business.AddressId = null;
                _Business.Address   = null;
            }
            _Business.PocId = !string.IsNullOrEmpty(_poc) ? Person.PersonIdFromExactName(_context, _poc) : null;
            if (!string.IsNullOrEmpty(_Business.UserLink))
            {
                _Business.UserLink = _Business.UserLink.Trim();
            }

            _context.Attach(_Business).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BusinessExists(_Business.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            if (string.IsNullOrEmpty(_RedirectURL))
            {
                return(RedirectToPage("./Index"));
            }
            _RedirectURL = "";
            return(NotFound());
        }
Ejemplo n.º 2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Page());
                }
                Address adr = new Address();
                adr.Street  = _Street;
                adr.Town    = _Town;
                adr.ZipCode = _ZipCode;
                adr.Phone   = _Phone;
                adr.State   = _State;
                adr.Fax     = _Fax;
                adr.Country = "USA";

                if (!string.IsNullOrEmpty(adr.Phone) || !string.IsNullOrEmpty(adr.Fax))
                {
                    if (!AddressMgr.Validate(ref adr))
                    {
                        if (string.IsNullOrEmpty(adr.Street))
                        {
                            adr.Street = "<missing>";
                        }
                        if (string.IsNullOrEmpty(adr.Town))
                        {
                            adr.Town = "<missing>";
                        }
                        if (string.IsNullOrEmpty(adr.State))
                        {
                            adr.State = "NY";
                        }
                        if (string.IsNullOrEmpty(adr.ZipCode))
                        {
                            adr.ZipCode = "11111";
                        }
                    }
                }

                int?id = Address.UpdateAddress(_context, adr);
                if (id.HasValue && (id.Value > 0))
                {
                    Business.AddressId = id;
                    Business.Address   = null;
                }
                else
                {
                    Business.AddressId = null;
                    Business.Address   = null;
                }

                Business.PocId = !string.IsNullOrEmpty(_poc) ? Person.PersonIdFromExactName(_context, _poc) : null;
                if (!string.IsNullOrEmpty(Business.UserLink))
                {
                    Business.UserLink = Business.UserLink.Trim();
                }
                _context.Business.Add(Business);
                await _context.SaveChangesAsync();
            }
            catch
            { }
            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 3
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Address adr = new Address();

            adr.Street  = _Street;
            adr.Town    = _Town;
            adr.ZipCode = _ZipCode;
            adr.Phone   = _Phone;
            adr.State   = _State;
            adr.Fax     = _Fax;
            adr.Country = "USA";

            if (!string.IsNullOrEmpty(adr.Phone) || !string.IsNullOrEmpty(adr.Fax))
            {
                if (!AddressMgr.Validate(ref adr))
                {
                    if (string.IsNullOrEmpty(adr.Street))
                    {
                        adr.Street = "<missing>";
                    }
                    if (string.IsNullOrEmpty(adr.Town))
                    {
                        adr.Town = "<missing>";
                    }
                    if (string.IsNullOrEmpty(adr.State))
                    {
                        adr.State = "NY";
                    }
                    if (string.IsNullOrEmpty(adr.ZipCode))
                    {
                        adr.ZipCode = "11111";
                    }
                }
            }

            int?id = Address.UpdateAddress(_context, adr);

            if (id.HasValue && (id.Value > 0))
            {
                Church.AddressId = id;
                Church.Address   = null;
            }
            else
            {
                Church.AddressId = null;
                Church.Address   = null;
            }

            Church.SeniorMinisterId = Person.PersonIdFromExactName(_context, _SeniorMinister);
            Church.YouthMinisterId  = Person.PersonIdFromExactName(_context, _YouthMinister);
            Church.Trustee1Id       = Person.PersonIdFromExactName(_context, _Trustee1);
            Church.Trustee2Id       = Person.PersonIdFromExactName(_context, _Trustee2);
            Church.Trustee3Id       = Person.PersonIdFromExactName(_context, _Trustee3);
            Church.Alternate1Id     = Person.PersonIdFromExactName(_context, _Alternate1);
            Church.Alternate2Id     = Person.PersonIdFromExactName(_context, _Alternate2);
            Church.Alternate3Id     = Person.PersonIdFromExactName(_context, _Alternate3);

            if (int.TryParse(Church.Affiliation, out int affIdx))
            {
                Church.Affiliation = ((AffiliationType)affIdx).ToString();
            }
            else
            {
                Church.Affiliation = AffiliationType.UNK.ToString();
            }

            _context.Church.Add(Church);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 4
0
        public static int UpdateAddress(Models.CStatContext ce, Address inAdr)
        {
            Address newAdr        = new Address();
            Address foundAdr      = null;
            bool    bValidAddress = false;
            bool    bHasZip       = !string.IsNullOrEmpty(inAdr.ZipCode);

            if (bHasZip)
            {
                inAdr.ZipCode = inAdr.ZipCode.Replace("-", string.Empty);
            }
            bool bHasStreet = !string.IsNullOrEmpty(inAdr.Street);
            bool bHasCS     = !string.IsNullOrEmpty(inAdr.Town) && !string.IsNullOrEmpty(inAdr.State);

            if (bHasStreet)
            {
                inAdr.Street = Models.Person.CleanStreet(inAdr.Street);
            }
            else
            {
                inAdr.Street = "";
            }

            bool bFoundAdrId = inAdr.Id > 0;
            int  FoundAdrId  = bFoundAdrId ? inAdr.Id : 0;

            if (!bFoundAdrId && (!bHasStreet || !bHasCS))
            {
                return(0); // nothing can be done.
            }
            if (bFoundAdrId && (!bHasStreet || !bHasCS))
            {
                return(FoundAdrId); // not going to attempt to update address
            }
            if (!bFoundAdrId && bHasStreet && (bHasZip || bHasCS))
            {
                bool bTrySCS = false;

                // Try to find an existing address by looping here up to 2 times.
                do
                {
                    int            ld, MinLD = 10000;
                    List <Address> adrList = new List <Address>();
                    if (bHasZip && !bTrySCS)
                    {
                        if (inAdr.ZipCode != "11111")
                        {
                            var adrL = from adr in ce.Address.AsNoTracking()
                                       where (adr.ZipCode == inAdr.ZipCode)
                                       select adr;
                            foreach (Address a in adrL)
                            {
                                adrList.Add(a);
                            }
                        }
                    }
                    else
                    {
                        if (!inAdr.Town.Contains("<missing>"))
                        {
                            var adrL = from adr in ce.Address.AsNoTracking()
                                       where (adr.Town == inAdr.Town) && (adr.State == inAdr.State)
                                       select adr;
                            foreach (Address a in adrL)
                            {
                                adrList.Add(a);
                            }
                        }
                    }

                    if (adrList.Count() > 0)
                    {
                        Address MinAdr = new Address();
                        foreach (Address a in adrList)
                        {
                            ld = a.Street.Contains("<missing>") ? 10000 : LevenshteinDistance.Compute(a.Street, inAdr.Street);
                            if (ld < MinLD)
                            {
                                MinAdr = a;
                                MinLD  = ld;
                            }
                        }

                        int si = MinAdr.Street.IndexOf(' ');
                        if ((MinLD < 2) && ((si > 1) && ((si + 3) < MinAdr.Street.Length) && inAdr.Street.StartsWith(MinAdr.Street.Substring(0, si + 3))))
                        {
                            // Found matching address. Just set address id
                            FoundAdrId  = newAdr.Id = MinAdr.Id;
                            foundAdr    = MinAdr;
                            bFoundAdrId = true;
                        }
                    }

                    if (bTrySCS)
                    {
                        break; // We already looped. Break here.
                    }
                    if (!bFoundAdrId && bHasZip)
                    {
                        // Zip may be bad or changed try to match by street, city, state
                        bTrySCS = true;
                    }
                    else
                    {
                        break; // Do not loop because there is nothing to retry.
                    }
                }while (!bFoundAdrId);
            }

            //***************************
            //*** Add Address fields ****
            //***************************
            if (bHasStreet)
            {
                newAdr.Street = inAdr.Street;
            }
            if (bHasCS)
            {
                newAdr.Town  = inAdr.Town;
                newAdr.State = inAdr.State;
            }

            if (bHasZip)
            {
                newAdr.ZipCode = inAdr.ZipCode;
            }

            if (!string.IsNullOrEmpty(inAdr.Phone))
            {
                newAdr.Phone = inAdr.Phone;
            }

            if (!string.IsNullOrEmpty(inAdr.Fax))
            {
                newAdr.Fax = inAdr.Fax;
            }

            //AddressMgr amgr = new AddressMgr(ce);
            bValidAddress = AddressMgr.Validate(ref newAdr);
            if (!bFoundAdrId && !bValidAddress)
            {
                return(0); // nothing can be done
            }
            // Add / Update Address
            try
            {
                if (bValidAddress)
                {
                    if (!bFoundAdrId)
                    {
                        // Add new, valid address and set Person.Address_id
                        try
                        {
                            ce.Address.Add(newAdr);
                            if (ce.SaveChanges() < 1)
                            {
                                return(0);
                            }
                            if (newAdr.Id != 0)
                            {
                                return(newAdr.Id);
                            }
                        }
                        catch
                        {
                        }
                        return(0);
                    }
                    else
                    {
                        // Make sure address fields are updated.
                        if (foundAdr != null)
                        {
                            newAdr = Address.Merge(foundAdr, newAdr);
                            try
                            {
                                ce.Address.Attach(newAdr);
                                ce.Entry(newAdr).State = EntityState.Modified;
                                ce.SaveChanges();
                                return(newAdr.Id);
                            }
                            catch
                            {
                                return(0);
                            }
                        }
                        return(FoundAdrId);
                    }
                }
            }
            catch
            {
            }
            return(0);
        }
Ejemplo n.º 5
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            //if (!ModelState.IsValid)
            //{
            //    return Page();
            //}

            Address adr = new Address();

            adr.Street  = _Street;
            adr.Town    = _Town;
            adr.ZipCode = _ZipCode;
            adr.Phone   = _Phone;
            adr.State   = _State;
            adr.Fax     = _Fax;
            adr.Country = "USA";

            if (!string.IsNullOrEmpty(adr.Phone) || !string.IsNullOrEmpty(adr.Fax))
            {
                if (!AddressMgr.Validate(ref adr))
                {
                    if (string.IsNullOrEmpty(adr.Street))
                    {
                        adr.Street = "<missing>";
                    }
                    if (string.IsNullOrEmpty(adr.Town))
                    {
                        adr.Town = "<missing>";
                    }
                    if (string.IsNullOrEmpty(adr.State))
                    {
                        adr.State = "NY";
                    }
                    if (string.IsNullOrEmpty(adr.ZipCode))
                    {
                        adr.ZipCode = "11111";
                    }
                }
            }

            int?id = Address.UpdateAddress(_context, adr);

            if (id.HasValue && (id.Value > 0))
            {
                _Church.AddressId = id;
                _Church.Address   = null;
            }
            else
            {
                _Church.AddressId = null;
                _Church.Address   = null;
            }

            if (!_Church.SeniorMinisterId.HasValue)
            {
                _Church.SeniorMinisterId = Person.PersonIdFromExactName(_context, _SeniorMinister);
            }
            if (!_Church.YouthMinisterId.HasValue)
            {
                _Church.YouthMinisterId = Person.PersonIdFromExactName(_context, _YouthMinister);
            }
            if (!_Church.Trustee1Id.HasValue)
            {
                _Church.Trustee1Id = Person.PersonIdFromExactName(_context, _Trustee1);
            }
            if (!_Church.Trustee2Id.HasValue)
            {
                _Church.Trustee2Id = Person.PersonIdFromExactName(_context, _Trustee2);
            }
            if (!_Church.Trustee3Id.HasValue)
            {
                _Church.Trustee3Id = Person.PersonIdFromExactName(_context, _Trustee3);
            }
            if (!_Church.Alternate1Id.HasValue)
            {
                _Church.Alternate1Id = Person.PersonIdFromExactName(_context, _Alternate1);
            }
            if (!_Church.Alternate2Id.HasValue)
            {
                _Church.Alternate2Id = Person.PersonIdFromExactName(_context, _Alternate2);
            }
            if (!_Church.Alternate3Id.HasValue)
            {
                _Church.Alternate3Id = Person.PersonIdFromExactName(_context, _Alternate3);
            }

            _Church.Affiliation = ((AffiliationType)_Affiliation).ToString();

            _context.Attach(_Church).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
            }

            return(RedirectToPage("./Index"));
        }