public ActionResult SaveOrUpdate(Customer customer) { try { if (customer.Id > 0) { customer = this.CustomerRepository.Get(customer.Id); TryUpdateModel(customer); } if (customer.Pinyin.IsNullOrEmpty() && !customer.Name.IsNullOrEmpty()) { customer.Pinyin = ChineseToSpell.GetChineseSpell(customer.Name); } customer = this.CustomerRepository.SaveOrUpdate(customer); return(JsonSuccess(customer)); } catch (Exception ex) { return(JsonError(ex.Message)); } }
public ActionResult SaveOrUpdate(Goods obj, int[] categorys) { try { if (obj.Id > 0) { obj = this.GoodsRepository.Get(obj.Id); TryUpdateModel(obj); } if (obj.Pinyin.IsNullOrEmpty() && !obj.Name.IsNullOrEmpty()) { obj.Pinyin = ChineseToSpell.GetChineseSpell(obj.Name); } obj = this.GoodsRepository.SaveOrUpdate(obj); if (categorys != null) { IList <GoodsType> types = this.GoodsTypeRepository.GetGoodsTypes(obj.Id); IList <int> ids = categorys.ToList(); // //每个商品可以属于多个类别 //先删除新类别中不存在的类别 int nLen = types.Count - 1; for (int i = nLen; i >= 0; i--) { GoodsType goodsType = types[nLen]; if (ids.IndexOf(goodsType.Type.Id) >= 0) { ids.Remove(goodsType.Type.Id); } else { this.GoodsTypeRepository.Delete(goodsType); } } foreach (var id in ids) { this.GoodsTypeRepository.SaveOrUpdate(new GoodsType() { Goods = obj, Type = this.CommonCodeRepository.Get(id) }); } } return(JsonSuccess(obj)); } catch (Exception ex) { return(JsonError(ex.Message)); } }
public ActionResult SaveOrUpdate(User user, string psw) { try { if (user.Id <= 0) { string strUserName = user.LoginName.Trim(); MembershipUser membershipuser = Membership.GetUser(strUserName); if (membershipuser != null) { throw new Exception("用户[" + strUserName + "]已经存在,请更换登录名!"); } membershipuser = Membership.CreateUser(strUserName, psw); user.MemberShipId = (Guid)membershipuser.ProviderUserKey; } else { user = this.UserRepository.Get(user.Id); TryUpdateModel(user); } if (user.Pinyin.IsNullOrEmpty() && !user.RealName.IsNullOrEmpty()) { user.Pinyin = ChineseToSpell.GetChineseSpell(user.RealName); } user = this.UserRepository.SaveOrUpdate(user); return(JsonSuccess(user)); } catch (Exception ex) { return(JsonError(ex.Message)); } }