private void Save(ConvertServiceRequest request)
        {
            var originalImageUrl = _viewModel.ImageUrl;

            _orgUnitId = int.Parse(GetFieldValue(_viewModel.Fields, _idField), CultureInfo.InvariantCulture);

            if (_orgUnitId == 0)
            {
                // Create main org unit record
                var addRequest = new AddOrgUnitRequest();
                PopulateRequestFieldValues(addRequest);

                _orgUnitId = ProcessRequest<AddOrgUnitResponse>(addRequest).Id;

                // Associate new org unit to tree root
                var addAssocRequest = new AddOrgUnitAssociationRequest
                {
                    PrimaryId = -1,
                    SecondaryId = _orgUnitId
                };

                ProcessRequest<AddOrgUnitAssociationResponse>(addAssocRequest);

                // Refresh model
                var detailResponse = QueryData(request);

                _viewModel.PageHeader = "Location - " + detailResponse.Location.Name;
                _viewModel.SubHeader = "Edit Location Information";
                _viewModel.SubEntities = BuildSubEntities(detailResponse.Location);
                _viewModel.Fields = BuildFields(detailResponse.Location, false);
            }
            else
            {
                //Main Location Record

                var updateRequest = new UpdateOrgUnitRequest { Id = _orgUnitId };
                PopulateRequestFieldValues(updateRequest);

                ProcessRequest<UpdateOrgUnitResponse>(updateRequest);

                var detailResponse = QueryData(request);
                _viewModel.PageHeader = "Location - " + detailResponse.Location.Name;
                _viewModel.SubHeader = "Edit Location Information";

                //Subentities
                foreach (var subentity in _viewModel.SubEntities)
                {
                    if (subentity.EntityName == _locationTypeSubEntity)
                        LocationTypesHelper.Save(this, subentity, _orgUnitId);
                    if (subentity.EntityName == _locationInsuranceSubEntity)
                        LocationInsurancesHelper.Save(this, subentity, _orgUnitId);
                    if (subentity.EntityName == _locationServiceSubEntity)
                        LocationServicesHelper.Save(this, subentity, _orgUnitId);
                    if (subentity.EntityName == _locationHourSubEntity)
                        LocationHoursHelper.Save(this, subentity, _orgUnitId);
                }
            }

            //Update SearchG2 record in index
            ProcessOneWayRequest(new UpdateLocationG2RecordRequest() { LocationId = _orgUnitId });

            // Upload location image if needed
            if (DigitalAssetManager.IsRawImageData(originalImageUrl))
                DigitalAssetManager.UploadImageAsset(Constants.Locations.LocationProfileImagePath + "/" + CalculateLocationImageName(originalImageUrl, _orgUnitId), originalImageUrl);
        }
예제 #2
0
        private string AddTreeNode(ConvertServiceRequest request)
        {
            try
            {
                if (!string.IsNullOrEmpty(request.Parameters["NodeTitle"]))
                {
                    var addRequest = new AddOrgUnitRequest
                    {
                        Name = request.Parameters["NodeTitle"],
                        IsEnabled = true,
                        IsBulkUpdateMode = true  //Org unit will be published when association is published below.
                    };

                    var addResponse = ProcessRequest<AddOrgUnitResponse>(addRequest);

                    var addAssocRequest = new AddOrgUnitAssociationRequest
                    {
                        PrimaryId = Convert.ToInt32(request.Parameters["ParentNodeId"]),
                        SecondaryId = addResponse.Id
                    };

                    ProcessRequest<AddOrgUnitAssociationResponse>(addAssocRequest);

                    _viewModel.Records.Add(new RecordBase() { Id = addResponse.Id });
                }
                else
                {
                    _viewModel.SetErrorMessage("Location Name is required");
                }
            }
            catch (Exception ex)
            {
                _viewModel.SetErrorMessage(ex.Message);
            }
            return CommonUtils.JsonSerialize(_viewModel);
        }