コード例 #1
0
        static void publishProducts()
        {
            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare(exchange: "exchange-card-read", type: ExchangeType.Fanout);

                    byte[]          body;
                    BinaryFormatter bf = new BinaryFormatter();
                    using (MemoryStream ms = new MemoryStream())
                    {
                        using (var db = new CardsContext())
                        {
                            List <AssemblyCard> cards = db.Cards.ToList();
                            bf.Serialize(ms, cards);
                            body = ms.ToArray();
                        }
                    }

                    channel.BasicPublish(exchange: "exchange-card-read",
                                         routingKey: "",
                                         basicProperties: null,
                                         body: body);
                    Console.WriteLine("Publish products");
                }
        }
コード例 #2
0
 static void insertProduct(AssemblyCard card)
 {
     using (var db = new CardsContext())
     {
         db.Add(card);
         db.SaveChanges();
     }
 }
コード例 #3
0
 static void deleteProduct(string id)
 {
     using (var db = new CardsContext())
     {
         AssemblyCard card = db.Cards.SingleOrDefault(r => r.CardId == id);
         if (card == null)
         {
             return;
         }
         db.Cards.Remove(card);
         db.SaveChanges();
     }
 }
コード例 #4
0
 static void updateProduct(AssemblyCard card)
 {
     using (var db = new CardsContext())
     {
         AssemblyCard savedCard = db.Cards.SingleOrDefault(r => r.CardId == card.CardId);
         if (savedCard == null)
         {
             return;
         }
         savedCard.EmployeeFN = card.EmployeeFN;
         savedCard.EmployeeLN = card.EmployeeLN;
         savedCard.EmployeeID = card.EmployeeID;
         savedCard.KNNR       = card.KNNR;
         savedCard.Sort       = card.Sort;
         db.SaveChanges();
     }
 }