public override IWorldObject Clone() { OrganizationObject res = new OrganizationObject(Word); res.Copy(this); return(res); }
public void Setup() { string serviceUri1 = @"/OrganizationService.svc/json/SaveOrganizationType"; string serviceUri2 = @"/OrganizationService.svc/json/SaveOrganization"; organizationTypeObject = new OrganizationTypeObject() { Name = "Manager" + Guid.NewGuid().ToString().Substring(0, 5), Domain = "Department", Description = "department-desc", LastUpdatedDate = System.DateTime.Now }; string organizationTypeId = TestServicesHelper.GetResponse<HttpWebRequest>(serviceUri1, userName, password, TestServicesHelper.PostDataByJsonWithContent, TestServicesHelper.GenerateJsonByType(organizationTypeObject), null).Replace("\"", ""); organizationTypeObject.OrganizationTypeId = new Guid(organizationTypeId); organizationObject = new OrganizationObject() { OrganizationCode = "sh021" + Guid.NewGuid().ToString().Substring(0, 5), OrganizationName = "sh-department" + Guid.NewGuid().ToString().Substring(0, 5), OrganizationTypeId = organizationTypeObject.OrganizationTypeId, Status = OrganizationStatus.Enabled, Description = "sh-desc", CreatedDate = System.DateTime.Now, LastUpdatedDate = System.DateTime.Now }; string organizationId = TestServicesHelper.GetResponse<HttpWebRequest>(serviceUri2, userName, password, TestServicesHelper.PostDataByJsonWithContent, TestServicesHelper.GenerateJsonByType(organizationObject), null).Replace("\"", ""); organizationObject.OrganizationId = new Guid(organizationId); }
public void Setup() { string serviceUri1 = @"/OrganizationService.svc/json/SaveOrganizationType"; string serviceUriorganization = @"/OrganizationService.svc/json/SaveOrganization"; organizationTypeObject = new OrganizationTypeObject() { Name = "Manager" + Guid.NewGuid().ToString().Substring(0, 5), Domain = "Department", Description = "department-desc", LastUpdatedDate = System.DateTime.Now }; string organizationTypeId = TestServicesHelper.GetResponse<HttpWebRequest>(serviceUri1, userName, password, TestServicesHelper.PostDataByJsonWithContent, TestServicesHelper.GenerateJsonByType(organizationTypeObject), null).Replace("\"", ""); organizationTypeObject.OrganizationTypeId = new Guid(organizationTypeId); organizationObject = new OrganizationObject() { OrganizationCode = "sh021" + Guid.NewGuid().ToString().Substring(0, 5), OrganizationName = "sh-department" + Guid.NewGuid().ToString().Substring(0, 5), OrganizationTypeId = organizationTypeObject.OrganizationTypeId, Status = OrganizationStatus.Enabled, Description = "sh-desc", CreatedDate = System.DateTime.Now, LastUpdatedDate = System.DateTime.Now }; string organizationId = TestServicesHelper.GetResponse<HttpWebRequest>(serviceUriorganization, userName, password, TestServicesHelper.PostDataByJsonWithContent, TestServicesHelper.GenerateJsonByType(organizationObject), null).Replace("\"", ""); organizationObject.OrganizationId = new Guid(organizationId); common = new UserObject { UserName = "******" + Guid.NewGuid().ToString().Substring(0, 5), DisplayName = "CommonUser" + Guid.NewGuid().ToString().Substring(0, 5), LastActivityDate = DateTime.Now, LastLockoutDate = DateTime.Now, LastLoginDate = DateTime.Now, LastPasswordChangedDate = DateTime.Now, CreationDate = System.DateTime.Now, OrganizationId = organizationObject.OrganizationId, LastUpdatedDate = DateTime.Now, PasswordQuestion = pwdAns }; string serviceUri = string.Format("/MembershipService.svc/json/Save"); string content = TestServicesHelper.GenerateJsonByType(common); IDictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("password", pwd); parameters.Add("passwordAnswer", pwdAns); string id = TestServicesHelper.GetResponse<HttpWebRequest>(serviceUri, userName, password, TestServicesHelper.PostDataByJsonWithContent, content, parameters).Replace("\"", ""); common.UserId = new Guid(id); super = new RoleObject { RoleName = "super", Domain = "Department", Description = "super role" }; string serviceUriRole = @"/RoleService.svc/json/Save"; string contentRole = TestServicesHelper.GenerateJsonByType(super); string idRole = TestServicesHelper.GetResponse<HttpWebRequest>(serviceUriRole, userName, password, TestServicesHelper.PostDataByJsonWithContent, contentRole, null).Replace("\"", ""); super.RoleId = new Guid(idRole); }
public OrganizationObject CreateOrganizationObject(Guid _OrganizationTypeId,string Name,string code) { OrganizationObject shOrganization = new OrganizationObject { OrganizationCode = code, OrganizationName = Name, OrganizationTypeId = _OrganizationTypeId, Status = OrganizationStatus.Enabled, Description = "sh-desc" }; return shOrganization; }
public void AnalizeTestWithGufContextIntegration() { var res = nlpCtrl.Analize("הוא הקריא את מגילת העצמאות בהכרזת העצמאות והם היו מחתרת לוחמת", "ההגנה ובן גוריון"); //good Assert.IsTrue(res.Contains(new PersonObject("דוד בן גוריון"))); Assert.IsTrue(res.Contains(new ConceptObject("מגילת העצמאות"))); Assert.IsTrue(res.Contains(new EventObject("הכרזת העצמאות"))); var ob = new OrganizationObject("ההגנה"); ob.DefiniteArticle = true; Assert.IsTrue(res.Contains(ob)); //bad Assert.IsFalse(res.Contains(new PersonObject(""))); //ugly Assert.IsFalse(res.Contains(null)); }
private IEnumerable<Guid> ResolveSelectedRoleCheckBox(OrganizationObject organization) { List<Guid> roleIds = new List<Guid>(); if (organization == null) return roleIds; IEnumerable<RoleObject> roleObjects = this.FindRolesByOrganization(organization); foreach (RoleObject roleObject in roleObjects) { string name = string.Format("{0}$ID{1}", TabPanelProfile.UniqueID, roleObject.RoleId); string checkBoxValue = HttpContext.Current.Request.Params[name]; if (string.Equals(checkBoxValue, "on", StringComparison.InvariantCultureIgnoreCase)) roleIds.Add(roleObject.RoleId); } return roleIds; }
private void CreateRoleCheckBoxes(OrganizationObject organization) { if (this.PanelRoleContainer == null) return; this.PanelRoleContainer.Controls.Clear(); if (organization == null) return; IEnumerable<RoleObject> roleObjects = this.FindRolesByOrganization(organization); foreach (RoleObject roleObject in roleObjects) { CheckBox checkbox = new CheckBox { ID = string.Format("ID{0}", roleObject.RoleId), Text = roleObject.RoleName }; this.PanelRoleContainer.Controls.Add(checkbox); this.dynamicGeneratedCheckBox.Add(checkbox); } }
private IEnumerable<RoleObject> FindRolesByOrganization(OrganizationObject organizationObject) { int recordCount; OrganizationTypeObject orgType = organizationApi.GetOrganizationType(organizationObject.OrganizationTypeId); LinqPredicate linqPredicate = new LinqPredicate("Domain=@0", orgType.Domain); IEnumerable<RoleObject> results = roleApi.FindRoles(linqPredicate, "RoleName ASC", 0, int.MaxValue, out recordCount); return results.ToList(); }
public void SaveANewOrganizationWithEmptyProperties() { _story = new Story("Save a Organization By IOrganizationApi"); _story.AsA("User") .IWant("to be able to create a new Organization, but I don't assign value to it") .SoThat("I can get specific exception"); _story.WithScenario("Save a new Organization which have no value") .Given("the new member with nothing", () => { _OrganObject1 = new OrganizationObject(); }) .When("I save this Organization", () => { }) .Then("I Get an ArgumentNullException from IOrganizationApi.Save()", () => typeof(ArgumentNullException).ShouldBeThrownBy(() => _organizationApi.Save(_OrganObject1))); this.CleanUp(); }
protected void popManufacturerEdit_WindowCallback(object source, DevExpress.Web.ASPxPopupControl.PopupWindowCallbackArgs e) { string[] args = e.Parameter.Split('|'); switch (args[0]) { case "new": ManufacturerOrg tempManufacturerOrg = ManufacturerOrg.InitNewRow(session); PrivateSession.Instance.ManufacturerOrgId = tempManufacturerOrg.OrganizationId; frmManufacturerEdit.DataSourceID = "dsManufacturer"; dsManufacturer.CriteriaParameters["ManufacturerOrgId"].DefaultValue = PrivateSession.Instance.ManufacturerOrgId.ToString(); ClearForm(); //Get object id //Bind data to gridview #region add manufacturer session.BeginTransaction(); try { //ObjectType ObjectType objectType = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.MANUFACTURER); // object NAS.BO.CMS.ObjectDocument.ObjectBO objectBO = new NAS.BO.CMS.ObjectDocument.ObjectBO(); NAS.DAL.CMS.ObjectDocument.Object cmsobject = objectBO.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.MANUFACTURER); // OrganizationObject OrganizationObject organizatoinObject = new OrganizationObject(session) { ObjectId = cmsobject, OrganizationId = tempManufacturerOrg }; organizatoinObject.Save(); // OrganizationCustomType OrganizationCustomType organizationCustomType = new OrganizationCustomType(session) { ObjectTypeId = objectType, OrganizationId = tempManufacturerOrg }; organizationCustomType.Save(); session.CommitTransaction(); } catch { session.RollbackTransaction(); } OrganizationObject organizationObject = tempManufacturerOrg.OrganizationObjects.FirstOrDefault(); grid_of_Manufacturer.CMSObjectId = organizationObject.ObjectId.ObjectId; grid_of_Manufacturer.DataBind(); #endregion //2013-11-22 Khoa.Truong DEL START //gridviewCustomFields.CMSObjectId = CurrentManufacturerOrg.ObjectId.ObjectId; //gridviewCustomFields.DataBind(); //2013-11-22 Khoa.Truong DEL END break; case "edit": ClearForm(); frmManufacturerEdit.DataSourceID = "dsManufacturer"; if (args.Length > 1) { PrivateSession.Instance.ManufacturerOrgId = Guid.Parse(args[1]); dsManufacturer.CriteriaParameters["ManufacturerOrgId"].DefaultValue = PrivateSession.Instance.ManufacturerOrgId.ToString(); txtCode.Text = CurrentManufacturerOrg.Code; //Get object id //Bind data to gridview #region edit manufacturer if (CurrentManufacturerOrg.OrganizationObjects.FirstOrDefault() == null) { session.BeginTransaction(); try { ObjectType objectType1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.MANUFACTURER); // object NAS.BO.CMS.ObjectDocument.ObjectBO objectBO1 = new NAS.BO.CMS.ObjectDocument.ObjectBO(); NAS.DAL.CMS.ObjectDocument.Object cmsobject1 = objectBO1.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.MANUFACTURER); OrganizationObject organizatoinObject1 = new OrganizationObject(session) { ObjectId = cmsobject1, OrganizationId = CurrentManufacturerOrg }; organizatoinObject1.Save(); // OrganizationCustomType OrganizationCustomType organizationCustomType1 = new OrganizationCustomType(session) { ObjectTypeId = objectType1, OrganizationId = CurrentManufacturerOrg }; organizationCustomType1.Save(); session.CommitTransaction(); } catch (Exception) { session.RollbackTransaction(); throw; } OrganizationObject organizationObject1 = CurrentManufacturerOrg.OrganizationObjects.FirstOrDefault(); grid_of_Manufacturer.CMSObjectId = organizationObject1.ObjectId.ObjectId; grid_of_Manufacturer.DataBind(); } else { OrganizationObject organizationObject1 = CurrentManufacturerOrg.OrganizationObjects.FirstOrDefault(); grid_of_Manufacturer.CMSObjectId = organizationObject1.ObjectId.ObjectId; grid_of_Manufacturer.DataBind(); } #endregion //2013-11-22 Khoa.Truong DEL START //gridviewCustomFields.CMSObjectId = CurrentManufacturerOrg.ObjectId.ObjectId; //gridviewCustomFields.DataBind(); //2013-11-22 Khoa.Truong DEL END } break; case "save": bool isSuccess = true; string recordIdStr = null; try { //Check validation if (!ASPxEdit.AreEditorsValid(pagMunufacturer, true)) { popManufacturerEdit.JSProperties.Add("cpInvalid", true); pagMunufacturer.ActiveTabIndex = 0; return; } //Logic to save data if (args.Length > 1) { //Update mode //Update general information recordIdStr = args[1]; Guid recordId = Guid.Parse(recordIdStr); ManufacturerOrg editManufacturerOrg = session.GetObjectByKey <ManufacturerOrg>(PrivateSession.Instance.ManufacturerOrgId); editManufacturerOrg.Code = txtCode.Text; editManufacturerOrg.Name = txtName.Text; editManufacturerOrg.RowStatus = short.Parse(cbRowStatus.SelectedItem.Value.ToString()); editManufacturerOrg.Save(); } else { //Insert mode ManufacturerOrg newManufacturerOrg = session.GetObjectByKey <ManufacturerOrg>(PrivateSession.Instance.ManufacturerOrgId); newManufacturerOrg.Code = txtCode.Text; newManufacturerOrg.Name = txtName.Text; newManufacturerOrg.RowStatus = short.Parse(cbRowStatus.SelectedItem.Value.ToString()); newManufacturerOrg.Save(); } } catch (Exception ex) { isSuccess = false; throw; } finally { popManufacturerEdit.JSProperties.Add("cpCallbackArgs", String.Format("{{ \"recordId\": \"{0}\", \"isSuccess\": {1} }}", recordIdStr, isSuccess.ToString().ToLower())); } break; default: break; } }
/// <summary> /// Set controls from organization properties for UI displaying. /// </summary> /// <param name="org"></param> protected virtual void SetControlsFromOrgProperties(OrganizationObject org) { if (org.ParentOrganizationId.HasValue && this.ParentOrganizationSelector != null) this.ParentOrganizationSelector.SelectedOrganization = organizationApi.GetOrganization(org.ParentOrganizationId.Value); if (org.Hierarchies.ContainsKey(platformConfiguration.AreaHierarchyTypeValue) && org.Hierarchies[platformConfiguration.AreaHierarchyTypeValue] != null && this.AssociatedAreaSelector != null) { HierarchyDataObject hierarchyDataObject = hierarchyApi.GetHierarchyData(org.Hierarchies[platformConfiguration.AreaHierarchyTypeValue]); this.AssociatedAreaSelector.SelectedItems = new MyControls.HierarchyItem[] { new MyControls.HierarchyItem { Id = hierarchyDataObject.HierarchyDataId, Name = hierarchyDataObject.Name } }; } if (this.TextBoxOrganizationCode != null) this.TextBoxOrganizationCode.Text = org.OrganizationCode; if (this.TextBoxOrganizationName != null) this.TextBoxOrganizationName.Text = org.OrganizationName; if (this.DropDownListOrganizationType != null) this.DropDownListOrganizationType.SelectedValue = org.OrganizationTypeId.ToString(); if (this.RadioButtonListOrganizationStatus != null) this.RadioButtonListOrganizationStatus.SelectedValue = org.Status.ToString(); if (this.TextBoxDescription != null) this.TextBoxDescription.Text = org.Description; this.OrganizationExtensionDataForm.SetControlValuesFromObjectProperties(org); if (this.PlaceHolderOperatorContext != null) this.PlaceHolderOperatorContext.Visible = true; if (this.UserLinkCreatedBy != null) this.UserLinkCreatedBy.UserId = org.CreatedBy.ToString(); if (this.UserLinkLastModifiedBy != null) this.UserLinkLastModifiedBy.UserId = org.LastUpdatedBy.ToString(); if (this.TextBoxCreatedOn != null) this.TextBoxCreatedOn.Text = LocalizationUtility.ToDateTimeString(org.CreatedDate); if (this.TextBoxLastModifiedOn != null) this.TextBoxLastModifiedOn.Text = LocalizationUtility.ToDateTimeString(org.LastUpdatedDate); }
public void FindChildOrganization() { _story = new Story("Find More than one Child Organizations of Parent Organization By IOrganizationApi"); _story.AsA("User") .IWant("to be able to find more than one existing Child Organization") .SoThat("I can get the child organization"); IEnumerable<Guid> _temp = null; _story.WithScenario("find more than one existing Child Organization ") .Given("the GUID of the parent organization", () => { _OrganTypeObject1 = _utils.CreateOrganizationTypeOject("Depart","Inc"); _organizationApi.Save(_OrganTypeObject1); createdOrganizationTypeIds.Add(_OrganTypeObject1.OrganizationTypeId); _OrganObject1 = _utils.CreateOrganizationObject(_OrganTypeObject1.OrganizationTypeId, "wuhan2", "wuhan2"); _organizationApi.Save(_OrganObject1); createdOrganizationIds.Add(_OrganObject1.OrganizationId); _OrganObject2 = _utils.CreateOrganizationObject(_OrganTypeObject1.OrganizationTypeId, "wuhan3", "wuhan3"); _OrganObject2.ParentOrganizationId = _OrganObject1.OrganizationId; _organizationApi.Save(_OrganObject2); createdOrganizationIds.Add(_OrganObject2.OrganizationId); _OrganObject3 = _utils.CreateOrganizationObject(_OrganTypeObject1.OrganizationTypeId, "tianjiang", "tianjiang"); _OrganObject3.ParentOrganizationId = _OrganObject1.OrganizationId; _organizationApi.Save(_OrganObject3); createdOrganizationIds.Add(_OrganObject3.OrganizationId); }) .When("I get the GUID of children organization", () => { _temp = _organizationApi.FindAllEnabledChildOrganizationIds(_OrganObject1.OrganizationId); }) .Then("I can confirm GUID of Children in this List", () => { _temp.Contains(_OrganObject2.OrganizationId); _temp.Contains(_OrganObject3.OrganizationId); }); this.CleanUp(); }
private static OrganizationObject Convert2OrganizationObject(MembershipDataContext ctx, Organization org) { OrganizationObject organizationObject = new OrganizationObject() { ExtensionDataTypeId = org.ExtensionDataTypeId, OrganizationId = org.OrganizationId, OrganizationCode = org.OrganizationCode, OrganizationName = org.OrganizationName, OrganizationTypeId = org.OrganizationTypeId, Description = org.Description, Status = org.Status, CreatedBy = org.CreatedBy, CreatedDate = org.CreatedDate, LastUpdatedBy = org.LastUpdatedBy, LastUpdatedDate = org.LastUpdatedDate, ParentOrganizationId = org.ParentOrganizationId }; foreach (OrganizationsInHierarchy organizationsInHierarchy in org.Hierarchies) organizationObject.Hierarchies[organizationsInHierarchy.HierarchyType] = organizationsInHierarchy.HierarchyDataId; organizationObject.ParseExtensionPropertiesFrom(org); return organizationObject; }
/// <summary> /// Find organization elements by enumerable organization ids. /// </summary> /// <param name="organizationIdList">enumerabe organization type ids, null or empty value indicates to query all organizations</param> /// <returns></returns> private IDictionary<Guid, OrganizationObject> BulkGetOrganizationsFromDB(IEnumerable<Guid> organizationIdList) { try { if (organizationIdList.Count() == 0) return new Dictionary<Guid, OrganizationObject>(); Guid[] organizationIdArray = organizationIdList.ToArray(); using (MembershipDataContext ctx = DataContextFactory.Create<MembershipDataContext>()) { // collect all organizations var q = ctx.Organizations.Where(org => organizationIdArray.Contains(org.OrganizationId) && org.ApplicationId == authenticationContext.ApplicationId); List<Organization> organizations = (from org in ctx.Organizations where organizationIdArray.Contains(org.OrganizationId) && org.ApplicationId == authenticationContext.ApplicationId select org).Distinct().ToList(); // collect related hierarchies for the organizations. var organizationsInHierarchyDictionary = (from organizationsInHierarchy in ctx.OrganizationsInHierarchies where organizationsInHierarchy.ApplicationId == this.authenticationContext.ApplicationId && organizationIdArray.Contains(organizationsInHierarchy.OrganizationId) group organizationsInHierarchy by organizationsInHierarchy.OrganizationId into g select g).ToDictionary(g => g.Key, g => g.ToList()); List<OrganizationObject> organizationObjects = new List<OrganizationObject>(); // go through each organization to parse dynamic properties and hierarchies. foreach (Organization org in organizations) { OrganizationObject organizationObject = new OrganizationObject() { ExtensionDataTypeId = org.ExtensionDataTypeId, OrganizationId = org.OrganizationId, OrganizationCode = org.OrganizationCode, OrganizationName = org.OrganizationName, OrganizationTypeId = org.OrganizationTypeId, Description = org.Description, Status = org.Status, CreatedBy = org.CreatedBy, CreatedDate = org.CreatedDate, LastUpdatedBy = org.LastUpdatedBy, LastUpdatedDate = org.LastUpdatedDate, ParentOrganizationId = org.ParentOrganizationId }; if (organizationsInHierarchyDictionary.ContainsKey(org.OrganizationId)) { List<OrganizationsInHierarchy> organizationsInHierarchies = organizationsInHierarchyDictionary[org.OrganizationId]; foreach (OrganizationsInHierarchy organizationsInHierarchy in organizationsInHierarchies) organizationObject.Hierarchies[organizationsInHierarchy.HierarchyType] = organizationsInHierarchy.HierarchyDataId; } organizationObject.ParseExtensionPropertiesFrom(org); base.AddCache(organizationObject.OrganizationId, organizationObject.Clone()); UpdateTimeZone(organizationObject); organizationObjects.Add(organizationObject); } return organizationObjects.ToDictionary(org => org.OrganizationId, org => org); } } catch (Exception exp) { Logger.Instance(this).Error(exp); throw; } }
public void HierarchyTreeStory() { _story = new Story("Save the Hierarchy data And Bind to Organization Type"); _story.AsA("User") .IWant("Create Hierarchy Data") .SoThat("I can bind the Hierarchy to the object that have cascade relationship"); _story.WithScenario("Save Hierarchy Data") .Given("a Hierarchy data which is new ", () => { _HierarchyDataObject = new HierarchyDataObject() { Code = "1111", Description = "Sample", HierarchyType = "Tree", Name = "Root" }; _HierarchyApi.Save(_HierarchyDataObject); createHierarchyIds.Add(_HierarchyDataObject.Id); }) .And("create More than one Organization ", () => { _OrganizationTypeObject1 = _Organutils.CreateOrganizationTypeOject("Root", "Inc"); _OrganizationApi.Save(_OrganizationTypeObject1); createdOrganizationTypeIds.Add(_OrganizationTypeObject1.OrganizationTypeId); _OrganizationObject1 = _Organutils.CreateOrganizationObject(_OrganizationTypeObject1.OrganizationTypeId, "Tim", "sh"); _OrganizationObject2 = _Organutils.CreateOrganizationObject(_OrganizationTypeObject1.OrganizationTypeId, "Euge", "sc"); _OrganizationApi.Save(_OrganizationObject1); _OrganizationApi.Save(_OrganizationObject2); createdOrganizationIds.Add(_OrganizationObject1.OrganizationId); createdOrganizationIds.Add(_OrganizationObject2.OrganizationId); }) .When("Have the Hierarchy Data", () => { _HierarchyDataObject1 = _HierarchyApi.GetHierarchyData(_HierarchyDataObject.Id); _HierarchyDataObject2 = _HierarchyApi.GetHierarchyData("Tree", "Root"); _HierarchyDataObject1.Id.ShouldEqual(_HierarchyDataObject.Id); _HierarchyDataObject2.Id.ShouldEqual(_HierarchyDataObject.Id); }) .Then("I can use the Hierarchy Data to bind to Organization object", () => { _RelationshipObject1 = new RelationshipObject() { ReferenceObjectId = _HierarchyDataObject.Id, RelationshipType = "Tree" }; _RelationShipApi.Save(_OrganizationObject1.OrganizationId, _RelationshipObject1); _RelationShipApi.Save(_OrganizationObject2.OrganizationId, _RelationshipObject1); _RelationshipObject2 = _RelationShipApi.GetOneToOne(_OrganizationObject1.OrganizationId, _RelationshipObject1.RelationshipType); _RelationshipObject3 = _RelationShipApi.GetOneToOne(_OrganizationObject2.OrganizationId, _RelationshipObject1.RelationshipType); _RelationshipObject2.ReferenceObjectId.ShouldEqual(_RelationshipObject3.ReferenceObjectId); _RelationshipObject2.Ordinal.ShouldEqual(_RelationshipObject3.Ordinal); }) .WithScenario("How to create Hierarchy in Organization") .Given("Remove the relationship between Organ1 and Organ2", () => { _RelationShipApi.Remove(_OrganizationObject1.OrganizationId); _RelationShipApi.Remove(_OrganizationObject2.OrganizationId, "Tree"); }) .And("Create a child Hierarchy data ", () => { _HierarchyDataObject2 = new HierarchyDataObject() { Code = "1111", Description = "Sample", HierarchyType = "Tree", Name = "Leaf", ParentHierarchyDataId = _HierarchyDataObject.Id }; _HierarchyApi.Save(_HierarchyDataObject2); }) .When("I add the hierarchy data to Organization", () => { _OrganizationObject1.Hierarchies.Add("Tree", _HierarchyDataObject.Id); _OrganizationObject2.Hierarchies.Add("Tree", _HierarchyDataObject2.Id); _OrganizationApi.Save(_OrganizationObject1); _OrganizationApi.Save(_OrganizationObject2); }) .Then("I can get children HierarchyData by Hierarchy", () => { _HierarchyDataObject1 = null; _HierarchyDataObject1 = _HierarchyApi.GetImmediateChildren("Tree", _HierarchyDataObject.Id).FirstOrDefault(); _HierarchyDataObject1.Id.ShouldEqual(_HierarchyDataObject2.Id); }) .WithScenario("Delete the children Hierarchy Data") .Given("an Existing parent Hierarchy Data and an existing child", () => { }) .When("I delete the parent hierarchy Data", () => { _HierarchyApi.DeleteHierarchyData(_HierarchyDataObject.Id); }) .Then("I cannot get the parent data, and Organization should not have this Hierarchy data", () => { }); this.CleanUp(); }
public void BulkGetOrganizations() { _story = new Story("Find More than one Organizations By IOrganizationApi"); _story.AsA("User") .IWant("to be able to find more than one existing Organization") .SoThat("I can get the organizations"); IDictionary<Guid, OrganizationObject> _temp = null; _story.WithScenario("find more than Organization ") .Given("the a bunch of GUID of the organizations", () => { _OrganTypeObject1 = _utils.CreateOrganizationTypeOject("Depart","Inc"); _organizationApi.Save(_OrganTypeObject1); createdOrganizationTypeIds.Add(_OrganTypeObject1.OrganizationTypeId); _OrganObject1 = _utils.CreateOrganizationObject(_OrganTypeObject1.OrganizationTypeId, "sh1", "sh1"); _organizationApi.Save(_OrganObject1); createdOrganizationIds.Add(_OrganObject1.OrganizationId); _OrganObject2 = _utils.CreateOrganizationObject(_OrganTypeObject1.OrganizationTypeId, "sh2", "sh2"); _OrganObject2.ParentOrganizationId = _OrganObject1.OrganizationId; _organizationApi.Save(_OrganObject2); createdOrganizationIds.Add(_OrganObject2.OrganizationId); _OrganObject3 = _utils.CreateOrganizationObject(_OrganTypeObject1.OrganizationTypeId, "sh3", "sh3"); _OrganObject3.ParentOrganizationId = _OrganObject1.OrganizationId; _organizationApi.Save(_OrganObject3); createdOrganizationIds.Add(_OrganObject3.OrganizationId); }) .When("I call bulkget organizations", () => { _temp = _organizationApi.BulkGetOrganizations(createdOrganizationIds); }) .Then("I can get all the organizations in this List", () => { _temp[_OrganObject2.OrganizationId].ShouldEqual(_OrganObject2); _temp[_OrganObject3.OrganizationId].ShouldEqual(_OrganObject3); _temp[_OrganObject1.OrganizationId].ShouldEqual(_OrganObject1); }); this.CleanUp(); }
protected void popCustomerEdit_WindowCallback(object source, DevExpress.Web.ASPxPopupControl.PopupWindowCallbackArgs e) { string[] args = e.Parameter.Split('|'); switch (args[0]) { case "new": CustomerOrg tempCustomerOrg = CustomerOrg.InitNewRow(session); PrivateSession.Instance.CustomerOrgId = tempCustomerOrg.OrganizationId; dsCustomer.CriteriaParameters["CustomerOrgId"].DefaultValue = PrivateSession.Instance.CustomerOrgId.ToString(); ClearForm(); initLbCustomerTypeForAdding(); #region customer session.BeginTransaction(); try { ObjectType objectType_cus = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER); NAS.BO.CMS.ObjectDocument.ObjectBO objectBO_cus = new NAS.BO.CMS.ObjectDocument.ObjectBO(); NAS.DAL.CMS.ObjectDocument.Object cmsObject_cus = objectBO_cus.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER); // OrganizationObject OrganizationObject organizatoinObject_cus = new OrganizationObject(session) { ObjectId = cmsObject_cus, OrganizationId = tempCustomerOrg }; organizatoinObject_cus.Save(); // OrganizationCustomType OrganizationCustomType organizationCustomType_cus = new OrganizationCustomType(session) { ObjectTypeId = objectType_cus, OrganizationId = tempCustomerOrg }; organizationCustomType_cus.Save(); session.CommitTransaction(); } catch (Exception) { session.RollbackTransaction(); throw; } if (lbCustomerType.Items[0].Selected == true) { xCallbackPanel_customer.Visible = true; ObjectType objectType_cus1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER); OrganizationObject organizationObject_sup = tempCustomerOrg.OrganizationObjects .Where(r => r.ObjectId.ObjectTypeId == objectType_cus1).FirstOrDefault(); grid_customer.CMSObjectId = organizationObject_sup.ObjectId.ObjectId; grid_customer.DataBind(); //grid_customer.CMSObjectId = cmsObject_cus.ObjectId; //grid_customer.DataBind(); } else { xCallbackPanel_customer.Visible = false; } #endregion #region supplier session.BeginTransaction(); try { ObjectType objectType_sup = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER); NAS.BO.CMS.ObjectDocument.ObjectBO objectBO_sup = new NAS.BO.CMS.ObjectDocument.ObjectBO(); NAS.DAL.CMS.ObjectDocument.Object cmsObject_sup = objectBO_sup.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER); // OrganizationObject OrganizationObject organizatoinObject_sup = new OrganizationObject(session) { ObjectId = cmsObject_sup, OrganizationId = tempCustomerOrg }; organizatoinObject_sup.Save(); // OrganizationCustomType OrganizationCustomType organizationCustomType_sup = new OrganizationCustomType(session) { ObjectTypeId = objectType_sup, OrganizationId = tempCustomerOrg }; organizationCustomType_sup.Save(); session.CommitTransaction(); } catch (Exception) { session.RollbackTransaction(); throw; } if (lbCustomerType.Items[1].Selected == true) { xCallbackPanel_supplier.Visible = true; ObjectType objectType_sup1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER); OrganizationObject organizationObject_sup = tempCustomerOrg.OrganizationObjects .Where(r => r.ObjectId.ObjectTypeId == objectType_sup1).FirstOrDefault(); grid_supplier.CMSObjectId = organizationObject_sup.ObjectId.ObjectId; grid_supplier.DataBind(); //grid_supplier.CMSObjectId = cmsObject_sup.ObjectId; //grid_supplier.DataBind(); } else { xCallbackPanel_supplier.Visible = false; } #endregion break; case "edit": ClearForm(); if (args.Length > 1) { PrivateSession.Instance.CustomerOrgId = Guid.Parse(args[1]); dsCustomer.CriteriaParameters["CustomerOrgId"].DefaultValue = PrivateSession.Instance.CustomerOrgId.ToString(); txtCode.Text = CurrentCustomerOrg.Code; loadLbCustomerType(); if (CurrentCustomerOrg.OrganizationObjects.FirstOrDefault() == null) { #region customer session.BeginTransaction(); try { ObjectType objectType_cus1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER); NAS.BO.CMS.ObjectDocument.ObjectBO objectBO_cus1 = new NAS.BO.CMS.ObjectDocument.ObjectBO(); NAS.DAL.CMS.ObjectDocument.Object cmsObject_cus1 = objectBO_cus1.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER); // OrganizationObject OrganizationObject organizatoinObject_cus1 = new OrganizationObject(session) { ObjectId = cmsObject_cus1, OrganizationId = CurrentCustomerOrg }; organizatoinObject_cus1.Save(); // OrganizationCustomType OrganizationCustomType organizationCustomType_cus1 = new OrganizationCustomType(session) { ObjectTypeId = objectType_cus1, OrganizationId = CurrentCustomerOrg }; organizationCustomType_cus1.Save(); session.CommitTransaction(); } catch (Exception) { session.RollbackTransaction(); throw; } if (lbCustomerType.Items[0].Selected == true) { xCallbackPanel_customer.Visible = true; ObjectType objectType_cus1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER); OrganizationObject organizationObject_sup = CurrentCustomerOrg.OrganizationObjects .Where(r => r.ObjectId.ObjectTypeId == objectType_cus1).FirstOrDefault(); grid_customer.CMSObjectId = organizationObject_sup.ObjectId.ObjectId; grid_customer.DataBind(); //grid_customer.CMSObjectId = cmsObject_cus1.ObjectId; //grid_customer.DataBind(); } else { xCallbackPanel_customer.Visible = false; } #endregion #region supplier session.BeginTransaction(); try { ObjectType objectType_sup1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER); NAS.BO.CMS.ObjectDocument.ObjectBO objectBO_sup1 = new NAS.BO.CMS.ObjectDocument.ObjectBO(); NAS.DAL.CMS.ObjectDocument.Object cmsObject_sup1 = objectBO_sup1.CreateCMSObject(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER); // OrganizationObject OrganizationObject organizatoinObject_sup1 = new OrganizationObject(session) { ObjectId = cmsObject_sup1, OrganizationId = CurrentCustomerOrg }; organizatoinObject_sup1.Save(); // OrganizationCustomType OrganizationCustomType organizationCustomType_sup1 = new OrganizationCustomType(session) { ObjectTypeId = objectType_sup1, OrganizationId = CurrentCustomerOrg }; organizationCustomType_sup1.Save(); session.CommitTransaction(); } catch (Exception) { session.RollbackTransaction(); throw; } if (lbCustomerType.Items[1].Selected == true) { xCallbackPanel_supplier.Visible = true; ObjectType objectType_sup1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER); OrganizationObject organizationObject_sup = CurrentCustomerOrg.OrganizationObjects .Where(r => r.ObjectId.ObjectTypeId == objectType_sup1).FirstOrDefault(); grid_supplier.CMSObjectId = organizationObject_sup.ObjectId.ObjectId; grid_supplier.DataBind(); //grid_supplier.CMSObjectId = cmsObject_sup1.ObjectId; //grid_supplier.DataBind(); } else { xCallbackPanel_supplier.Visible = false; } #endregion } else { #region load customer data if (lbCustomerType.Items[0].Selected == true) { xCallbackPanel_customer.Visible = true; ObjectType objectType_cus1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.CUSTOMER); OrganizationObject organizationObject_sup = CurrentCustomerOrg.OrganizationObjects .Where(r => r.ObjectId.ObjectTypeId == objectType_cus1).FirstOrDefault(); grid_customer.CMSObjectId = organizationObject_sup.ObjectId.ObjectId; grid_customer.DataBind(); } else { xCallbackPanel_customer.Visible = false; } #endregion #region load supplier data if (lbCustomerType.Items[1].Selected == true) { xCallbackPanel_supplier.Visible = true; ObjectType objectType_sup1 = ObjectType.GetDefault(session, NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.SUPPLIER); OrganizationObject organizationObject_sup = CurrentCustomerOrg.OrganizationObjects .Where(r => r.ObjectId.ObjectTypeId == objectType_sup1).FirstOrDefault(); grid_supplier.CMSObjectId = organizationObject_sup.ObjectId.ObjectId; grid_supplier.DataBind(); } else { xCallbackPanel_supplier.Visible = false; } #endregion } } break; case "save": bool isSuccess = true; string recordIdStr = null; try { session.BeginTransaction(); //Check validation if (!IsSelectedLbType()) { throw new Exception(String.Format("Phải chọn ít nhất một phân loại cho khách hàng")); } if (!ASPxEdit.AreEditorsValid(pagCustomer, true)) { popCustomerEdit.JSProperties.Add("cpInvalid", true); pagCustomer.ActiveTabIndex = 0; return; } //Logic to save data if (args.Length > 1) { //Update mode //Update general information recordIdStr = args[1]; Guid recordId = Guid.Parse(recordIdStr); Organization editCustomerOrg = session.GetObjectByKey <Organization>(PrivateSession.Instance.CustomerOrgId); editCustomerOrg.Code = txtCode.Text; editCustomerOrg.Name = txtName.Text; editCustomerOrg.TaxNumber = txtTaxNumber.Text; // Duc.Vo 10/09/2013 INS-START editCustomerOrg.Address = txtAddress.Text; // Duc.Vo 10/09/2013 INS-START editCustomerOrg.RowStatus = short.Parse(cbRowStatus.SelectedItem.Value.ToString()); //----Duc.Vo 03/11/2013 INS -START selectedObjectTypeId = new List <Guid>(); foreach (ListEditItem l in lbCustomerType.Items) { if (l.Selected) { selectedObjectTypeId.Add(Guid.Parse(l.Value.ToString())); } } if (editCustomerOrg is SupplierOrg) { supplierBO.updateTradingCategoriesForObject <SupplierOrg>(session, recordId, selectedObjectTypeId); } else { supplierBO.updateTradingCategoriesForObject <CustomerOrg>(session, recordId, selectedObjectTypeId); } //----Duc.Vo 03/11/2013 INS -END editCustomerOrg.Save(); session.CommitTransaction(); } else { //Insert mode CustomerOrg newCustomerOrg = session.GetObjectByKey <CustomerOrg>(PrivateSession.Instance.CustomerOrgId); newCustomerOrg.Code = txtCode.Text; newCustomerOrg.Name = txtName.Text; newCustomerOrg.TaxNumber = txtTaxNumber.Text; // Duc.Vo 10/09/2013 INS-START newCustomerOrg.Address = txtAddress.Text; // Duc.Vo 10/09/2013 INS-START newCustomerOrg.RowStatus = short.Parse(cbRowStatus.SelectedItem.Value.ToString()); newCustomerOrg.Save(); //----Duc.Vo 03/11/2013 INS -START selectedObjectTypeId = new List <Guid>(); foreach (ListEditItem l in lbCustomerType.Items) { if (l.Selected) { selectedObjectTypeId.Add(Guid.Parse(l.Value.ToString())); } } supplierBO.updateTradingCategoriesForObject <CustomerOrg>(session, newCustomerOrg.OrganizationId, selectedObjectTypeId); //----Duc.Vo 03/11/2013 INS -END session.CommitTransaction(); } } catch (Exception ex) { session.RollbackTransaction(); isSuccess = false; throw; } finally { popCustomerEdit.JSProperties.Add("cpCallbackArgs", String.Format("{{ \"recordId\": \"{0}\", \"isSuccess\": {1} }}", recordIdStr, isSuccess.ToString().ToLower())); } break; default: break; } }
/// <summary> /// Create a new organization and return the id. /// </summary> /// <returns>returns the id of new created organization.</returns> public override string Create() { this.ValidateDataInputForm(null); OrganizationObject org = new OrganizationObject { ExtensionDataTypeId = this.ResolveOrganizationExtensionDataTypeId() }; SetOrgPropertiesFromControls(org); organizationApi.Save(org); return org.OrganizationId.ToString(); }
/// <summary> /// Set organization properties from controls for saving the organization. /// </summary> /// <param name="org"></param> protected virtual void SetOrgPropertiesFromControls(OrganizationObject org) { if (this.AssociatedAreaSelector != null && this.AssociatedAreaSelector.SelectedItems != null && this.AssociatedAreaSelector.SelectedItems.Count() > 0) org.Hierarchies[platformConfiguration.AreaHierarchyTypeValue] = this.AssociatedAreaSelector.SelectedItems.FirstOrDefault().Id; else org.Hierarchies.Remove(platformConfiguration.AreaHierarchyTypeValue); if (this.TextBoxOrganizationCode != null) org.OrganizationCode = this.TextBoxOrganizationCode.Text; if (this.TextBoxOrganizationName != null) org.OrganizationName = this.TextBoxOrganizationName.Text; if (this.ParentOrganizationSelector != null) org.ParentOrganizationId = this.ParentOrganizationSelector.SelectedOrganization != null ? this.ParentOrganizationSelector.SelectedOrganization.OrganizationId : (Guid?)null; if (this.DropDownListOrganizationType != null) org.OrganizationTypeId = new Guid(this.DropDownListOrganizationType.SelectedValue); if (this.RadioButtonListOrganizationStatus != null) org.Status = (OrganizationStatus)Enum.Parse(typeof(OrganizationStatus), this.RadioButtonListOrganizationStatus.SelectedValue); if (this.TextBoxDescription != null) org.Description = this.TextBoxDescription.Text; this.OrganizationExtensionDataForm.SetObjectPropertiesFromControlValues(org); }
public void GetOrganizationWithCorrectGuidAndCorrectName() { _story = new Story("Find a Organization By IOrganizationApi"); _story.AsA("User") .IWant("to be able to find an existing Organization") .SoThat("I can modify the object"); _story.WithScenario("find an existing Organization ") .Given("the GUID and Name of the organization", () => { _OrganTypeObject1 = _utils.CreateOrganizationTypeOject("Depart","Inc"); _organizationApi.Save(_OrganTypeObject1); createdOrganizationTypeIds.Add(_OrganTypeObject1.OrganizationTypeId); _OrganObject1 = _utils.CreateOrganizationObject(_OrganTypeObject1.OrganizationTypeId, "hangzhou1", "hangzhou1"); _organizationApi.Save(_OrganObject1); createdOrganizationIds.Add(_OrganObject1.OrganizationId); }) .When("I get the organization", () => { _OrganObject2 = _organizationApi.GetOrganization(_OrganObject1.OrganizationId); _OrganObject3 = _organizationApi.GetOrganizationByName(_OrganObject1.OrganizationName); _OrganObject4 = _organizationApi.GetOrganizationByCode(_OrganObject1.OrganizationCode); }) .Then("I Get two same Organization", () => { _OrganObject2.ShouldEqual(_OrganObject1); _OrganObject2.ShouldEqual(_OrganObject3); _OrganObject2.ShouldEqual(_OrganObject4); }); this.CleanUp(); }
/// <summary> /// Validation on if there specifies parent organization to new created one, the status of new organization must be lower priority than its parent. /// Organization status priority: Enabled > Pending > Disabled. /// </summary> /// <param name="parentOrganizationObject"></param> /// <param name="status"></param> /// <param name="organizationName"></param> /// <param name="validationScope"></param> private void VerifyStatusAgainstParentOrganization(OrganizationObject parentOrganizationObject, OrganizationStatus status, string organizationName, ValidationScope validationScope) { OrganizationStatus parentStatus = parentOrganizationObject.Status; if ((int)parentStatus < (int)status) validationScope.Error(Resources.OrganizationStatusCannotBeHigherThanParent, parentOrganizationObject.OrganizationName, parentStatus, organizationName, status); }
bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) { string comboboxKey = string.Format(CultureInfo.InvariantCulture, "{0}$ComboBox", postDataKey); string selectedItemValue = postCollection[comboboxKey]; if (!string.IsNullOrEmpty(selectedItemValue)) { Guid organizationId = new Guid(selectedItemValue); this.selectedOrganizationObject = organizationApi.GetOrganization(organizationId); } return true; }
/// <summary> /// Update an existed organization. /// </summary> /// <param name="entityId"></param> public override void Update(string entityId) { Guid organizationId = new Guid(entityId); OrganizationObject orgToUpdate = organizationApi.GetOrganization(organizationId); if (orgToUpdate == null) throw new ValidationException(Resources.InvalidOrganizationID); orgToUpdate.ExtensionDataTypeId = this.ResolveOrganizationExtensionDataTypeId(); this.ValidateDataInputForm(organizationId); OrganizationObject org = new OrganizationObject { OrganizationId = organizationId, ExtensionDataTypeId = orgToUpdate.ExtensionDataTypeId }; SetOrgPropertiesFromControls(org); organizationApi.Save(org); }
/// <summary> /// Save organization business object. /// If organizationObject.Id equals Guid.Empty, it means to save a new organization. /// Otherwise it's updating an existed organization. /// </summary> /// <param name="organizationObject"></param> public void Save(OrganizationObject organizationObject) { Kit.NotNull(organizationObject, "organizationObject"); Kit.NotNull(organizationObject.OrganizationCode, "organizationObject.OrganizationCode"); Kit.NotNull(organizationObject.OrganizationName, "organizationObject.OrganizationName"); if (organizationObject.OrganizationTypeId == Guid.Empty) throw new ArgumentException(Resources.InvalidOrganizationTypeID); if (organizationObject.Status == OrganizationStatus.None) throw new ArgumentException(Resources.OrganizationStatusNotSpecified, "organizationObject.Status"); try { using (TransactionScope transactionScope = new TransactionScope()) { bool isUpdate = organizationObject.OrganizationId != Guid.Empty; this.SaveOrganization(organizationObject); // remove the cache for update if (isUpdate) base.RemoveCache(organizationObject.OrganizationId); transactionScope.Complete(); UpdateTimeZone(organizationObject); } } catch (ValidationException) { throw; } catch (Exception exp) { Logger.Instance(this).Error(exp); throw; } }
/// <summary> /// Create an organization into specified application. /// </summary> /// <param name="applicationId"></param> /// <param name="organizationObject"></param> /// <param name="operatedUserId"></param> protected static void CreateOrganization(Guid applicationId, OrganizationObject organizationObject, Guid operatedUserId) { Kit.NotNull(organizationObject, "organizationObject"); try { using (MembershipDataContext ctx = DataContextFactory.Create<MembershipDataContext>()) { Organization organization = ExtensionObjectFactory.Create<Organization>(); organization.ApplicationId = applicationId; organization.OrganizationCode = organizationObject.OrganizationCode; organization.OrganizationName = organizationObject.OrganizationName; organization.OrganizationTypeId = organizationObject.OrganizationTypeId; organization.Status = organizationObject.Status; organization.Description = organizationObject.Description; organization.CreatedDate = DateTime.UtcNow; organization.CreatedBy = operatedUserId; organization.LastUpdatedDate = DateTime.UtcNow; organization.LastUpdatedBy = operatedUserId; organization.ParseExtensionPropertiesFrom(organizationObject); ctx.Organizations.InsertOnSubmit(organization); ctx.SubmitChanges(); organizationObject.OrganizationId = organization.OrganizationId; } } catch (ValidationException) { throw; } catch (Exception exp) { Logger.Instance(typeof(CredentialInstaller)).Error(exp); throw; } }
private static void UpdateTimeZone(OrganizationObject orgObject) { orgObject.CreatedDate = LocalizationUtility.ConvertUtcTimeToClientTime(orgObject.CreatedDate); orgObject.LastUpdatedDate = LocalizationUtility.ConvertUtcTimeToClientTime(orgObject.LastUpdatedDate); }
/// <summary> /// Save organization object /// </summary> /// <param name="organizationObject"></param> /// <returns></returns> public string SaveOrganizationJson(OrganizationObject organizationObject) { if (organizationObject == null) throw new BadRequestException(string.Format(CultureInfo.InvariantCulture, Resources.OrganizationCannotBeEmpty )); try { organizationApi.Save(organizationObject); return organizationObject.OrganizationId.ToString(); } catch (ArgumentException ex) { throw new BadRequestException(string.Format(CultureInfo.InvariantCulture, ex.Message)); } catch (BadRequestException bad) { throw new BadRequestException(string.Format(CultureInfo.InvariantCulture, bad.Message)); } catch (FormatException formatEx) { throw new BadRequestException(string.Format(CultureInfo.InvariantCulture, formatEx.Message)); } catch (Exception exp) { Logger.Instance(this).Error(exp); throw new InternalServerErrorException(); } }
/// <summary> /// Save organization business object. /// If organizationObject.Id equals Guid.Empty, it means to save a new organization. /// Otherwise it's updating an existed organization. /// </summary> /// <param name="organizationObject"></param> private void SaveOrganization(OrganizationObject organizationObject) { try { Organization organization = null; using (TransactionScope transactionScope = new TransactionScope()) using (MembershipDataContext ctx = DataContextFactory.Create<MembershipDataContext>()) { using (ValidationScope validationScope = new ValidationScope(true)) { // check duplicate organization name int existedOrganizationCount = (from org in ctx.Organizations where org.OrganizationName == organizationObject.OrganizationName && org.ApplicationId == this.authenticationContext.ApplicationId && org.OrganizationId != organizationObject.OrganizationId select org).Count(); if (existedOrganizationCount > 0) validationScope.Error(Resources.ExistedOrganizationName, organizationObject.OrganizationName); // check duplicate organization code if (!string.IsNullOrEmpty(organizationObject.OrganizationCode)) { existedOrganizationCount = (from org in ctx.Organizations where org.OrganizationCode == organizationObject.OrganizationCode && org.ApplicationId == this.authenticationContext.ApplicationId && org.OrganizationId != organizationObject.OrganizationId select org).Count(); if (existedOrganizationCount > 0) validationScope.Error(Resources.ExistedOrganizationCode, organizationObject.OrganizationCode); } // validate organization type OrganizationTypeObject organizationTypeObject = this.GetOrganizationType(organizationObject.OrganizationTypeId); if (organizationTypeObject == null) validationScope.Error(Resources.InvalidOrganizationTypeID); // validate organization located area if (organizationObject.Hierarchies != null && organizationObject.Hierarchies.Count > 0) { foreach (string hierarchyType in organizationObject.Hierarchies.Keys) { HierarchyDataObject hierarchyDataObject = hierarchyApi.GetHierarchyData(organizationObject.Hierarchies[hierarchyType]); if (hierarchyDataObject == null || !string.Equals(hierarchyDataObject.HierarchyType, hierarchyType, StringComparison.OrdinalIgnoreCase)) validationScope.Error(Resources.InvalidHierarchyAssociatedWithOrganization, hierarchyType, hierarchyDataObject.HierarchyDataId); } } // check circular reference of parent if (organizationObject.ParentOrganizationId.HasValue) { if (organizationObject.OrganizationId == organizationObject.ParentOrganizationId.Value) validationScope.Error(Resources.InvalidParentOrganizationID); if (organizationObject.OrganizationId != organizationObject.ParentOrganizationId.Value) { List<string> existedOrganizationNames = new List<string>(); HashSet<Guid> existedOrganizationIds = new HashSet<Guid> { organizationObject.OrganizationId }; OrganizationObject parentOrganizationObject = this.GetOrganization(organizationObject.ParentOrganizationId.Value); if (parentOrganizationObject == null) validationScope.Error(Resources.InvalidParentOrganizationID); else { this.VerifyStatusAgainstParentOrganization(parentOrganizationObject, organizationObject.Status, organizationObject.OrganizationName, validationScope); while (parentOrganizationObject != null) { existedOrganizationNames.Add(parentOrganizationObject.OrganizationName); if (existedOrganizationIds.Contains(parentOrganizationObject.OrganizationId)) { validationScope.Error(Resources.ParentOrganizationCircularReference, FormatCircularOrganizationNames(existedOrganizationNames)); break; } existedOrganizationIds.Add(parentOrganizationObject.OrganizationId); if (!parentOrganizationObject.ParentOrganizationId.HasValue) break; parentOrganizationObject = this.GetOrganization(parentOrganizationObject.ParentOrganizationId.Value); } } } } if (organizationObject.OrganizationId == Guid.Empty) { organization = ExtensionObjectFactory.Create<Organization>(organizationObject); organization.OrganizationCode = organizationObject.OrganizationCode; organization.CreatedDate = DateTime.UtcNow; organization.CreatedBy = this.authenticationContext.User.UserId; ctx.Organizations.InsertOnSubmit(organization); } else { organization = ctx.Organizations.FirstOrDefault(org => org.OrganizationId == organizationObject.OrganizationId); if (organization == null) validationScope.Error(Resources.InvalidOrganizationID); organization.ExtensionDataTypeId = organizationObject.ExtensionDataTypeId; if (organization.OrganizationCode != organizationObject.OrganizationCode) validationScope.Error(Resources.CodeCannotUpdate); // update status of all children only when updates status from Enabled to Disabled. if (organizationObject.Status == OrganizationStatus.Disabled && organization.Status == OrganizationStatus.Enabled) UpdateSubOrganizationsStatus(ctx, new[] { organization.OrganizationId }, organizationObject.Status); } } organization.ApplicationId = this.authenticationContext.ApplicationId; organization.OrganizationName = organizationObject.OrganizationName; organization.OrganizationTypeId = organizationObject.OrganizationTypeId; organization.ParentOrganizationId = organizationObject.ParentOrganizationId; organization.Status = organizationObject.Status; organization.Description = organizationObject.Description; organization.LastUpdatedDate = DateTime.UtcNow; organization.LastUpdatedBy = this.authenticationContext.User.UserId; // remove original hierarchies and added new ones if (organizationObject.OrganizationId != Guid.Empty && organization.Hierarchies.Count > 0) ctx.OrganizationsInHierarchies.DeleteAllOnSubmit(organization.Hierarchies); if (organizationObject.Hierarchies != null && organizationObject.Hierarchies.Count > 0) { foreach (string hierarchyType in organizationObject.Hierarchies.Keys) { HierarchyDataObject hierarchyDataObject = hierarchyApi.GetHierarchyData(organizationObject.Hierarchies[hierarchyType]); if (hierarchyDataObject != null) { ctx.OrganizationsInHierarchies.InsertOnSubmit(new OrganizationsInHierarchy { ApplicationId = authenticationContext.ApplicationId, HierarchyType = hierarchyType, HierarchyDataId = organizationObject.Hierarchies[hierarchyType], Organization = organization, }); } } } organization.ParseExtensionPropertiesFrom(organizationObject); ctx.SubmitChanges(); transactionScope.Complete(); organizationObject.OrganizationId = organization.OrganizationId; organizationObject.CreatedBy = organization.CreatedBy; organizationObject.CreatedDate = organization.CreatedDate; organizationObject.LastUpdatedBy = organization.LastUpdatedBy; organizationObject.LastUpdatedDate = organization.LastUpdatedDate; } } catch (ValidationException) { throw; } catch (Exception exp) { Logger.Instance(this).Error(exp); throw; } }
/// <summary> /// Save organization object /// </summary> /// <param name="organizationObject"></param> /// <returns></returns> public string SaveOrganizationXml(OrganizationObject organizationObject) { return SaveOrganizationJson(organizationObject); }
/// <summary> /// Find organization business objects by custom predicates. /// </summary> /// <param name="predicate">linq predicate. see organization properties for predicate at <see cref="RapidWebDev.Platform.Linq.Organization"/>.</param> /// <param name="orderby">dynamic orderby command</param> /// <param name="pageIndex">current paging index</param> /// <param name="pageSize">page size</param> /// <param name="recordCount">total hit records count</param> /// <returns>Returns enumerable organizations</returns> public IEnumerable<OrganizationObject> FindOrganizations(LinqPredicate predicate, string orderby, int pageIndex, int pageSize, out int recordCount) { try { using (MembershipDataContext ctx = DataContextFactory.Create<MembershipDataContext>()) { // set query criteria. var q = from org in ctx.Organizations where org.ApplicationId == authenticationContext.ApplicationId select org; if (predicate != null && !Kit.IsEmpty(predicate.Expression)) q = q.Where(predicate.Expression, predicate.Parameters); if (!Kit.IsEmpty(orderby)) q = q.OrderBy(orderby); // get count of matched organizations recordCount = q.Count(); // collect organizations List<Organization> organizations = q.Skip(pageIndex * pageSize).Take(pageSize).ToList(); // collect all OrganizationsInHierarchy entities of the organizations. Guid[] organizationIdArray = organizations.Select(org => org.OrganizationId).ToArray(); var organizationsInHierarchyDictionary = (from organizationsInHierarchy in ctx.OrganizationsInHierarchies where organizationsInHierarchy.ApplicationId == this.authenticationContext.ApplicationId && organizationIdArray.Contains(organizationsInHierarchy.OrganizationId) group organizationsInHierarchy by organizationsInHierarchy.OrganizationId into g select g).ToDictionary(g => g.Key, g => g.ToList()); List<OrganizationObject> organizationObjects = new List<OrganizationObject>(); // go through each organization to parse dynamic properties and hierarchies. foreach (Organization org in organizations) { OrganizationObject organizationObject = new OrganizationObject() { ExtensionDataTypeId = org.ExtensionDataTypeId, OrganizationId = org.OrganizationId, OrganizationCode = org.OrganizationCode, OrganizationName = org.OrganizationName, OrganizationTypeId = org.OrganizationTypeId, Description = org.Description, Status = org.Status, CreatedBy = org.CreatedBy, CreatedDate = org.CreatedDate, LastUpdatedBy = org.LastUpdatedBy, LastUpdatedDate = org.LastUpdatedDate, ParentOrganizationId = org.ParentOrganizationId }; if (organizationsInHierarchyDictionary.ContainsKey(org.OrganizationId)) { List<OrganizationsInHierarchy> organizationsInHierarchies = organizationsInHierarchyDictionary[org.OrganizationId]; foreach (OrganizationsInHierarchy organizationsInHierarchy in organizationsInHierarchies) organizationObject.Hierarchies[organizationsInHierarchy.HierarchyType] = organizationsInHierarchy.HierarchyDataId; } organizationObject.ParseExtensionPropertiesFrom(org); base.AddCache(organizationObject.OrganizationId, organizationObject.Clone()); UpdateTimeZone(organizationObject); organizationObjects.Add(organizationObject); } return organizationObjects; } } catch (Exception exp) { Logger.Instance(this).Error(exp); throw; } }
private WorldObject getOrginazationFromWord( ) { var res = new OrganizationObject(Text); return(res); }