public void ReOrderMediaFields(List <FrameworkLibrary.MediaDetailField> items) { UserMustBeInRole(RoleEnum.Developer); var index = 0; foreach (var item in items) { var mediaField = BaseMapper.GetDataModel().Fields.SingleOrDefault(i => i.ID == item.ID); if (mediaField != null) { mediaField.OrderIndex = index; index++; } if (mediaField is MediaTypeField) { var mediaTypeField = mediaField as MediaTypeField; foreach (var mediaDetailField in mediaTypeField.MediaDetailFields) { mediaDetailField.OrderIndex = mediaTypeField.OrderIndex; } } } var returnObj = BaseMapper.SaveDataModel(); var json = returnObj.ToJson(); WriteJSON(json); }
public override void SetValue(object value) { var field = GetField(); var hasDeleted = false; var hasReordered = false; if (ItemsToDelete.Text != "" && ItemsToDelete.Text != "[]") { var deleteIds = StringHelper.JsonToObject <List <long> >(ItemsToDelete.Text); foreach (var id in deleteIds) { var fieldAssociation = field.FieldAssociations.SingleOrDefault(i => i.ID == id); if (fieldAssociation != null) { var returnObj = MediaDetailsMapper.DeletePermanently(fieldAssociation.MediaDetail); if (!returnObj.IsError) { BaseMapper.DeleteObjectFromContext(fieldAssociation); } hasDeleted = true; } } } if (ReorderItems.Text != "" && ReorderItems.Text != "[]") { var reorderedIds = StringHelper.JsonToObject <List <long> >(ReorderItems.Text); var index = 0; foreach (var id in reorderedIds) { if (id == null) { return; } var fieldAssociation = field.FieldAssociations.SingleOrDefault(i => i.ID == id); if (fieldAssociation != null) { fieldAssociation.OrderIndex = index; hasReordered = true; index++; } } } if (hasDeleted || hasReordered) { var returnObj = BaseMapper.SaveDataModel(); } BindValues(); }
//public ViewMode Mode { get; set; } protected void AddItem_Click(object sender, EventArgs e) { var field = GetField(); var media = MediasMapper.GetByID(field.MediaDetail.MediaID); var fieldAssociation = new FieldAssociation(); fieldAssociation.MediaDetail = (MediaDetail)PagesMapper.CreateObject(MediaTypeID, MediasMapper.CreateObject(), media); fieldAssociation.MediaDetail.SectionTitle = fieldAssociation.MediaDetail.ShortDescription = fieldAssociation.MediaDetail.MainContent = fieldAssociation.MediaDetail.LinkTitle; fieldAssociation.MediaDetail.PathToFile = "/media/images/icons/File.jpg"; fieldAssociation.MediaDetail.PublishDate = DateTime.Now; fieldAssociation.MediaDetail.CreatedByUserID = fieldAssociation.MediaDetail.LastUpdatedByUserID = FrameworkSettings.CurrentUser.ID; fieldAssociation.MediaDetail.CachedVirtualPath = fieldAssociation.MediaDetail.CalculatedVirtualPath(); fieldAssociation.MediaDetail.LanguageID = AdminBasePage.CurrentLanguage.ID; fieldAssociation.MediaDetail.UseDefaultLanguageLayouts = false; var mediaType = MediaTypesMapper.GetByID(fieldAssociation.MediaDetail.MediaTypeID); if (mediaType != null) { fieldAssociation.MediaDetail.UseMediaTypeLayouts = mediaType.UseMediaTypeLayouts; } field.FieldAssociations.Add(fieldAssociation); var returnObj = BaseMapper.SaveDataModel(); BindValues(); }
protected void UploadFilesNow_Click(object sender, EventArgs e) { try { var field = GetField(); if (IsPostBack && Request.Files.Count > 0 && !hasRun) { hasRun = true; var index = 0; for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (string.IsNullOrEmpty(file.FileName)) { continue; } var fileInfo = (new System.IO.FileInfo(GetFolderPath() + file.FileName)); if (!fileInfo.Directory.Exists) { fileInfo.Directory.Create(); } if (fileInfo.Directory.Exists) { file.SaveAs(fileInfo.FullName); var filePath = URIHelper.ConvertAbsUrlToTilda(URIHelper.ConvertAbsPathToAbsUrl(fileInfo.FullName)).Replace("~", ""); if (!field.FieldAssociations.Any(j => j.MediaDetail.PathToFile == filePath)) { var fieldAssociation = new FieldAssociation(); fieldAssociation.MediaDetail = (MediaDetail)PagesMapper.CreateObject(MediaTypeID, MediasMapper.CreateObject(), AdminBasePage.SelectedMedia); fieldAssociation.MediaDetail.LinkTitle = fieldAssociation.MediaDetail.SectionTitle = fieldAssociation.MediaDetail.ShortDescription = fieldAssociation.MediaDetail.MainContent = fileInfo.Name; fieldAssociation.MediaDetail.PathToFile = filePath; fieldAssociation.MediaDetail.PublishDate = DateTime.Now; fieldAssociation.MediaDetail.CreatedByUser = fieldAssociation.MediaDetail.LastUpdatedByUser = FrameworkSettings.CurrentUser; fieldAssociation.MediaDetail.CachedVirtualPath = fieldAssociation.MediaDetail.CalculatedVirtualPath(); fieldAssociation.MediaDetail.LanguageID = SettingsMapper.GetSettings().DefaultLanguage.ID; field.FieldAssociations.Add(fieldAssociation); index++; var returnObj = BaseMapper.SaveDataModel(); } } } } SetValue(GetValue()); } catch (Exception ex) { } }