public UnitTest1() { ImagePropertyGuids = new List <String>(); imageFileExtensions = new List <string>() { "JPG", "JPEG", "TIF", "PNG", "GIF", "BMP" }; ImageGuids = Task.Run(() => ValuesController.GetRandomImageGuids(imageFileExtensions, 500)).Result.Value; idCatalogItemFirstImage = Db.idCatalogItem .Include(x => x.idFilePath) .Where(x => x.FileName.EndsWith(".JPG")) .OrderBy(x => x.DateTimeStamp) .First(); idCatalogItemFirstVideo = Db.idCatalogItem .Include(x => x.idFilePath) .Where(x => x.FileName.EndsWith(".MP4")) .OrderBy(x => x.DateTimeStamp) .First(); idPropFirst = Db.idProp.First(); List <ImageProperty> ImageProperties = Task.Run(() => ValuesController.GetImageProperties(null)).Result.Value; foreach (ImageProperty imageProperty in ImageProperties) { ImagePropertyGuids.Add(imageProperty.GUID); } }
private List <ImagePropertyRecursive> GetImagePropertyRecursive(IQueryable <idProp> query) { List <ImagePropertyRecursive> listImagePropertyRecursive = new List <ImagePropertyRecursive>(); foreach (idProp row in query) { String parentGuid = row.ParentGUID; List <String> parentProperties = new List <string>(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, readUncommittedTransactionOptions)) { while (parentGuid != null) { idProp parentProperty = db.idProp.SingleOrDefault(x => x.GUID == parentGuid); if (parentProperty == null) { idPropCategory parentPropCategory = db.idPropCategory.SingleOrDefault(x => x.GUID == parentGuid); if (parentPropCategory != null) { parentProperties.Insert(0, parentPropCategory.CategoryName); } parentGuid = null; } else { parentProperties.Insert(0, parentProperty.PropName); parentGuid = parentProperty.ParentGUID; } } scope.Complete(); } ImagePropertyRecursive imagePropertyRecursive = new ImagePropertyRecursive(); imagePropertyRecursive.GUID = row.GUID; imagePropertyRecursive.Name = row.PropName; imagePropertyRecursive.FullRecursivePath = String.Join("::", parentProperties); listImagePropertyRecursive.Add(imagePropertyRecursive); } return(listImagePropertyRecursive); }
public string AddImageProperty(string propertyName, string parentGUID) { try { idProp parentIdProp = db.idProp.SingleOrDefault(x => x.GUID.Equals(parentGUID)); int? parentRgt; if (parentIdProp == null) { parentRgt = db.idProp.Where(x => x.ParentGUID.Equals(parentGUID)).Max(x => x.rgt); } else { parentRgt = parentIdProp.rgt; } idUser user = db.idUser.First(); DateTime dtNow = DateTime.Now; String guid = Guid.NewGuid().ToString(); while (db.idProp.Where(x => x.GUID == guid).Count() > 0) { guid = Guid.NewGuid().ToString(); } //Update nested set rgt var queryUpdateNestedSetRgt = from tbl in db.idProp where tbl.rgt >= parentRgt select tbl; foreach (idProp row in queryUpdateNestedSetRgt) { row.rgt = row.rgt + 2; } //Update nested set lft var queryUpdateNestedSetLft = from tbl in db.idProp where tbl.lft > parentRgt select tbl; foreach (idProp row in queryUpdateNestedSetLft) { row.lft = row.lft + 2; } idProp newIdProp = new idProp(); newIdProp.GUID = guid; newIdProp.ParentGUID = parentGUID; newIdProp.PropName = propertyName; newIdProp.PropValue = ""; newIdProp.Quick = 0; newIdProp.UserGUID = user.GUID; newIdProp.idCreated = dtNow; newIdProp.idLastAccess = dtNow; newIdProp.PropXMPLink = ""; newIdProp.lft = parentRgt; newIdProp.rgt = parentRgt + 1; newIdProp.idImage = null; newIdProp.ParentAssign = 0; newIdProp.ParentXMPLinkAssign = 0; newIdProp.idSynonyms = ""; newIdProp.idGPSLon = 90; newIdProp.idGPSLat = 90; newIdProp.idGPSAlt = 0; newIdProp.idGPSGeoTag = 0; newIdProp.idGPSGeoTagIfExist = 0; newIdProp.idGPSRadius = 0; newIdProp.idShortCut = 0; newIdProp.MutualExclusive = 0; newIdProp.idDescription = ""; newIdProp.idDetails = null; newIdProp.idProps = null; newIdProp.ApplyProps = 0; db.idProp.Add(newIdProp); db.SaveChanges(); log.Info(String.Format("Client {0}:{1} called AddImageProperty with propertyName: {2}, parentGUID {3}, lft {4}, rgt {5}", clientEndpoint.Address, clientEndpoint.Port, propertyName, parentGUID, newIdProp.lft, newIdProp.rgt)); return("OK"); } catch (Exception ex) { log.Error(ex.ToString()); throw ex; } }