public void AddRoles(List <Role> roles) { var mediaTypesRoles = MediaTypesRoles.ToList(); foreach (var mediaTypesRole in mediaTypesRoles) { var mediaTypeRole = BaseMapper.GetDataModel().MediaTypeRoles.FirstOrDefault(i => i.ID == mediaTypesRole.ID); if (mediaTypeRole != null) { BaseMapper.GetDataModel().MediaTypeRoles.Remove(mediaTypeRole); } } var savedChanges = BaseMapper.GetDataModel().SaveChanges(); foreach (var role in roles) { var contextRole = BaseMapper.GetObjectFromContext(role); MediaTypesRoles.Add(new MediaTypeRole() { Role = contextRole, DateCreated = DateTime.Now, DateLastModified = DateTime.Now }); } }
public static Return ClearAllCache() { try { ContextHelper.ClearAllMemoryCache(); FileCacheHelper.ClearAllCache(); RedisCacheHelper.ClearAllCache(); var webserviceRequests = FrameworkLibrary.WebserviceRequestsMapper.GetAll(); foreach (var item in webserviceRequests) { var context = BaseMapper.GetObjectFromContext(item); if (context != null) { BaseMapper.DeleteObjectFromContext(context); } } var returnObj = BaseMapper.SaveDataModel(); return(BaseMapper.GenerateReturn()); } catch (Exception ex) { return(BaseMapper.GenerateReturn(ex)); } }
public void AddChildMediaTypes(IEnumerable <MediaType> items) { MediaTypes.Clear(); foreach (MediaType item in items.Where(item => MediaTypes.Where(i => i.ID == item.ID).Count() == 0)) { MediaTypes.Add(BaseMapper.GetObjectFromContext(item)); } }
private static void UpdateProperty <T>(PropertyInfo toProperty, object value, T toObject, T fromObject) { if (toProperty.GetSetMethod() == null) { return; } if (value != null) { var propertyName = toProperty.Name.ToString(); if (propertyName == "EntityKey") { return; } if (propertyName == "ID") { return; } if (value.GetType().BaseType == typeof(EntityReference)) { return; } if (value.GetType().Name.Contains("EntityCollection")) { return; } if (value.GetType().Name.Contains("HashSet")) { return; } if (value.GetType().Name.Contains("EntityReference")) { return; } if (value.GetType().BaseType.ToString().Contains("FrameworkLibrary")) { return; } if (value.GetType().BaseType == typeof(EntityObject)) { value = BaseMapper.GetObjectFromContext((IMustContainID)value); } } toProperty.SetValue(toObject, value, null); }
public Return MoveToIndex(int insertAtIndex) { var returnObj = BaseMapper.GenerateReturn(); if (insertAtIndex < 0) { var ex = new System.Exception("Cant move to index: " + insertAtIndex); returnObj.Error = ErrorHelper.CreateError(ex); return(returnObj); } var siblings = GetSiblings(); var currentIndex = GetIndex(siblings); if (currentIndex >= 0 && currentIndex <= siblings.Count) { siblings.RemoveAt(currentIndex); } if (siblings.Count < insertAtIndex) { var ex = new System.Exception("Cant move to index: " + insertAtIndex); returnObj.Error = ErrorHelper.CreateError(ex); return(returnObj); } siblings.Insert(insertAtIndex, this); var index = 0; foreach (var media in siblings) { if (media.OrderIndex == index) { index++; continue; } var inContext = BaseMapper.GetObjectFromContext(media); media.OrderIndex = index; returnObj = MediasMapper.Update(media); index++; } MediasMapper.ClearCache(); MediaDetailsMapper.ClearCache(); return(returnObj); }
public void ReorderChildren() { var index = 0; var childMedias = ChildMedias.Where(i => i.MediaDetails.Any() && i.MediaDetails.ElementAt(0).MediaType.ShowInSiteTree).OrderBy(i => i.OrderIndex).ToList(); foreach (var mediaItem in childMedias) { var context = BaseMapper.GetObjectFromContext(mediaItem); if (context == null) { continue; } if (context.OrderIndex != index) { context.OrderIndex = index; MediasMapper.Update(context); } index++; } }
public string MakeWebRequest(string urlString, ICredentials credentialCache = null, RequestMethod method = RequestMethod.GET, string queryString = "") { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var storageItem = WebserviceRequestsMapper.GetByUrl(urlString); var data = ""; if ((storageItem != null) && (EnableCaching) && !storageItem.Response.Contains("unavailable") && storageItem.DateLastModified.AddSeconds(CacheDurationInSeconds) > DateTime.Now) { return(storageItem.Response); } WebserviceRequest request = null; if (storageItem == null) { request = new WebserviceRequest(); } else { request = storageItem; } request.Url = urlString; request.QueryString = queryString; request.Response = ""; request.Method = method.ToString(); request.UrlReferrer = ""; if (System.Web.HttpContext.Current.Request.UrlReferrer != null) { request.UrlReferrer = System.Web.HttpContext.Current.Request.UrlReferrer.AbsoluteUri; } WebRequest webRequest = WebRequest.Create(urlString); if (credentialCache != null) { webRequest.Credentials = credentialCache; webRequest.PreAuthenticate = true; } webRequest.Method = method.ToString(); try { if (method == RequestMethod.POST) { var encoding = new ASCIIEncoding(); byte[] bytes = encoding.GetBytes(queryString); webRequest.ContentLength = bytes.Length; webRequest.ContentType = "application/x-www-form-urlencoded"; using (var webRequestStream = webRequest.GetRequestStream()) { webRequestStream.Write(bytes, 0, bytes.Length); webRequestStream.Flush(); webRequestStream.Close(); } } using (WebResponse webResponse = webRequest.GetResponse()) { Stream dataStream = webResponse.GetResponseStream(); using (StreamReader streamReader = new StreamReader(dataStream)) { data = streamReader.ReadToEnd(); } } } catch (WebException ex) { ErrorHelper.LogException(ex); data = ex.Message; if (ex.Response != null) { // can use ex.Response.Status, .StatusDescription if (ex.Response.ContentLength != 0) { using (var stream = ex.Response.GetResponseStream()) { using (var reader = new StreamReader(stream)) { data = reader.ReadToEnd(); } } } } } if (request != null) { request.Response = data; var ommit = false; foreach (var item in OmmitList) { if (request.Url.ToLower().Contains(item)) { ommit = true; break; } } if (EnableCaching) { if (request.ID == 0) { WebserviceRequestsMapper.Insert(request); } else { request = BaseMapper.GetObjectFromContext(request); WebserviceRequestsMapper.Update(request); } } } return(data); }
public Return PublishLive() { var returnObj = new Return(); var liveVersion = BaseMapper.GetObjectFromContext((MediaDetail)this.Media.GetLiveMediaDetail()); var selectedItem = BaseMapper.GetObjectFromContext((MediaDetail)this); selectedItem.HistoryVersionNumber = 0; selectedItem.HistoryForMediaDetail = null; selectedItem.IsDraft = false; selectedItem.PublishDate = DateTime.Now; //selectedItem.ShowInMenu = true; IEnumerable <MediaDetail> items = new List <MediaDetail>(); if (liveVersion != null) { items = liveVersion.History.ToList(); foreach (var item in items) { if (item.ID != selectedItem.ID) { var tmpItem = BaseMapper.GetObjectFromContext(item); item.HistoryForMediaDetailID = selectedItem.ID; } } } foreach (var fieldAssociation in selectedItem.FieldAssociations) { var index = 1; foreach (var history in fieldAssociation.MediaDetail.History) { history.HistoryForMediaDetail = fieldAssociation.MediaDetail; history.HistoryVersionNumber = 1; index++; } fieldAssociation.MediaDetail.HistoryForMediaDetail = null; fieldAssociation.MediaDetail.HistoryVersionNumber = 0; } foreach (var field in selectedItem.Fields) { foreach (var fieldAssociation in field.FieldAssociations) { var index = 1; foreach (var mediaDetail in fieldAssociation.MediaDetail.Media.MediaDetails) { mediaDetail.HistoryForMediaDetail = fieldAssociation.MediaDetail; mediaDetail.HistoryVersionNumber = 1; index++; } fieldAssociation.MediaDetail.HistoryForMediaDetail = null; fieldAssociation.MediaDetail.HistoryVersionNumber = 0; } if (liveVersion != null) { field.FrontEndSubmissions = liveVersion.LoadField(field.FieldCode)?.FrontEndSubmissions; } } foreach (var mediaTypeField in selectedItem.MediaType.Fields) { if (!selectedItem.Fields.Any(i => i.FieldCode == mediaTypeField.FieldCode)) { var mediaDetailField = new MediaDetailField(); mediaDetailField.CopyFrom(mediaTypeField); mediaDetailField.UseMediaTypeFieldFrontEndLayout = true; mediaDetailField.UseMediaTypeFieldDescription = true; mediaDetailField.MediaTypeField = mediaTypeField; mediaDetailField.DateCreated = mediaDetailField.DateLastModified = DateTime.Now; mediaDetailField.OrderIndex = selectedItem.Fields.Count; selectedItem.Fields.Add(mediaDetailField); } } if (liveVersion != null) { if (items.Any()) { liveVersion.HistoryVersionNumber = items.OrderByDescending(i => i.HistoryVersionNumber).FirstOrDefault().HistoryVersionNumber + 1; } else { liveVersion.HistoryVersionNumber = 1; } liveVersion.HistoryForMediaDetail = (MediaDetail)selectedItem; var associations = BaseMapper.GetDataModel().FieldAssociations.Where(i => i.AssociatedMediaDetailID == liveVersion.ID); foreach (var association in associations) { association.MediaDetail = (MediaDetail)selectedItem; } } returnObj = MediaDetailsMapper.Update(selectedItem); if (!returnObj.IsError) { if (liveVersion != null) { liveVersion.HistoryForMediaDetailID = selectedItem.ID; returnObj = MediaDetailsMapper.Update(liveVersion); } if (!returnObj.IsError) { ContextHelper.Clear(ContextType.Cache); FileCacheHelper.ClearAllCache(); return(returnObj); } else { return(returnObj); } } else { return(returnObj); } }