public CustomJsonResult Add(string operater, string merchId, RopStoreAdd rop) { CustomJsonResult result = new CustomJsonResult(); using (TransactionScope ts = new TransactionScope()) { var isExistStore = CurrentDb.Store.Where(m => m.MerchId == merchId && m.Name == rop.Name).FirstOrDefault(); if (isExistStore != null) { return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "名称已存在,请使用其它")); } var store = new Store(); store.Id = GuidUtil.New(); store.MerchId = merchId; store.Name = rop.Name; store.Address = rop.Address; store.BriefDes = rop.BriefDes; store.IsOpen = false; store.DispalyImgUrls = rop.DispalyImgUrls.ToJsonString(); store.MainImgUrl = ImgSet.GetMain(store.DispalyImgUrls); store.CreateTime = DateTime.Now; store.Creator = operater; CurrentDb.Store.Add(store); //默认 快递商品库存 var storeSellChannel = new StoreSellChannel(); storeSellChannel.Id = GuidUtil.New(); storeSellChannel.Name = "快递商品"; storeSellChannel.MerchId = merchId; storeSellChannel.StoreId = store.Id; storeSellChannel.RefType = E_StoreSellChannelRefType.Express; storeSellChannel.RefId = GuidUtil.Empty(); storeSellChannel.CreateTime = DateTime.Now; store.Creator = operater; CurrentDb.SaveChanges(); ts.Complete(); result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "保存成功"); } return(result); }
public CustomJsonResult AddMachine(string operater, string merchId, RopStoreAddMachine rop) { CustomJsonResult result = new CustomJsonResult(); using (TransactionScope ts = new TransactionScope()) { var merchMachine = CurrentDb.MerchMachine.Where(m => m.MerchId == merchId && m.MachineId == rop.MachineId).FirstOrDefault(); if (merchMachine == null) { return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "找不到商户的机器")); } if (!string.IsNullOrEmpty(merchMachine.StoreId)) { return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "已被使用")); } merchMachine.StoreId = rop.StoreId; merchMachine.Mender = operater; merchMachine.MendTime = DateTime.Now; var storeSellChannel = CurrentDb.StoreSellChannel.Where(m => m.MerchId == merchId && m.StoreId == rop.StoreId && m.RefType == E_StoreSellChannelRefType.Machine && m.RefId == rop.MachineId).FirstOrDefault(); if (storeSellChannel == null) { storeSellChannel = new StoreSellChannel(); storeSellChannel.Id = GuidUtil.New(); storeSellChannel.MerchId = merchId; storeSellChannel.StoreId = rop.StoreId; storeSellChannel.Name = merchMachine.Name; storeSellChannel.RefType = E_StoreSellChannelRefType.Machine; storeSellChannel.RefId = rop.MachineId; storeSellChannel.Creator = operater; storeSellChannel.CreateTime = DateTime.Now; CurrentDb.StoreSellChannel.Add(storeSellChannel); } CurrentDb.SaveChanges(); ts.Complete(); result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "添加成功"); } return(result); }