public static void SendPushToSuppliers(Int64 BidId, Int64 ServiceId, Int64 CityId, Geometry.Point Location) { List <Int64> HomeServiceId = Service.FetchAllHomeServices(); Query qry = new Query(AppSupplier.TableSchema); qry.AddWhere(AppSupplier.Columns.Status, false); qry.Join(JoinType.InnerJoin, AppSupplier.TableSchema, AppSupplier.Columns.SupplierId, AppSupplier.TableSchema.SchemaName, SupplierService.TableSchema, SupplierService.Columns.SupplierId, SupplierService.TableSchema.SchemaName); qry.Where(SupplierService.TableSchema.SchemaName, SupplierService.Columns.ServiceId, WhereComparision.EqualsTo, ServiceId); qry.Select(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.SupplierId, AppSupplier.Columns.SupplierId, true); qry.Distinct(); if (HomeServiceId.Contains(ServiceId)) { Query CityInnerQuery = new Query(SupplierHomeServiceCity.TableSchema); CityInnerQuery.Where(SupplierHomeServiceCity.Columns.CityId, WhereComparision.EqualsTo, CityId); CityInnerQuery.Select(SupplierHomeServiceCity.Columns.SupplierId).Distinct(); qry.AddWhere(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.SupplierId, WhereComparision.In, CityInnerQuery); } //get all appusers that are in the radius of Location else { if (Location != null) { Query q = new Query(AppSupplier.TableSchema); q.SelectAllTableColumns(); q.AddSelectLiteral( "( 6371 * acos ( cos ( radians(" + Location.X + ") ) * cos( radians( X(" + AppSupplier.Columns.AddressLocation + ") ) ) " + "* cos( radians( Y(" + AppSupplier.Columns.AddressLocation + ") ) - radians(" + Location.Y + ") ) " + "+ sin ( radians(" + Location.X + ") ) * sin( radians( X(" + AppSupplier.Columns.AddressLocation + ") ) ) )) AS distance"); List <Int64> appSupplierIds = new List <Int64>(); using (DataReaderBase reader = q.ExecuteReader()) { while (reader.Read()) { decimal distance = reader["distance"] != null?Convert.ToDecimal(reader["distance"]) : 0; if (distance > Settings.GetSettingInt32(Settings.Keys.SUPPLIER_RADIUS, 10)) { continue; } appSupplierIds.Add(Convert.ToInt64(reader[AppSupplier.Columns.SupplierId])); } } qry.AddWhere(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.SupplierId, WhereComparision.In, appSupplierIds); } } try { SupplierNotification.SendNotificationNewServiceBidToSupplier(BidId, qry.ExecuteScalarList <Int64>()); } catch (Exception) { } }
internal static void SendMessages(List <BidMessage> messages, DateTime now) { foreach (var msg in messages) { switch (msg.Stage) { case START_STAGE: WaitingEmails.Enqueue(msg); SupplierNotification.SendNotificationNewBidToSupplier(msg.BidId, new List <Int64> { msg.SupplierId }); msg.ExpirationTime = now.AddMinutes(Settings.GetSettingInt64(Settings.Keys.MESSAGE_EXPIRATION_SUPPLIER, 60)); msg.Stage = SUPPLIER_STAGE; msg.Save(); break; case PREMIUM_STAGE: case SUPPLIER_STAGE: long supplierId = get_primium_supplier(msg); if (supplierId == 0) { goto case SPECIAL_DEAL_STAGE; } SupplierNotification.SendNotificationNewBidToPremiumSupplier(msg.BidId, supplierId); var newPremMessage = new BidMessage(msg); newPremMessage.Stage = PREMIUM_STAGE; newPremMessage.SupplierId = supplierId; newPremMessage.ExpirationTime = now.AddMinutes(Settings.GetSettingInt64(Settings.Keys.MESSAGE_EXPIRATION_PREMIUM, 20)); newPremMessage.Save(); WaitingEmails.Enqueue(newPremMessage); goto default; case SPECIAL_DEAL_STAGE: var supplierList = get_relevant_suppliers(msg); if (supplierList.Count <= 0) { var bid = Bid.FetchByID(msg.BidId); if (!bid.IsActive) { goto default; } goto case ADMIN_STAGE; } foreach (int sId in supplierList) { var newSpecMessage = new BidMessage(msg); newSpecMessage.SupplierId = sId; newSpecMessage.ExpirationTime = now.AddMinutes(Settings.GetSettingInt64(Settings.Keys.MESSAGE_EXPIRATION_SPECIAL_DEAL, 10)); newSpecMessage.Stage = SPECIAL_DEAL_STAGE; newSpecMessage.IsActive = false; newSpecMessage.Save(); SupplierNotification.SendNotificationNewBidToPremiumSupplier(msg.BidId, sId); WaitingEmails.Enqueue(newSpecMessage); } var forAdminMessage = new BidMessage(msg); forAdminMessage.ExpirationTime = now.AddMinutes(Settings.GetSettingInt64(Settings.Keys.MESSAGE_EXPIRATION_SPECIAL_DEAL, 10)); forAdminMessage.Stage = SPECIAL_DEAL_STAGE; forAdminMessage.IsActive = true; forAdminMessage.SupplierId = 1; forAdminMessage.Save(); goto default; case ADMIN_STAGE: var expiredDid = Bid.FetchByID(msg.BidId); expiredDid.IsActive = false; expiredDid.Save(); msg.Stage = ADMIN_STAGE; send_message_to_admin(msg); goto default; default: msg.IsActive = false; msg.Save(); break; } } }