public ActionResult DistributionContract() { ViewDistributionContract model = new ViewDistributionContract(); using (var db = new EFContext()) { var shopdistribution = db.selshopdistribution.FirstOrDefault(x => x.ShopID == ShopId); if (shopdistribution != null) { model.IsSignAgreement = shopdistribution.IsSignAgreement; if (model.IsSignAgreement) { model.SignAgreementTimeFormat = shopdistribution.SignAgreementTime.Value.ToString(FormatHelper.DataTimeFormat); } } var shop = db.selshop.FirstOrDefault(x => x.ID == ShopId); if (shop != null) { model.LinkMan = shop.LinkMan; model.Phone = shop.Phone; } model.ShopName = ShopName; } return(View(model)); }
public ActionResult SaveDistributionContract(ViewDistributionContract model) { ViewBase b = new ViewBase(); try { if (model.IsSignAgreement == false) { b.Code = 0; b.Message = ConstantHelper.Failure; return(Json(b, JsonRequestBehavior.AllowGet)); } using (var db = new EFContext()) { var shopdistribution = db.selshopdistribution.FirstOrDefault(x => x.ShopID == ShopId); if (shopdistribution == null) { shopdistribution = new selshopdistribution() { ShopID = ShopId, IsSignAgreement = true, SignAgreementTime = DateTime.Now, IsOpen = false, IsSetPercentage = false, OperatorDateTime = DateTime.Now, Percentage = 0, SetPercentageTime = DateTime.Now }; db.selshopdistribution.Add(shopdistribution); } else { shopdistribution.IsSignAgreement = true; shopdistribution.SignAgreementTime = DateTime.Now; } db.SaveChanges(); b.Code = 1; b.Message = "协议签署成功"; b.Url = "/DistributionBank/DistributionContract"; } } catch (Exception Exc) { b.Code = 0; b.Message = ConstantHelper.Failure; b.Description = Exc.ToString(); } return(Json(b, JsonRequestBehavior.AllowGet)); }