Example #1
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            bool nameAvailable = true;
            Site currentSite   = null;
            if (!string.IsNullOrEmpty(lblSiteId.Text))
            {
                currentSite = SiteManager.GetSiteById(lblSiteId.Text);
            }

            Site site = SiteManager.GetSiteByName(txtSiteName.Text);
            if (site != null)
            {
                if (currentSite != null)
                {
                    if (site != null && site.Id != currentSite.Id)
                    {
                        nameAvailable = false;
                        ((IFeedback)Page.Master).ShowFeedback(Feedback.Actions.Error, "Site " + txtSiteName.Text + " already exists");
                    }
                }
                else //new site
                {
                    nameAvailable = false;
                    ((IFeedback)Page.Master).ShowFeedback(Feedback.Actions.Error, "Region " + txtSiteName.Text + " already exists");
                }
            }

            if (nameAvailable)
            {
                // Figure out the address.
                Address physicalAddress = CreatePhysicalAddressFromFields();
                //if (physicalAddress == null)
                //    physicalAddress = new Address();
                Address postalAddress = CreatePostalAddressFromFields();
                //if (postalAddress == null)
                //    postalAddress = new Address();

                if (currentSite == null)
                {
                    // Create a new site.
                    currentSite      = new Site();
                    currentSite.Name = txtSiteName.Text;
                    // Just get the first available site type. We don't use site types at the moment.
                    currentSite.SiteType        = SiteManager.GetAllSiteTypes()[0];
                    currentSite.PhoneNumber     = txtPhoneNumber.Text;
                    currentSite.AltPhoneNumber  = txtAltPhoneNumber.Text;
                    currentSite.Email           = txtEmail.Text;
                    currentSite.Region          = (Region)regions[cmbRegions.SelectedIndex];
                    currentSite.PhysicalAddress = physicalAddress;
                    currentSite.PostalAddress   = postalAddress;
                    SiteManager.CreateSite(currentSite);
                    lblSiteId.Text = SiteManager.GetSiteByName(currentSite.Name).Id;
                    RefreshData(SiteManager.GetSiteByName(currentSite.Name).Id);
                    btnUpdate.Text = UpdateSite;

                    ((IFeedback)Master).QueueFeedback(BusiBlocksConstants.Blocks.Administration.LongName,
                                                      currentSite.GetType().Name, Feedback.Actions.Created, currentSite.Name);

                    Navigation.Admin_ManageLocations().Redirect(this);
                }
                else
                {
                    if (physicalAddress != null)
                    {
                        if (currentSite.PhysicalAddress == null)
                        {
                            currentSite.PhysicalAddress = new Address();
                        }

                        currentSite.PhysicalAddress.Address1 = physicalAddress.Address1;
                        currentSite.PhysicalAddress.Address2 = physicalAddress.Address2;
                        currentSite.PhysicalAddress.Suburb   = physicalAddress.Suburb;
                        currentSite.PhysicalAddress.Postcode = physicalAddress.Postcode;
                        currentSite.PhysicalAddress.State    = physicalAddress.State;

                        if (string.IsNullOrEmpty(currentSite.PhysicalAddress.Id))
                        {
                            AddressManager.CreateAddress(currentSite.PhysicalAddress);
                        }
                        else
                        {
                            AddressManager.UpdateAddress(currentSite.PhysicalAddress);
                        }
                    }
                    else if (physicalAddress == null && currentSite.PhysicalAddress != null)
                    {
                        // Delete the address.
                        AddressManager.DeleteAddress(currentSite.PhysicalAddress);
                        currentSite.PhysicalAddress = null;
                    }

                    if (postalAddress != null)
                    {
                        if (currentSite.PostalAddress == null)
                        {
                            currentSite.PostalAddress = new Address();
                        }

                        currentSite.PostalAddress.Address1 = postalAddress.Address1;
                        currentSite.PostalAddress.Address2 = postalAddress.Address2;
                        currentSite.PostalAddress.Suburb   = postalAddress.Suburb;
                        currentSite.PostalAddress.Postcode = postalAddress.Postcode;
                        currentSite.PostalAddress.State    = postalAddress.State;

                        if (string.IsNullOrEmpty(currentSite.PostalAddress.Id))
                        {
                            AddressManager.CreateAddress(currentSite.PostalAddress);
                        }
                        else
                        {
                            AddressManager.UpdateAddress(currentSite.PostalAddress);
                        }
                    }
                    else if (postalAddress == null && currentSite.PostalAddress != null)
                    {
                        // Delete the address.
                        AddressManager.DeleteAddress(currentSite.PostalAddress);
                        currentSite.PostalAddress = null;
                    }

                    currentSite.Name           = txtSiteName.Text;
                    currentSite.PhoneNumber    = txtPhoneNumber.Text;
                    currentSite.AltPhoneNumber = txtAltPhoneNumber.Text;
                    currentSite.Email          = txtEmail.Text;
                    currentSite.Region         = (Region)regions[cmbRegions.SelectedIndex];
                    SiteManager.UpdateSite(currentSite);

                    ((IFeedback)Master).QueueFeedback(BusiBlocksConstants.Blocks.Administration.LongName,
                                                      currentSite.GetType().Name, Feedback.Actions.Saved, currentSite.Name);

                    Navigation.Admin_ManageLocations().Redirect(this);
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
            ((IFeedback)Master).SetException(GetType(), ex);
        }
    }
Example #2
0
 protected void btnCancel_Click(object sender, EventArgs e)
 {
     Navigation.Admin_ManageLocations().Redirect(this);
 }
Example #3
0
 protected string GetRegionNameAvailableUrl()
 {
     return(Navigation.Admin_ManageLocations().GetAbsoluteClientUrl(true) + "/RegionNameAvailable");
 }