示例#1
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Treaty _model     = db.Treaties.Find(id);
            var    _viewModel = TreatyViewModel.GetViewModelDatas(_model);

            if (_model == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ContractorID = new SelectList(db.Contractors, "ContractorID", "Company", _model.ContractorID);
            return(View(_viewModel));
        }
示例#2
0
        // GET: Treaties
        public ActionResult Index(string searchString, int?page)
        {
            #region Default Code
            //var treaties = db.Treaties.Include(t => t.Contractor);
            //return View(treaties.ToList());

            #endregion End of Default Code

            #region List
            //var _model = db.Treaties.Include(d => d.Contractor);
            //var _viewModel = new List<TreatyViewModel>();

            //foreach (var item in _model)
            //{
            //    _viewModel.Add(TreatyViewModel.GetViewModelDatas(item));
            //}

            //return View(_viewModel);
            #endregion // end of List

            #region LINQ Expression
            //var qData = from q in db.Devices.Include(d => d.DeviceDocument) select q;

            var qData = (from q in db.Treaties.Include(d => d.Contractor) select q).OrderBy(s => s.TreatyNumber).Skip(0);
            if (!string.IsNullOrEmpty(searchString))
            {
                qData = qData.Where(s => s.TreatyNumber.Contains(searchString));
            }

            int pageSize   = 8;
            int pageNumber = (page ?? 1);

            var _viewModel = new List <TreatyViewModel>();
            foreach (var item in qData)
            {
                _viewModel.Add(TreatyViewModel.GetViewModelDatas(item));
            }

            return(View("Index", _viewModel.ToPagedList(pageNumber, pageSize)));

            //return View(_listViewModel.ToPagedList(pageNumber, pageSize));

            #endregion // end of LINQ Expression
        }