/// <summary> /// 编辑收货地址 /// </summary> /// <param name="req"></param> /// <returns></returns> public Respbase EditAddress(EditAddressReq req) { try { var addr = db.TnetNodeconsigneeaddrSet.Where(c => c.Consigneeid == req.ConsigneeId).FirstOrDefault(); if (addr == null) { log.Info("获取收货地址失败,请检查consigneeId是否正确"); return(Fail("获取收货地址失败")); } db.BeginTransaction(); if (req.ProvinceId != 0) { addr.Provinceid = req.ProvinceId; } if (req.CityId != 0) { addr.Cityid = req.CityId; } if (req.RegionId != 0) { addr.Regionid = req.RegionId; } if (req.IsDefaultAddr == 1) { var addrs = db.TnetNodeconsigneeaddrSet.Where(c => c.Nodeid == req.Nodeid && c.Isdefault == 1).ToList(); if (addrs.Count > 0) { addrs.ForEach(c => c.Isdefault = 0); if (db.SaveChanges() < addrs.Count) { db.Rollback(); log.Info("清空默认地址失败"); return(Fail("清空默认地址失败")); } } } addr.Mobile = req.Moblie; addr.Address = req.AddrDetail; addr.Consigneename = req.UserName; addr.Postcode = ""; addr.Isdefault = req.IsDefaultAddr; if (db.SaveChanges() <= 0) { db.Rollback(); log.Info("更改收货地址失败,请稍后重试"); return(Fail("更改收货地址失败")); } db.Commit(); return(OK()); } catch (Exception e) { db.Rollback(); log.Info("异常处理" + e.ToString()); return(Fail("服务器异常"));; } }
public Respbase EditAddress(EditAddressReq req) { var result = facede.EditAddress(req); return(result); }