public KhHeTong UpdateSingle(int id, KhHeTongReq data, out string error) { KhHeTong model = db.KhHeTong.Find(id); error = CheckKeTongSave(model, data); bool canUpdate = string.IsNullOrEmpty(error); if (!canUpdate) { return(model); } SetKhHeTong(model, data); db.SaveChanges(); return(model); }
/// <summary> /// 返回错误,为空正确 /// </summary> /// <param name="model"></param> /// <param name="data"></param> /// <returns></returns> public string CheckKeTongSave(KhHeTong model, KhHeTongReq data) { bool canUpdate = true; string error = ""; if (model.KhHTStateID == 1 && data.KhHTStateID == 2) { //从有效变到无效时,要做判断 List <DDShouKuan> skList = db.DDShouKuan.Where(d => d.HeTongID == model.id).ToList(); skList.ForEach(s => { if (s.SKState == "已付") { canUpdate = false; } }); if (!canUpdate) { error = "有已付订单,必须调整成取消才能变为无效"; } } return(error); }
/// <summary> /// 设置model,如果不为空就设置,如果为空则和之前一样 /// </summary> /// <param name="target"></param> /// <param name="source"></param> /// <returns></returns> public KhHeTong SetKhHeTong(KhHeTong model, KhHeTongReq data) { if (data.KhID != null)//添加订单来源 { var kehu = db.KeHu.FirstOrDefault(n => n.id == data.KhID); if (kehu != null) { var seskh = sesdb.Seskehu.FirstOrDefault(n => n.id == kehu.sesKHID); if (seskh != null && model.DDLaiYuanID == null) { model.DDLaiYuanID = seskh.KhLaiYuan; } } model.KhID = data.KhID.Value; } if (!string.IsNullOrEmpty(data.KhName)) { model.KhName = data.KhName; } if (!string.IsNullOrEmpty(data.KhPhone)) { model.KhPhone = data.KhPhone; } if (data.KhYuChanQi != null && data.KhYuChanQi != DateTime.MinValue && data.KhYuChanQi != SqlDateTime.MinValue.Value) { model.KhYuChanQi = data.KhYuChanQi.Value; } if (!string.IsNullOrEmpty(data.KhHTNumber)) { model.KhHTNumber = data.KhHTNumber; } if (!string.IsNullOrEmpty(data.KhHTSerialNumber)) { model.KhHTSerialNumber = data.KhHTSerialNumber; } if (!string.IsNullOrEmpty(data.KhHTName)) { model.KhHTName = data.KhHTName; } if (!string.IsNullOrEmpty(data.KhHTHouseStyle)) { model.KhHTHouseStyle = data.KhHTHouseStyle; } if (!string.IsNullOrEmpty(data.KhHTHouseNumber)) { model.KhHTHouseNumber = data.KhHTHouseNumber; } if (data.KhHTLiveDays != null) { model.KhHTLiveDays = data.KhHTLiveDays.Value; } if (data.KhHTDingJin != null) { model.KhHTDingJin = data.KhHTDingJin.Value; } if (data.KhHTWeiKuan != null) { model.KhHTWeiKuan = data.KhHTWeiKuan.Value; } if (data.KhHTTotalMoney != null) { model.KhHTTotalMoney = data.KhHTTotalMoney.Value; } if (data.KhHTZheKouMoney != null) { model.KhHTZheKouMoney = data.KhHTZheKouMoney.Value; } if (data.KhHTRuZhuDate != null && data.KhHTRuZhuDate != DateTime.MinValue && data.KhHTRuZhuDate != SqlDateTime.MinValue.Value) { model.KhHTRuZhuDate = data.KhHTRuZhuDate.Value; } if (data.KhHTChuSuoDate != null && data.KhHTChuSuoDate != DateTime.MinValue && data.KhHTChuSuoDate != SqlDateTime.MinValue.Value) { model.KhHTChuSuoDate = data.KhHTChuSuoDate.Value; } if (data.KhHTMuYingBaoXian != null) { model.KhHTMuYingBaoXian = data.KhHTMuYingBaoXian.Value; } if (!string.IsNullOrEmpty(data.KhHTXieYiShiXiang)) { model.KhHTXieYiShiXiang = data.KhHTXieYiShiXiang; } if (data.KhHTStateID != null) { model.KhHTStateID = data.KhHTStateID.Value; } if (!string.IsNullOrEmpty(data.KhHTSales)) { model.KhHTSales = data.KhHTSales; } if (data.projectid != null) { model.ProjectID = data.projectid.Value; } if (!string.IsNullOrEmpty(data.optName)) { model.optName = data.optName; } if (data.optDateTime != null && data.optDateTime != DateTime.MinValue && data.optDateTime != SqlDateTime.MinValue.Value) { model.optDateTime = data.optDateTime.Value; } if (data.KhRoomId != null) { model.KhRoomId = data.KhRoomId; } if (data.ChildCount != null) { model.ChildCount = data.ChildCount; } if (data.SignDateTime != null) { model.SignDateTime = data.SignDateTime; } if (data.KhHTSalesID != null) { model.KhHTSalesID = data.KhHTSalesID; } if (data.KhHTSalesSystemId != null) { model.KhHTSalesSystemId = data.KhHTSalesSystemId; } return(model); }