/// <summary> /// 添加或更新商家 /// </summary> /// <param name="storeTypeEntity"></param> /// <returns></returns> public Tuple <bool, int> AddOrUpdateStoreInfo(StoreDetailInfoEntity storeInfo) { int result = 0; var id = -1; if (storeInfo.Id > 0) { string password = string.Empty; var temp = helper.QueryScalar($@"select [Password] from [User] where Id={storeInfo.Id}"); if (temp.ToString() == storeInfo.Password) { password = temp.ToString(); } else { password = Util.MD5Encrypt(storeInfo.Password); } if (!string.IsNullOrWhiteSpace(storeInfo.Password)) { result = helper.Execute($@"update [User] set UserName='******', Phone='{storeInfo.Phone}' ,Password='******' where Id={storeInfo.StoreId}; update StoreDetailInfo set StoreName='{storeInfo.StoreName}',StoreTypeId={storeInfo.StoreTypeId},MaximumStore={storeInfo.MaximumStore}, DelegatingContract='{storeInfo.DelegatingContract}',Province='{storeInfo.Province}',City='{storeInfo.City}', County='{storeInfo.County}',DetailAddress='{storeInfo.DetailAddress}' where UserId={storeInfo.StoreId};"); id = storeInfo.StoreId; } else { result = helper.Execute($@"update [User] set UserName='******', Phone='{storeInfo.Phone}' where Id={storeInfo.StoreId}; update StoreDetailInfo set StoreName='{storeInfo.StoreName}',StoreTypeId={storeInfo.StoreTypeId},MaximumStore={storeInfo.MaximumStore}, DelegatingContract='{storeInfo.DelegatingContract}',Province='{storeInfo.Province}',City='{storeInfo.City}', County='{storeInfo.County}',DetailAddress='{storeInfo.DetailAddress}' where UserId={storeInfo.StoreId};"); id = storeInfo.StoreId; } } else { var p = new DynamicParameters(); p.Add("@Id", dbType: DbType.Int32, direction: ParameterDirection.Output); string sql = $@"insert into [User] (UserName,Password,Phone,UserType,IsMain, StoreCode,StoreManage,SongManage,UserManage,Status) values ('{storeInfo.UserName}','{Util.MD5Encrypt(storeInfo.Password)}', '{storeInfo.Phone}',{2},{1},'{Guid.NewGuid().ToString()}',{1},{1},{1},{1});SELECT @Id=SCOPE_IDENTITY()"; result = helper.Execute(sql, p); id = p.Get <int>("@Id"); var detailSql = $@"insert into StoreDetailInfo (UserId,StoreName,StoretypeId,Province,City,County, DetailAddress,MaximumStore,DelegatingContract,CreateTime,Enabled) values ({id},'{storeInfo.StoreName}', {storeInfo.StoreTypeId},'{storeInfo.Province}','{storeInfo.City}','{storeInfo.County}','{storeInfo.DetailAddress}', {storeInfo.MaximumStore},'{storeInfo.DelegatingContract}','{DateTime.Now}',{1});"; helper.Execute(detailSql); } return(Tuple.Create(true, id)); }
/// <summary> /// 添加或更新商家信息 /// </summary> /// <param name="entity"></param> /// <returns></returns> public ActionResult AddOrUpdateStoreInfo(StoreDetailInfoEntity entity) { var result = storeRepository.AddOrUpdateStoreInfo(entity); return(Json(new { status = result.Item1, data = result.Item2 }, JsonRequestBehavior.AllowGet)); }