public DBTag this[string name] { get { if (String.IsNullOrWhiteSpace(name)) { return(null); } name = name.ToAlphaNumericLower(); Helpers.BlockUntilFinished(ref _initTask); if (_byName.TryGetValue(name, out var cached)) { return(cached.Item); } DateTime lastMiss = _nameMisses.GetValueOrDefault(name); if (lastMiss < DateTime.Now.AddSeconds(-MissExpireSecs)) { using (var cmd = DBTag.GetSqlCommandForSP_GetOne(Ctx, null, name)) { CachedEntry tag = AddTag(cmd.ExecuteReader_GetOne <DBTag>()); if (tag != null) { return(tag.Item); } } _nameMisses[name] = DateTime.Now; } return(null); } }
public Tag SaveTag(Tag tag, out bool result) { if (tag.Guid == Guid.Empty) { tag.Guid = Guid.NewGuid(); result = DBTag.Create( tag.Guid, tag.SiteGuid, tag.FeatureGuid, tag.ModuleGuid, tag.TagText, tag.CreatedUtc, tag.CreatedBy, tag.VocabularyGuid ); } else { result = DBTag.Update( tag.Guid, tag.TagText, tag.ModifiedUtc, tag.ModifiedBy, tag.VocabularyGuid ); } return(tag); }
public Tag GetTagByGuid(Guid tagGuid) { using (IDataReader reader = DBTag.GetOneTag(tagGuid)) { return(getTagFromIDataReader(reader)); } }
public DBTag this[long id] { get { if (id <= 0) { return(null); } Helpers.BlockUntilFinished(ref _initTask); if (_byId.TryGetValue(id, out var cached)) { return(cached.Item); } DateTime lastMiss = _idMisses.GetValueOrDefault(id); if (lastMiss < DateTime.Now.AddSeconds(-MissExpireSecs)) { using (var cmd = DBTag.GetSqlCommandForSP_GetOne(Ctx, id)) { CachedEntry tag = AddTag(cmd.ExecuteReader_GetOne <DBTag>()); if (tag != null) { return(tag.Item); } } _idMisses[id] = DateTime.Now; } return(null); } }
public void AddTags(params Tag[] tags) { foreach (var tag in tags) { if (!TagExists(tag.Name)) { DBTag dbTag = _mapper.Map <DBTag>(tag); _db.Tags.Add(dbTag); } } _db.SaveChanges(); }
private CachedEntry AddTag(DBTag dbtag) { if (dbtag != null) { var tag = new CachedEntry(dbtag); _byId[tag.Item.TagID] = tag; _byName[tag.NormName] = tag; QueryAutoComplete.Add(tag.Item.Name, tag); QueryAutoComplete.Add(tag.Item.Description, tag); return(tag); } return(null); }
private int Update() { if (DBTag.Update( this.tagID, this.siteGuid, this.featureGuid, this.tag, this.itemCount, this.guid, this.createdUtc, this.createdBy)) { return(this.tagID); } return(0); }
/// <summary> /// Gets an instance of Tag. /// </summary> /// <param name="tagID"> tagID </param> private void GetTag(int tagId, int languageId) { using (IDataReader reader = DBTag.GetOne(tagId, languageId)) { if (reader.Read()) { this.tagID = Convert.ToInt32(reader["TagID"]); this.siteGuid = new Guid(reader["SiteGuid"].ToString()); this.featureGuid = new Guid(reader["FeatureGuid"].ToString()); this.tag = reader["Tag"].ToString(); this.itemCount = Convert.ToInt32(reader["ItemCount"]); this.guid = new Guid(reader["Guid"].ToString()); this.createdUtc = Convert.ToDateTime(reader["CreatedUtc"]); this.createdBy = new Guid(reader["CreatedBy"].ToString()); } } }
private int Create() { int newID = 0; this.guid = Guid.NewGuid(); newID = DBTag.Create( this.siteGuid, this.featureGuid, this.tag, this.itemCount, this.guid, this.createdUtc, this.createdBy); this.tagID = newID; return(newID); }
private async Task Init() { using (var cmd = DBTag.GetSqlCommandForSP_Search(this.Ctx)) { if (cmd.Connection.State != ConnectionState.Open) { await cmd.Connection.OpenAsync().ConfigureAwait(false); } using (var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false)) { while (await reader.ReadAsync().ConfigureAwait(false)) { var tag = new CachedEntry(new DBTag(reader)); _byId[tag.Item.TagID] = tag; _byName[tag.NormName] = tag; QueryAutoComplete.Add(tag.Item.Name, tag); QueryAutoComplete.Add(tag.Item.Description, tag); } } } QueryAutoComplete.Optimize(); }
public void AddRelation(int fileId, int tagId) { DBFile dbFile = _db.Files.FirstOrDefault(f => f.Id == fileId); if (dbFile == null) { return; } DBTag dbTag = _db.Tags.FirstOrDefault(t => t.Id == tagId); if (dbTag == null) { return; } if (dbFile.Tags.Contains(dbTag)) { return; } dbFile.Tags.Add(dbTag); _db.SaveChanges(); }
public bool DeleteTagByGuid(Guid guid) { return(DBTag.Delete(guid)); }
public static List <Tag> GetTagCloud(Guid siteGuid, Guid?featureGuid, int languageId, int top) { IDataReader reader = DBTag.GetTagCloud(siteGuid, featureGuid, languageId, top); return(LoadListFromReader(reader)); }
public static List <Tag> GetPage(Guid siteGuid, Guid?featureGuid, string keyword, int languageId, int pageNumber, int pageSize) { IDataReader reader = DBTag.GetPage(siteGuid, featureGuid, keyword, languageId, pageNumber, pageSize); return(LoadListFromReader(reader)); }
public static int GetCount(Guid siteGuid, Guid?featureGuid, string keyword, int languageId = -1) { return(DBTag.GetCount(siteGuid, featureGuid, keyword, languageId)); }
public List <Tag> GetTagsByModuleGuid(Guid moduleGuid) { return(getTagListFromIDataReader(DBTag.GetByModule(moduleGuid))); }
public ApiResult <EventInfo> EventCreate(EventInput input) { var apiresult = new ApiResult <EventInfo>(); if (UserContext == null) { return(apiresult.Failure("Must be logged in.")); } if (!UserContext.IsVerifiedLogin) { return(apiresult.Failure("Insufficient account permissions.")); } if (input == null) { return(apiresult.Failure("Bad Post. Input is null.")); } if (input.Location == null) { return(apiresult.Failure("Location Invalid")); } //TODO sanitize Title, Caption, and Description to be free of javascript if (input.Title.CountAlphaNumeric() <= 5) { return(apiresult.Failure("Title to short.")); } if (input.Caption.CountAlphaNumeric() <= 8) { return(apiresult.Failure("Caption to short.")); } if (input.DateStart.ToUniversalTime() < DateTime.UtcNow) { return(apiresult.Failure("DateStart in the past.")); } if (input.DateEnd.ToUniversalTime() < input.DateStart.ToUniversalTime()) { return(apiresult.Failure("DateEnd is before DateStart")); } if (input.DateStart.AddDays(14).ToUniversalTime() < input.DateEnd.ToUniversalTime()) { return(apiresult.Failure("Events cannot last longer than 2 weeks.")); } DBEventType eventType = Factory.EventTypeManager[input.EventTypeID]; if (eventType == null) { return(apiresult.Failure("EventType does not exist.")); } if (input.Tags == null || input.Tags.Length == 0) { return(apiresult.Failure("Include at least one EventTag.")); } DBTag[] eventTags = new DBTag[input.Tags.Length]; for (int i = 0; i < input.Tags.Length; i++) { DBTag tag = Factory.TagManager[input.Tags[i]]; if (tag == null) { return(apiresult.Failure("Invalid Tag: " + input.Tags[i].ToString())); } eventTags[i] = tag; } LocationNode.CountryRegionNode oCountry = Factory.LocationManager.QueryCachedCountries(input.Location.CountryRegion).FirstOrDefault(); if (oCountry == null) { return(apiresult.Failure("Invalid Country")); } LocationNode.AdminDistrictNode oState = Factory.LocationManager.QueryCachedStates(input.Location.AdminDistrict).FirstOrDefault(); if (oState == null) { return(apiresult.Failure("Invalid State")); } if (input.Location.PostalCode.CountAlphaNumeric() < 3) { return(apiresult.Failure("Invalid PostalCode")); } if (oCountry.Abbreviation == "USA") { LocationNode.PostalCodeNode oZip = Factory.LocationManager.QueryCachedPostalCodes(input.Location.PostalCode).FirstOrDefault(); if (oZip == null) { return(apiresult.Failure("Invalid PostalCode")); } } if (input.Location.Locality.CountAlphaNumeric() < 3) { return(apiresult.Failure("Invalid City")); } try { StreetAddress address = new StreetAddress(Factory.LocationManager.GetOrCreateDBLocation(input.Location)); DBEventFeedItem dbEventItem = Factory.EventManager.CreateEvent(eventType.EventTypeID, input.DateStart, input.DateEnd, UserContext.AccountID, address.LocationID.UnBox(), input.Title, input.Caption, input.Description); EventInfo info = new EventInfo() { EventID = dbEventItem.EventID, DateStart = dbEventItem.DateStart, DateEnd = dbEventItem.DateEnd, Title = dbEventItem.Title, Caption = dbEventItem.Title, EventTypeID = dbEventItem.EventTypeID, EventType = eventType, LocationID = dbEventItem.LocationID, LocationName = address.Name, AddressLine = Helpers.FormatAddress(null, address.AddressLine, address.Locality, address.AdminDistrict, address.PostalCode, address.CountryRegion), AccountID = dbEventItem.AccountID, Host = String.IsNullOrWhiteSpace(UserContext.UserDisplayName) ? UserContext.UserName : UserContext.UserDisplayName, Tags = eventTags, Details = input.Description }; for (int i = 0; i < eventTags.Length; i++) { DBTag tag = eventTags[i]; #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Factory.TagManager.LinkTagToEvent(info.EventID, tag.TagID); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } return(apiresult.Success(info)); } catch (Exception ex) { return(apiresult.Failure(ex)); } }
public bool DeleteTagByFeatureGuid(Guid featureGuid) { return(DBTag.DeleteByFeature(featureGuid)); }
public List <Tag> GetTagsByVocabulary(Guid vocabularyGuid) { return(getTagListFromIDataReader(DBTag.GetByVocabulary(vocabularyGuid))); }
public List <Tag> GetTagsBySite(int siteId) { return(getTagListFromIDataReader(DBTag.GetBySite(siteId))); }
public List <Tag> GetTagsByFeatureGuid(Guid featureGuid) { return(getTagListFromIDataReader(DBTag.GetByFeature(featureGuid))); }
public DBTag Create(string name, string description) { return(AddTag(DBTag.SP_Create(Ctx, name, description))?.Item); }
public CachedEntry(DBTag tag) { Item = tag; NormName = tag.Name.ToAlphaNumericLower(); }
public bool DeleteTagByModuleGuid(Guid moduleGuid) { return(DBTag.DeleteByModule(moduleGuid)); }
public static bool DeleteBySite(Guid siteGuid) { return(DBTag.DeleteBySite(siteGuid)); }
public bool DeleteTagBySiteGuid(Guid siteGuid) { return(DBTag.DeleteBySite(siteGuid)); }
public ApiResult <EventInfo> EventUpdate(long EventID, EventInput input) { //TODO: Verify Event belongs to user if updating. Right now anyone can update any event. var apiresult = new ApiResult <EventInfo>(); if (UserContext == null) { return(apiresult.Failure("Must be logged in.")); } if (!UserContext.IsVerifiedLogin) { return(apiresult.Failure("Insufficient account permissions.")); } if (EventID <= 0) { return(apiresult.Failure("Invalid ID")); } DBEventFeedItemExtended existing = null; try { existing = Factory.EventManager.EventGetByID(EventID); if (existing == null) { return(apiresult.Failure("Event Does not exist.")); } } catch (Exception ex) { return(apiresult.Failure(ex)); } if (input == null) { return(apiresult.Failure("Input is null.")); } if (input.Title != null && existing.Title != input.Title) { existing.Title = input.Title; } if (input.Caption != null && existing.Caption != input.Caption) { existing.Caption = input.Caption; } if (input.Description != null && existing.Details != input.Description) { existing.Details = input.Description; } if (input.EventTypeID > 0 && existing.EventTypeID != input.EventTypeID) { existing.EventTypeID = input.EventTypeID; } if (input.DateStart != default && existing.DateStart != input.DateStart) { existing.DateStart = input.DateStart; } if (input.DateEnd != default && existing.DateEnd != input.DateEnd) { existing.DateEnd = input.DateEnd; } //TODO sanitize Title, Caption, and Description to be free of javascript if (existing.Title.CountAlphaNumeric() <= 5) { return(apiresult.Failure("Title to short.")); } if (existing.Caption.CountAlphaNumeric() <= 8) { return(apiresult.Failure("Caption to short.")); } if (existing.DateStart.ToUniversalTime() < DateTime.UtcNow) { apiresult.Failure("DateStart in the past."); if (UserContext.IsAdmin) { apiresult.AppendMessage("(AdminOverride)"); } else { return(apiresult); } } if (existing.DateEnd.ToUniversalTime() < input.DateStart.ToUniversalTime()) { return(apiresult.Failure("DateEnd is before DateStart")); } if (existing.DateStart.AddDays(14).ToUniversalTime() < input.DateEnd.ToUniversalTime()) { return(apiresult.Failure("Events cannot last longer than 2 weeks.")); } DBEventType eventType = Factory.EventTypeManager[existing.EventTypeID]; if (eventType == null) { return(apiresult.Failure("EventType does not exist.")); } List <DBTag> newTags = null; List <DBTag> removedTags = null; DBTag[] eventTags = null; if (input.Tags != null && input.Tags.Length > 0) { DBTag[] previousTags = existing.TagIds.Select(x => Factory.TagManager[x]).ToArray(); existing.TagIds = new long[input.Tags.Length]; eventTags = new DBTag[input.Tags.Length]; newTags = new List <DBTag>(); removedTags = new List <DBTag>(); for (int i = 0; i < input.Tags.Length; i++) { DBTag tag = eventTags[i] = Factory.TagManager[input.Tags[i]]; if (tag == null) { return(apiresult.Failure("Invalid Tag: " + input.Tags[i].ToString())); } existing.TagIds[i] = tag.TagID; if (Array.IndexOf(previousTags, tag) == -1) { newTags.Add(tag); } } for (int i = 0; i < previousTags.Length; i++) { DBTag tag = previousTags[i]; if (Array.IndexOf(eventTags, tag) == -1) { removedTags.Add(tag); } } } else { eventTags = new DBTag[existing.TagIds.Length]; for (int i = 0; i < existing.TagIds.Length; i++) { DBTag tag = Factory.TagManager[existing.TagIds[i]]; if (tag == null) { return(apiresult.Failure("Invalid Tag: " + input.Tags[i].ToString())); } eventTags[i] = tag; } } bool bLocChange = false; if (input.Location != null) { var loc = input.Location; if (loc.Name != null && existing.LocationName != loc.Name) { existing.LocationName = loc.Name; bLocChange = true; } if (loc.AddressLine != null && existing.AddressLine != loc.AddressLine) { existing.AddressLine = loc.AddressLine; bLocChange = true; } if (loc.Locality != null && existing.Locality != loc.Name) { existing.Locality = loc.Locality; bLocChange = true; } if (loc.PostalCode != null && existing.PostalCode != loc.PostalCode) { existing.PostalCode = loc.PostalCode; bLocChange = true; } if (loc.AdminDistrict != null && existing.AdminDistrict != loc.Name) { existing.AdminDistrict = loc.AdminDistrict; bLocChange = true; } if (loc.CountryRegion != null && existing.CountryRegion != loc.CountryRegion) { existing.CountryRegion = loc.CountryRegion; bLocChange = true; } if (bLocChange) { LocationNode.CountryRegionNode oCountry = Factory.LocationManager.QueryCachedCountries(existing.CountryRegion).FirstOrDefault(); if (oCountry == null) { return(apiresult.Failure("Invalid Country")); } LocationNode.AdminDistrictNode oState = Factory.LocationManager.QueryCachedStates(existing.AdminDistrict).FirstOrDefault(); if (oState == null) { return(apiresult.Failure("Invalid State")); } if (existing.PostalCode.CountAlphaNumeric() < 3) { return(apiresult.Failure("Invalid PostalCode")); } if (oCountry.Abbreviation == "USA") { LocationNode.PostalCodeNode oZip = Factory.LocationManager.QueryCachedPostalCodes(existing.PostalCode).FirstOrDefault(); if (oZip == null) { return(apiresult.Failure("Invalid PostalCode")); } } if (existing.Locality.CountAlphaNumeric() < 3) { return(apiresult.Failure("Invalid City")); } } } StreetAddress address = new StreetAddress() { ParentLocationID = existing.ParentLocationID, LocationID = existing.LocationID, Name = existing.LocationName, AddressLine = existing.AddressLine, Locality = existing.Locality, AdminDistrict = existing.AdminDistrict, PostalCode = existing.PostalCode, CountryRegion = existing.CountryRegion }; if (bLocChange) { try { address = new StreetAddress(Factory.LocationManager.GetOrCreateDBLocation(address)); } catch (Exception ex) { return(apiresult.Failure(ex)); } } try { Factory.EventManager.UpdateEvent(EventID, existing.EventTypeID, existing.DateStart, existing.DateEnd, UserContext.AccountID, existing.LocationID, existing.Title, existing.Caption, existing.Details); EventInfo info = new EventInfo() { EventID = existing.EventID, DateStart = existing.DateStart, DateEnd = existing.DateEnd, Title = existing.Title, Caption = existing.Title, EventTypeID = existing.EventTypeID, EventType = eventType, LocationID = existing.LocationID, LocationName = address.Name, AddressLine = Helpers.FormatAddress(null, address.AddressLine, address.Locality, address.AdminDistrict, address.PostalCode, address.CountryRegion), AccountID = existing.AccountID, Host = String.IsNullOrWhiteSpace(UserContext.UserDisplayName) ? UserContext.UserName : UserContext.UserDisplayName, Tags = eventTags, Details = existing.Details }; #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed if (newTags != null) { for (int i = 0; i < newTags.Count; i++) { Factory.TagManager.LinkTagToEvent(info.EventID, newTags[i].TagID); } } if (removedTags != null) { for (int i = 0; i < removedTags.Count; i++) { Factory.TagManager.RemoveTagFromEvent(info.EventID, removedTags[i].TagID); } } #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return(apiresult.Success(info)); } catch (Exception ex) { return(apiresult.Failure(ex)); } }
public static bool UpdateItemCount(int tagId) { return(DBTag.UpdateItemCount(tagId)); }
public ViewModel_Tag(DBTag tag) { Data = tag; }
public static bool Delete(int tagId) { return(DBTag.Delete(tagId)); }