// GET: TradingProgress/Edit/5
        public ActionResult Edit(int id)
        {
            TradingProgressRepository repository     = new TradingProgressRepository();
            ParticipantRepository     participantRep = new ParticipantRepository();
            DealRepository            dealRep        = new DealRepository();

            TradingProgressModel model = repository.GetById(id);

            model.Buyers = participantRep.GetAll();
            model.Deals  = dealRep.GetAll();

            return(View(model));
        }
        // GET: TradingProgress/Create
        public ActionResult Create()
        {
            ParticipantRepository participantRep = new ParticipantRepository();
            DealRepository        dealRep        = new DealRepository();

            TradingProgressModel model = new TradingProgressModel
            {
                Buyers = participantRep.GetAll(),
                Deals  = dealRep.GetAll()
            };

            return(View(model));
        }
        public ActionResult Edit(int id, TradingProgressModel ModelObject)
        {
            try
            {
                TradingProgressRepository repository = new TradingProgressRepository();
                repository.Update(ModelObject);

                return(RedirectToAction("GetAll"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult GetItemInfo(int dealId, int byuerId, int stepRate)
        {
            DateTime now = DateTime.Now;
            TradingProgressRepository tradingProgressRepository = new TradingProgressRepository();
            TradingProgressModel      tradingProgress           = new TradingProgressModel
            {
                Deal_Id  = dealId,
                Buyer_Id = byuerId,
                StepTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0),
                StepRate = stepRate
            };

            tradingProgressRepository.Add(tradingProgress);

            return(Json(new { }, JsonRequestBehavior.DenyGet));
        }
        public ActionResult Create(TradingProgressModel ModelObject)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    TradingProgressRepository repository = new TradingProgressRepository();
                    repository.Add(ModelObject);
                    return(RedirectToAction("GetAll"));
                }

                return(View());
            }
            catch
            {
                return(View());
            }
        }
        public TradingProgressModel GetById(int id)
        {
            using (SqlConnection db = SQLConnector.Connect())
            {
                db.Open();

                TradingProgressModel ModelObject = new TradingProgressModel();

                SqlCommand com = new SqlCommand("GetTradingProgressById", db);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@Id", id);
                com.ExecuteNonQuery();
                SqlDataAdapter da = new SqlDataAdapter(com);
                DataTable      dt = new DataTable();
                da.Fill(dt);

                return(FillTable(dt)[0]);
            }
        }
        public bool Add(TradingProgressModel obj)
        {
            using (SqlConnection db = SQLConnector.Connect())
            {
                db.Open();

                SqlCommand com = new SqlCommand("AddTradingProgress", db);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@Deal_Id", obj.Deal_Id);
                com.Parameters.AddWithValue("@Byer_Id", obj.Buyer_Id);
                com.Parameters.AddWithValue("@StepTime", obj.StepTime);
                com.Parameters.AddWithValue("@StepRate", obj.StepRate);

                if (com.ExecuteNonQuery() == -1)
                {
                    return(false);
                }
                return(true);
            }
        }