protected void CopyFields_Click(object sender, EventArgs e) { var otherMediaType = MediaTypeSelector.GetSelectedMediaType(); foreach (var otherMediaTypeField in otherMediaType.Fields) { if (!mediaType.Fields.Any(i => i.FieldCode == otherMediaTypeField.FieldCode)) { var mediaTypeField = new MediaTypeField(); mediaTypeField.CopyFrom(otherMediaTypeField); mediaTypeField.DateCreated = mediaTypeField.DateLastModified = DateTime.Now; mediaType.Fields.Add(mediaTypeField); foreach (var mediaDetail in mediaType.MediaDetails) { var mediaDetailField = new MediaDetailField(); mediaDetailField.CopyFrom(mediaTypeField); if (string.IsNullOrEmpty(mediaDetailField.UsageExample)) { mediaDetailField.UsageExample = "{Field:" + mediaDetailField.FieldCode + "} OR {{Load:" + mediaDetail.MediaID + "}.Field:" + mediaDetailField.FieldCode + "}"; } mediaDetailField.UseMediaTypeFieldFrontEndLayout = true; mediaDetailField.UseMediaTypeFieldDescription = true; if (mediaDetailField.FrontEndSubmissions == null) { mediaDetailField.FrontEndSubmissions = ""; } if (mediaDetailField.FieldSettings == null) { mediaDetailField.FieldSettings = ""; } mediaDetailField.MediaTypeField = mediaTypeField; mediaDetailField.DateCreated = mediaDetailField.DateLastModified = DateTime.Now; mediaDetailField.OrderIndex = mediaDetail.Fields.Count; mediaDetail.Fields.Add(mediaDetailField); } } } var returnObj = MediaTypesMapper.Update(mediaType); if (!returnObj.IsError) { Bind(); } else { BasePage.DisplayErrorMessage("Error", returnObj.Error); } }
private void ImportNewFields(IEnumerable <MediaTypeField> importFields) { foreach (var field in importFields) { if (!mediaType.Fields.Any(i => i.FieldCode == field.FieldCode)) { var mediaTypeField = new MediaTypeField(); mediaTypeField.CopyFrom(field); mediaTypeField.DateCreated = mediaTypeField.DateLastModified = DateTime.Now; mediaType.Fields.Add(mediaTypeField); foreach (var mediaDetail in mediaType.MediaDetails) { var mediaDetailField = new MediaDetailField(); mediaDetailField.CopyFrom(mediaTypeField); if (string.IsNullOrEmpty(mediaDetailField.UsageExample)) { mediaDetailField.UsageExample = "{Field:" + mediaDetailField.FieldCode + "} OR {{Load:" + mediaDetail.MediaID + "}.Field:" + mediaDetailField.FieldCode + "}"; } mediaDetailField.UseMediaTypeFieldFrontEndLayout = true; mediaDetailField.UseMediaTypeFieldDescription = true; if (mediaDetailField.FrontEndSubmissions == null) { mediaDetailField.FrontEndSubmissions = ""; } if (mediaDetailField.FieldSettings == null) { mediaDetailField.FieldSettings = ""; } mediaDetailField.MediaTypeField = mediaTypeField; mediaDetailField.DateCreated = mediaDetailField.DateLastModified = DateTime.Now; mediaDetailField.OrderIndex = mediaDetail.Fields.Count; mediaDetail.Fields.Add(mediaDetailField); } } } var returnObj = MediaTypesMapper.Update(mediaType); if (!returnObj.IsError) { Bind(); } else { BasePage.DisplayErrorMessage("Error", returnObj.Error); } }
protected void Save_OnClick(object sender, EventArgs e) { if (selectedItem == null) { selectedItem = MediaTypesMapper.CreateObject(); } else { selectedItem = BaseMapper.GetObjectFromContext <MediaType>(selectedItem); } UpdateObjectFromFields(); Return returnObj = selectedItem.Validate(); if (!returnObj.IsError) { if (selectedItem.ID == 0) { returnObj = MediaTypesMapper.Insert(selectedItem); } else { returnObj = MediaTypesMapper.Update(selectedItem); } } if (returnObj.IsError) { DisplayErrorMessage("Error Saving Item", returnObj.Error); } else { /*var mediaDetails = selectedItem.MediaDetails.Where(i => i.HistoryForMediaDetail == null); * * foreach (var mediaDetail in mediaDetails) * { * mediaDetail.RemoveFromCache(); * }*/ DisplaySuccessMessage("Successfully Saved Item"); } }
protected void Delete_Click(object sender, EventArgs e) { var field = GetDataItemFromSender((Control)sender); if (field != null && field.ID != 0) { //TODO: Only un-comment for testing var mediaDetailFields = field.MediaDetailFields.ToList(); foreach (var mediaDetailField in mediaDetailFields) { var fieldAssociations = mediaDetailField.FieldAssociations.ToList(); foreach (var item in fieldAssociations) { if (!item.MediaDetail.MediaType.ShowInSiteTree) { var media = item.MediaDetail.Media; MediaDetailsMapper.ClearObjectRelations(item.MediaDetail); BaseMapper.DeleteObjectFromContext(item.MediaDetail); } } BaseMapper.DeleteObjectFromContext(mediaDetailField); } // End of TODO BaseMapper.DeleteObjectFromContext(field); var returnObj = MediaTypesMapper.Update(mediaType); if (!returnObj.IsError) { UpdatedFieldsFromObject(new MediaTypeField()); Bind(); } else { BasePage.DisplayErrorMessage("Error", returnObj.Error); } } }
protected void Update_Click(object sender, EventArgs e) { if (mediaType.ID == 0) { BasePage.DisplayErrorMessage("You can only add fields once you have created the page"); return; } if (FieldCode.Text == "") { BasePage.DisplayErrorMessage("'FieldCode' cannot be blank"); return; } var fieldId = long.Parse(FieldID.Value); if (fieldId == 0) { var mediaTypeField = new MediaTypeField(); UpdatedObjectFromFields(mediaTypeField); mediaType.Fields.Add(mediaTypeField); foreach (var mediaDetail in mediaType.MediaDetails) { var mediaDetailField = new MediaDetailField(); mediaDetailField.CopyFrom(mediaTypeField); if (string.IsNullOrEmpty(mediaDetailField.UsageExample)) { mediaDetailField.UsageExample = "{Field:" + mediaDetailField.FieldCode + "} OR {{Load:" + mediaDetail.MediaID + "}.Field:" + mediaDetailField.FieldCode + "}"; } mediaDetailField.UseMediaTypeFieldFrontEndLayout = true; mediaDetailField.UseMediaTypeFieldDescription = true; if (mediaDetailField.FrontEndSubmissions == null) { mediaDetailField.FrontEndSubmissions = ""; } if (mediaDetailField.FieldSettings == null) { mediaDetailField.FieldSettings = ""; } mediaDetailField.MediaTypeField = mediaTypeField; mediaDetailField.DateCreated = mediaDetailField.DateLastModified = DateTime.Now; mediaDetailField.OrderIndex = mediaDetail.Fields.Count; mediaDetail.Fields.Add(mediaDetailField); } } else { var mediaTypeField = mediaType.Fields.SingleOrDefault(i => i.ID == fieldId); var oldFieldCode = mediaTypeField.FieldCode; UpdatedObjectFromFields(mediaTypeField); foreach (var mediaDetailField in mediaTypeField.MediaDetailFields) { var mediaDetailFieldValue = mediaDetailField.FieldValue; mediaDetailField.CopyFrom(mediaTypeField); if (string.IsNullOrEmpty(mediaDetailField.UsageExample)) { mediaDetailField.UsageExample = "{Field:" + mediaDetailField.FieldCode + "} OR {{Load:" + mediaDetailField.MediaDetail.MediaID + "}.Field:" + mediaDetailField.FieldCode + "}"; } if (mediaDetailField.UseMediaTypeFieldDescription) { mediaDetailField.FieldDescription = mediaTypeField.FieldDescription; } if (mediaDetailField.UseMediaTypeFieldFrontEndLayout) { mediaDetailField.FrontEndLayout = mediaTypeField.FrontEndLayout; } if (string.IsNullOrEmpty(mediaDetailFieldValue)) { mediaDetailField.FieldValue = mediaTypeField.FieldValue; } else { mediaDetailField.FieldValue = mediaDetailFieldValue; } mediaDetailField.DateLastModified = DateTime.Now; } } var returnObj = MediaTypesMapper.Update(mediaType); if (!returnObj.IsError) { Bind(); /*var liveMediaDetails = mediaType.MediaDetails.Where(i => i.HistoryVersionNumber == 0); * * foreach (var item in liveMediaDetails) * { * item.RemoveFromCache(); * }*/ } else { BasePage.DisplayErrorMessage("Error", returnObj.Error); } }