public ActionResult CreateOneToMany(OneToManyRelationshipModel oneToMany) { if (!Services.Authorizer.Authorize(Permissions.PublishContent, T("Not allowed to edit a content."))) { return(new HttpUnauthorizedResult()); } if (oneToMany.IsCreate) { var checkNameMessage = _relationshipService.CheckRelationName(oneToMany.Name); if (!string.IsNullOrWhiteSpace(checkNameMessage)) { ModelState.AddModelError("OneToManyRelation", T(checkNameMessage).ToString()); return(ResponseError("")); } var backMessage = _relationshipService.CreateRelationship(oneToMany); int relationId; if (int.TryParse(backMessage.ToString(), out relationId)) { return(Json(new { relationId = relationId })); } if (!string.IsNullOrWhiteSpace(backMessage)) { ModelState.AddModelError("OneToManyRelation", T(backMessage).ToString()); return(ResponseError("")); } } return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public string CreateRelationship(OneToManyRelationshipModel oneToMany) { if (oneToMany == null) { return("Invalid model."); } var primaryEntity = _contentMetadataService.GetEntity(oneToMany.PrimaryEntity); var relatedEntity = _contentMetadataService.GetDraftEntity(oneToMany.RelatedEntity); if (primaryEntity == null || relatedEntity == null || !primaryEntity.HasPublished()) { return("Invalid entity"); } if (RelationshipExists(oneToMany.Name)) { return("Name already exist."); } var relationship = CreateRelation(new RelationshipRecord { Name = oneToMany.Name, PrimaryEntity = primaryEntity.Record, RelatedEntity = relatedEntity.Record, Type = (byte)RelationshipType.OneToMany }); var updateModel = new ReferenceUpdateModel(new ReferenceFieldSettings { AlwaysInLayout = oneToMany.AlwaysInLayout, ContentTypeName = oneToMany.PrimaryEntity, DisplayAsLink = oneToMany.DisplayAsLink, HelpText = oneToMany.HelpText, IsAudit = oneToMany.IsAudit, Required = oneToMany.Required, RelationshipId = relationship.Id, RelationshipName = relationship.Name }); var fieldViewModel = new AddFieldViewModel { AddInLayout = true, Name = oneToMany.FieldName, DisplayName = oneToMany.FieldLabel, FieldTypeName = "ReferenceField" }; _contentMetadataService.CreateField(relatedEntity, fieldViewModel, updateModel); var fieldRecord = relatedEntity.FieldMetadataRecords.FirstOrDefault(field => field.Name == oneToMany.FieldName); var projectionPart = CreateProjection(oneToMany.RelatedEntity, oneToMany.ColumnFieldList); _oneToManyRepository.Create(new OneToManyRelationshipRecord { DeleteOption = (byte)oneToMany.DeleteOption, LookupField = fieldRecord, RelatedListProjection = projectionPart.Record, RelatedListLabel = oneToMany.RelatedListLabel, Relationship = relationship, ShowRelatedList = oneToMany.ShowRelatedList }); return(relationship.Id.ToString()); }
public ActionResult EditOneToMany(int relationId, OneToManyRelationshipModel oneToMany) { if (!Services.Authorizer.Authorize(Permissions.EditContent, T("Not allowed to edit a content."))) { return(new HttpUnauthorizedResult()); } var errorMessage = _relationshipService.EditRelationship(relationId, oneToMany); if (!string.IsNullOrWhiteSpace(errorMessage)) { ModelState.AddModelError("ManyToManyRelation", T(errorMessage).ToString()); return(ResponseError("")); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public string EditRelationship(int relationshipId, OneToManyRelationshipModel oneToMany) { var oneToManyRecord = _oneToManyRepository.Get(record => record.Relationship.Id == relationshipId); if (oneToManyRecord == null) { return("Invalid relashionship ID."); } oneToManyRecord.ShowRelatedList = oneToMany.ShowRelatedList; oneToManyRecord.RelatedListLabel = oneToMany.RelatedListLabel; _oneToManyRepository.Update(oneToManyRecord); UpdateLayoutProperties(oneToManyRecord.Relationship.RelatedEntity.Name, oneToManyRecord.RelatedListProjection.LayoutRecord, oneToMany.ColumnFieldList); return(null); }