public JsonResult Create(OrderBuyerType obj) { try { NSession.SaveOrUpdate(obj); NSession.Flush(); } catch (Exception ee) { return Json(new { IsSuccess = false, ErrorMsg = "出错了" }); } return Json(new { IsSuccess = true }); }
/// <summary> /// 创建客户数据 /// </summary> /// <param name="name"></param> /// <param name="email"></param> /// <param name="amount"></param> /// <param name="buyOn"></param> /// <param name="platform"></param> /// <returns></returns> public static int CreateBuyer(string name, string email, double amount, DateTime buyOn, PlatformEnum platform, ISession NSession) { IList<OrderBuyerType> list = NSession.CreateQuery(" from OrderBuyerType where BuyerName=:p and Platform=:p2").SetString("p", name).SetString("p2", platform.ToString()).List<OrderBuyerType>(); OrderBuyerType buyer = new OrderBuyerType(); if (list.Count > 0) { buyer = list[0]; buyer.BuyCount += 1; buyer.BuyAmount += amount; buyer.ListBuyOn = buyOn; } else { buyer = new OrderBuyerType(); buyer.BuyerName = name; buyer.BuyerEmail = email; buyer.FristBuyOn = buyOn; buyer.BuyCount = 1; buyer.BuyAmount = amount; buyer.ListBuyOn = buyOn; buyer.Platform = platform.ToString(); } NSession.SaveOrUpdate(buyer); NSession.Flush(); return buyer.Id; }