public async Task ModifyAppStarAsync(Int32 userId, Int32 appId, Int32 starCount) { Check.IfNullOrZero(userId); Check.IfNullOrZero(appId); Check.IfNullOrZero(starCount); await Task.Run(() => { using var mapper = EntityMapper.CreateMapper(); try { #region 前置条件判断 { var result = mapper.Query <AppStar>().Where(a => a.UserId == userId && a.AppId == appId).Count(); if (result > 0) { throw new BusinessException("您已为这个应用打分"); } } #endregion #region sql { var appStar = new AppStar(userId, appId, starCount); mapper.Add(appStar); } #endregion } catch (System.Exception) { throw; } }); }
public async Task RemoveAppAsync(Int32 appId) { Check.IfNullOrZero(appId); await Task.Run(() => { using var mapper = EntityMapper.CreateMapper(); mapper.OpenTransaction(); try { #region 移除应用的评分 { var appStar = new AppStar(); appStar.Remove(); var result = mapper.Update(appStar, star => star.AppId == appId); if (!result) { throw new BusinessException("移除应用的评分失败"); } } #endregion #region 移除应用 { var app = new App(); app.Remove(); var result = mapper.Update(app, a => a.Id == appId); if (!result) { throw new BusinessException("移除应用失败"); } } #endregion mapper.Commit(); } catch (Exception) { mapper.Rollback(); throw; } }); }