/// <summary> /// 编辑 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Edit(int id = 0) { Order_ContractProduct model = null; int contractId = RequestInt("contractId"); if (contractId == 0) { return(LayerAlertErrorAndClose("请选择一个合同!")); } var contract = Bll.BllOrder_Contract.First(o => o.Id == contractId); if (contract == null) { return(LayerAlertErrorAndClose("合同不存在!")); } if (id == 0) { model = new Order_ContractProduct(); } else { model = Bll.BllOrder_ContractProduct.First(o => o.Id == id); if (model == null) { return(LayerAlertErrorAndClose("记录不存在!")); } } ViewBag.contract = contract; return(View(model)); }
public ActionResult Save(Order_ContractProduct model) { int contractId = RequestInt("contractId"); int quantity = RequestInt("quantity"); decimal price = RequestDecimal("price"); string name = RequestString("name"); if (contractId == 0) { return(LayerAlertErrorAndReturn("请选择一个合同!")); } var contract = Bll.BllOrder_Contract.First(o => o.Id == contractId); if (contract == null) { return(LayerAlertErrorAndClose("合同不存在!")); } if (string.IsNullOrEmpty(name)) { return(LayerAlertErrorAndClose("请输入产品名称!")); } if (model.Id > 0) { model = Bll.BllOrder_ContractProduct.First(o => o.Id == model.Id); if (model == null) { return(Response404()); } } else { model = new Order_ContractProduct(); } model.ContractId = contractId; model.Name = name; model.Price = price; model.Quantity = quantity; model.TotalPrice = quantity * price; model.AddTime = DateTime.Now; model.AdminId = MyInfo.Id; if ((model.Id > 0 ? Bll.BllOrder_ContractProduct.Update(model) : Bll.BllOrder_ContractProduct.Insert(model)) > 0) { return(LayerAlertSuccessAndRefresh((model.Id > 0 ? "修改" : "添加") + "成功")); } else { return(LayerAlertErrorAndReturn((model.Id > 0 ? "修改" : "添加") + "失败")); } }