/// <summary>
 /// Delete obj from database
 /// </summary>
 /// <param name="deal"></param>
 public static void DeleteDealFromDb(Deal deal)
 {
     using (var db = new DB_Context())
     {
         db.Deals.Remove(db.Deals.Find(deal.DealID));
         db.ObjectOfTransactions.Find(deal.ObjectOfTransactionID).ObjectStateID = 1;
         db.SaveChanges();
     }
 }
        /// <summary>
        /// Add new objects to database
        /// </summary>
        /// <param name="deal"></param>
        public static void AddDealToDb(Deal deal)
        {
            try
            {
                using (var db = new DB_Context())
                {
                    db.Deals.Add(deal);
                    db.ObjectOfTransactions.Find(deal.ObjectOfTransactionID).ObjectStateID = 2;
                    db.SaveChanges();
                }
            }
            catch (Exception EX)
            {

            }
        }
        public static ViewDeal ConvertDeal(Deal deal)
        {
            return new ViewDeal
            {
                DealID = deal.DealID,
                ObjectOfTransactionID = deal.ObjectOfTransactionID,
                Seller_UserID = deal.Seller_UserID,
                Buyer_UserID = deal.Buyer_UserID,

                PersonalNumberOfDeal = deal.PersonalNumberOfDeal,
                SellerInfo = DataManager.GetuUserFromDbById(deal.Seller_UserID).ToString(),
                BuyerInfo = DataManager.GetuUserFromDbById(deal.Buyer_UserID).ToString(),
                ObjectOfTransactionInfo = DataManager.GetObjectOfTransactionFromDbById(deal.ObjectOfTransactionID).ToString(),

                KindOfCalculatingID = (EnumKindOfCalculating)deal.KindOfCalculatingID,
                DateOfDeal = deal.DateOfDeal,
                TransactionAmount = deal.TransactionAmount
            };
        }
        /// <summary>
        /// Update objects from database
        /// </summary>
        /// <param name="deal"></param>
        public static void UpdateDealFromDb(Deal deal)
        {
            using (var db = new DB_Context())
            {
                var d = db.Deals.Find(deal.DealID);

                d.Buyer_UserID = deal.Buyer_UserID;
                d.Seller_UserID = deal.Seller_UserID;
                d.DateOfDeal = deal.DateOfDeal;
                d.PersonalNumberOfDeal = deal.PersonalNumberOfDeal;
                d.TransactionAmount = deal.TransactionAmount;
                d.KindOfCalculatingID = deal.KindOfCalculatingID;
                d.ObjectOfTransactionID = deal.ObjectOfTransactionID;

                db.ObjectOfTransactions.Find(deal.ObjectOfTransactionID).ObjectStateID = 2;
                db.SaveChanges();

            }
        }