public async Task <List <EventInfo> > EventSearch(long?EventID, long?EventTypeID, long?AccountID, long?LocationID, DateTime? @DateFrom, DateTime? @DateTo, string Title, string Caption) { List <EventInfo> ls = new List <EventInfo>(10); using (SqlCommand cmd = new SqlCommand("[dbo].[sp_Event_Search]", new SqlConnection(Ctx.Config.dbUniHangoutsRead)) { CommandType = CommandType.StoredProcedure }) { cmd.AddParam(ParameterDirection.Input, SqlDbType.BigInt, nameof(EventID), EventID); cmd.AddParam(ParameterDirection.Input, SqlDbType.BigInt, nameof(EventTypeID), EventTypeID); cmd.AddParam(ParameterDirection.Input, SqlDbType.BigInt, nameof(AccountID), AccountID); cmd.AddParam(ParameterDirection.Input, SqlDbType.BigInt, nameof(LocationID), LocationID); cmd.AddParam(ParameterDirection.Input, SqlDbType.SmallDateTime, nameof(@DateFrom), @DateFrom); cmd.AddParam(ParameterDirection.Input, SqlDbType.SmallDateTime, nameof(@DateTo), @DateTo); cmd.AddParam(ParameterDirection.Input, SqlDbType.VarChar, nameof(Title), Title); cmd.AddParam(ParameterDirection.Input, SqlDbType.NVarChar, nameof(Caption), Caption); if (cmd.Connection.State != ConnectionState.Open) { await cmd.Connection.OpenAsync().ConfigureAwait(false); } using (SqlDataReader reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false)) { while (await reader.ReadAsync().ConfigureAwait(false)) { DBEventFeedItem item = new DBEventFeedItem(reader); EventInfo info = new EventInfo(Ctx, item); ls.Add(info); } } } return(ls); }
public DBEventFeedItem CreateEvent(long EventTypeID, DateTime DateStart, DateTime DateEnd, long AccountID, long LocationID, string Title, string Caption, string Details) { using (SqlCommand cmd = new SqlCommand("[dbo].[sp_Event_Create]", new SqlConnection(Ctx.Config.dbUniHangoutsWrite)) { CommandType = CommandType.StoredProcedure }) { SqlParameter paramEventID = cmd.AddParam(ParameterDirection.Output, SqlDbType.BigInt, nameof(DBEventFeedItem.EventID), null); cmd.AddParam(ParameterDirection.Input, SqlDbType.BigInt, nameof(EventTypeID), EventTypeID); cmd.AddParam(ParameterDirection.Input, SqlDbType.SmallDateTime, nameof(DateStart), DateStart); cmd.AddParam(ParameterDirection.Input, SqlDbType.SmallDateTime, nameof(DateEnd), DateEnd); cmd.AddParam(ParameterDirection.Input, SqlDbType.BigInt, nameof(AccountID), AccountID); cmd.AddParam(ParameterDirection.Input, SqlDbType.BigInt, nameof(LocationID), LocationID); cmd.AddParam(ParameterDirection.Input, SqlDbType.VarChar, nameof(Title), Title); cmd.AddParam(ParameterDirection.Input, SqlDbType.NVarChar, nameof(Caption), Caption); cmd.AddParam(ParameterDirection.Input, SqlDbType.NVarChar, nameof(Details), Details); int rowsAffected = cmd.ExecuteProcedure(); DBEventFeedItem result = new DBEventFeedItem() { EventID = (Int64)paramEventID.Value, EventTypeID = EventTypeID, DateStart = DateStart, DateEnd = DateEnd, AccountID = AccountID, LocationID = LocationID, Title = Title, Caption = Caption }; if (result.EventID > 0) { return(result); } } return(null); }
public EventInfo(Factory Ctx, DBEventFeedItem item) { AccountID = item.AccountID; EventID = item.EventID; EventTypeID = item.EventTypeID; DateStart = item.DateStart; DateEnd = item.DateEnd; LocationID = item.LocationID; Title = item.Title; Caption = item.Caption; RSVP_Attending = item.RSVP_Attending; RSVP_Later = item.RSVP_Later; RSVP_StopBy = item.RSVP_StopBy; RSVP_Maybe = item.RSVP_Maybe; RSVP_No = item.RSVP_No; Host = String.IsNullOrWhiteSpace(item.UserDisplayName) ? item.UserName : item.UserDisplayName; LocationName = item.LocationName; AddressLine = Helpers.FormatAddress(null, item.AddressLine, item.Locality, item.AdminDistrict, item.PostalCode, item.CountryRegion, ", "); EventType = Ctx.EventTypeManager[item.EventTypeID]; Tags = item.TagIds?.Select(x => Ctx.TagManager[x]).Where(x => x != null).ToArray(); }
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)); } }