public virtual TopicStore UpdateTopicStore(TopicStore entity)
        {
            if (entity.IsTransient())
            {
                return(entity);
            }
            TopicStore other = GetTopicStore(entity.TopicId);

            if (entity.Equals(other))
            {
                return(entity);
            }
            string sql = @"Update TopicStore set  [ID]=@ID
							, [StoreID]=@StoreID
							, [CreatedOn]=@CreatedOn 
							 where TopicID=@TopicID"                            ;

            SqlParameter[] parameterArray = new SqlParameter[] {
                new SqlParameter("@TopicID", entity.TopicId)
                , new SqlParameter("@ID", entity.Id)
                , new SqlParameter("@StoreID", entity.StoreId)
                , new SqlParameter("@CreatedOn", entity.CreatedOn)
            };
            SqlHelper.ExecuteNonQuery(this.ConnectionString, CommandType.Text, sql, parameterArray);
            return(GetTopicStore(entity.TopicId));
        }
        public virtual TopicStore InsertTopicStore(TopicStore entity)
        {
            TopicStore other = new TopicStore();

            other = entity;
            if (entity.IsTransient())
            {
                string         sql            = @"Insert into TopicStore ( [TopicID]
				,[ID]
				,[StoreID]
				,[CreatedOn] )
				Values
				( @TopicID
				, @ID
				, @StoreID
				, @CreatedOn );
				Select scope_identity()"                ;
                SqlParameter[] parameterArray = new SqlParameter[] {
                    new SqlParameter("@TopicID", entity.TopicId)
                    , new SqlParameter("@ID", entity.Id)
                    , new SqlParameter("@StoreID", entity.StoreId)
                    , new SqlParameter("@CreatedOn", entity.CreatedOn)
                };
                var identity = SqlHelper.ExecuteScalar(this.ConnectionString, CommandType.Text, sql, parameterArray);
                if (identity == DBNull.Value)
                {
                    throw new DataException("Identity column was null as a result of the insert operation.");
                }
                return(GetTopicStore(Convert.ToInt32(identity)));
            }
            return(entity);
        }
        public virtual TopicStore TopicStoreFromDataRow(DataRow dr)
        {
            if (dr == null)
            {
                return(null);
            }
            TopicStore entity = new TopicStore();

            entity.Id        = (System.Int32)dr["ID"];
            entity.TopicId   = (System.Int32)dr["TopicID"];
            entity.StoreId   = (System.Int32)dr["StoreID"];
            entity.CreatedOn = (System.DateTime)dr["CreatedOn"];
            return(entity);
        }
 public virtual TopicStore DeleteTopicStore(TopicStore entity)
 {
     this.DeleteTopicStore(entity.TopicId);
     return(entity);
 }
Exemple #5
0
        static async Task Main(string[] args)
        {
            var topicStore = new TopicStore();

            var host = Host.CreateDefaultBuilder(args)
                       .ConfigureServices(services =>
            {
                services.AddSingleton(topicStore);
            })
                       .ConfigureWebHostDefaults(b =>
            {
                b.UseKestrel(o =>
                {
                    o.ListenAnyIP(8000, builder => builder.UseConnectionHandler <PubSubServer>());
                    o.ListenAnyIP(5000);
                });

                b.Configure(app =>
                {
                    app.UseRouting();

                    app.UseEndpoints(e =>
                    {
                        e.MapGet("/topics", async context =>
                        {
                            var response = from t in topicStore
                                           select new
                            {
                                Name        = t.Key,
                                Subscribers = t.Value.SubscriberCount,
                                Messages    = t.Value.PublishCount
                            };

                            context.Response.ContentType = "application/json";
                            await JsonSerializer.SerializeAsync(context.Response.Body, response);
                        });

                        e.MapGet("/topics/{name}", async context =>
                        {
                            var name = (string)context.Request.RouteValues["name"];
                            context.Response.ContentType = "application/json";

                            if (!topicStore.TryGetValue(name, out var t))
                            {
                                context.Response.StatusCode = 404;
                                await JsonSerializer.SerializeAsync(context.Response.Body, new
                                {
                                    Message = "No such topic found"
                                });
                                return;
                            }

                            await JsonSerializer.SerializeAsync(context.Response.Body, new
                            {
                                Name        = name,
                                Subscribers = t.SubscriberCount,
                                Messages    = t.PublishCount
                            });
                        });
                    });
                });
            })
                       .Build();

            await host.RunAsync();
        }
 public TopicStore InsertTopicStore(TopicStore entity)
 {
     return(_iTopicStoreRepository.InsertTopicStore(entity));
 }
 public TopicStore UpdateTopicStore(TopicStore entity)
 {
     return(_iTopicStoreRepository.UpdateTopicStore(entity));
 }