コード例 #1
0
        public ActionResult UpdateAgreements(int?supplierId)
        {
            if (null == supplierId)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            try
            {
                SupplierWithAgreements supplier = _supplierManager.RetrieveSupplierWithAgreementsBySupplierId((int)supplierId);
                if (null == supplier)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                if (null != supplier.Agreements)
                {
                    supplier.Agreements.RemoveAll(a => a.IsApproved == false);
                }


                SupplierUpdateAgreementViewModel model = new SupplierUpdateAgreementViewModel()
                {
                    SupplierId         = (int)supplierId,
                    ApprovedAgreements = supplier.Agreements,
                    ProductsToSelect   = _productManager.RetrieveProducts()
                };

                if (model.ApprovedAgreements != null)
                {
                    foreach (AgreementWithProductName a in model.ApprovedAgreements)
                    {
                        model.ProductsToSelect.RemoveAll(p => p.ProductId == a.ProductId);
                    }
                }

                return(View("UpdateAgreements", model));
            }
            catch (Exception)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable));
            }
        }