Пример #1
0
        private static TalentShow.Organization GetOrganization(TalentShow.Organization defaultOrganization, string organizationName, string parentOrganizationName)
        {
            organizationName       = organizationName.ToUpper().Trim();
            parentOrganizationName = parentOrganizationName.ToUpper().Trim();

            var allOrganizations = ServiceFactory.OrganizationService.GetAll();

            var organization       = allOrganizations.FirstOrDefault(o => o.Name.ToUpper().Trim() == organizationName);
            var parentOrganization = allOrganizations.FirstOrDefault(o => o.Name.ToUpper().Trim() == parentOrganizationName);

            if (organization == null && !String.IsNullOrWhiteSpace(organizationName))
            {
                organization = new TalentShow.Organization(organizationName);

                if (parentOrganization == null && !String.IsNullOrWhiteSpace(parentOrganizationName))
                {
                    parentOrganization = new TalentShow.Organization(parentOrganizationName);

                    ServiceFactory.OrganizationService.Add(parentOrganization);
                }

                organization.SetParent(parentOrganization);

                ServiceFactory.OrganizationService.Add(organization);
            }

            if (organization == null)
            {
                organization = ServiceFactory.OrganizationService.Get(defaultOrganization.Id);
            }

            return(organization);
        }
        protected void btnUpdateOrganization_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                //TODO
                return;
            }

            var name = organizationForm.GetNameTextBox().Text.Trim();
            var parentOrganizationId = organizationForm.GetOrganizationsDropDownList().SelectedValue;
            var organization         = new TalentShow.Organization(GetOrganizationId(), name, null);

            if (!String.IsNullOrWhiteSpace(parentOrganizationId))
            {
                organization.SetParent(ServiceFactory.OrganizationService.Get(Convert.ToInt32(parentOrganizationId)));
            }

            ServiceFactory.OrganizationService.Update(organization);
            GoToOrganizationsPage();
        }