public async Task <IActionResult> OnPostAsync()
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Page());
                }

                NodeContext.Org_tbAddresses.Add(Org_tbAddress);
                if (IsAdminAddress)
                {
                    Org_tbOrg org = await NodeContext.Org_tbOrgs.FirstOrDefaultAsync(t => t.AccountCode == Org_tbAddress.AccountCode);

                    org.AddressCode = Org_tbAddress.AddressCode;
                }

                await NodeContext.SaveChangesAsync();

                RouteValueDictionary route = new();
                route.Add("accountCode", Org_tbAddress.AccountCode);

                return(RedirectToPage("./Index", route));
            }
            catch (Exception e)
            {
                NodeContext.ErrorLog(e);
                throw;
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Page());
                }

                Profile profile = new(NodeContext);
                Org_tbAddress.UpdatedBy = await profile.UserName(UserManager.GetUserId(User));

                NodeContext.Attach(Org_tbAddress).State = EntityState.Modified;

                if (IsAdminAddress)
                {
                    Org_tbOrg org = await NodeContext.Org_tbOrgs.FirstOrDefaultAsync(t => t.AccountCode == Org_tbAddress.AccountCode);

                    if (org.AddressCode != Org_tbAddress.AddressCode)
                    {
                        org.AddressCode = Org_tbAddress.AddressCode;
                        NodeContext.Attach(org).State = EntityState.Modified;
                    }
                }

                try
                {
                    await NodeContext.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await NodeContext.Org_tbAddresses.AnyAsync(e => e.AddressCode == Org_tbAddress.AddressCode))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                RouteValueDictionary route = new();
                route.Add("accountCode", Org_tbAddress.AccountCode);

                return(RedirectToPage("./Index", route));
            }
            catch (Exception e)
            {
                NodeContext.ErrorLog(e);
                throw;
            }
        }