public static OrganizationModelExtended ConvertToOrganizationModel(this Organization organization) { if (organization == null) { return(null); } var organizationModel = new OrganizationModelExtended { OrganizationType = organization.OrganizationType, OrgCustomerGroup = organization.OrgCustomerGroup, Contacts = organization.Contacts.Select(c => c.ConvertToContactModel()).ToList(), Addresses = organization.Addresses.Select(a => a.ConvertToAddressModel()).ToList(), ChildOrganizations = organization.ChildOrganizations.Select(o => o.ConvertToOrganizationModel()).ToList(), MetaFields = organization.GetMetaFields(new List <string>()) }; if (organization.PrimaryKeyId.HasValue) { organizationModel.PrimaryKeyId = organization.PrimaryKeyId.Value; } return(organizationModel); }
public virtual IHttpActionResult PostOrganization([FromBody] OrganizationModelExtended model) { var newOrganization = Organization.CreateInstance(); newOrganization.PrimaryKeyId = new PrimaryKeyId(model.PrimaryKeyId); newOrganization.OrgCustomerGroup = model.OrgCustomerGroup; newOrganization.OrganizationType = model.OrganizationType; newOrganization.UpdateMetaFields(model, new List <string>()); newOrganization.SaveChanges(); model = newOrganization.ConvertToOrganizationModel(); return(CreatedAtRoute("GetOrganization", new { orgId = model.PrimaryKeyId }, model)); }
public virtual IHttpActionResult PutOrganization(string id, [FromBody] OrganizationModelExtended model) { var existingOrg = CustomerContext.Current.GetOrganizationById(PrimaryKeyId.Parse(id)); if (existingOrg == null) { return(NotFound()); } existingOrg.OrgCustomerGroup = model.OrgCustomerGroup; existingOrg.OrganizationType = model.OrganizationType; existingOrg.UpdateMetaFields(model, new List <string>()); existingOrg.SaveChanges(); return(StatusCode(HttpStatusCode.NoContent)); }