/// <summary> /// 详细页面 /// </summary> /// <param name="id"></param> /// <returns></returns> public IActionResult Detail(int id) { CaseOfficialBLL caseOfficialBLL = new CaseOfficialBLL(); CaseOfficialEntity caseOfficialEntity = caseOfficialBLL.GetById(id); return(View(caseOfficialEntity)); }
public ActionResult <DataResult> Edit([Bind("caseOfficialId,title, coverImage, contents")] CaseOfficialEntity caseOfficialEntity) { DataResult dataResult = new DataResult(); try { if (string.IsNullOrWhiteSpace(caseOfficialEntity.title)) { dataResult.code = "201"; dataResult.msg = "标题不能为空"; return(dataResult); } if (string.IsNullOrWhiteSpace(caseOfficialEntity.coverImage)) { dataResult.code = "201"; dataResult.msg = "图片不能为空"; return(dataResult); } if (string.IsNullOrWhiteSpace(caseOfficialEntity.contents)) { dataResult.code = "201"; dataResult.msg = "内容不能为空"; return(dataResult); } CaseOfficialBLL caseOfficialBLL = new CaseOfficialBLL(); CaseOfficialEntity caseOfficial = caseOfficialBLL.GetById(caseOfficialEntity.caseOfficialId); caseOfficial.contents = caseOfficialEntity.contents; caseOfficial.title = caseOfficialEntity.title; caseOfficial.coverImage = caseOfficialEntity.coverImage; caseOfficial.modifyDate = DateTime.Now; int rows = caseOfficialBLL.ActionDal.ActionDBAccess.Updateable(caseOfficial).ExecuteCommand(); if (rows > 0) { dataResult.code = "200"; dataResult.msg = "成功"; } else { dataResult.code = "201"; dataResult.msg = "失败"; } } catch (Exception e) { dataResult.code = "999"; dataResult.msg = e.Message; return(dataResult); } return(dataResult); }
/// <summary> /// 列表页面 /// </summary> /// <param name="searchString"></param> /// <param name="page"></param> /// <returns></returns> public IActionResult List(string searchString, int?page) { ViewBag.searchString = string.IsNullOrWhiteSpace(searchString) ? "" : searchString; int pageNumber = (page ?? 1); int pageSize = 15; CaseOfficialBLL caseOfficialBLL = new CaseOfficialBLL(); IPagedList <CaseOfficialEntity> caseOfficialEntities = caseOfficialBLL.AdminPageList(pageNumber, pageSize, searchString); return(View(caseOfficialEntities)); }
/// <summary> /// 删除 /// </summary> /// <param name="id"></param> /// <returns></returns> public IActionResult Delete(int id) { CaseOfficialBLL caseOfficialBLL = new CaseOfficialBLL(); CaseOfficialEntity caseOfficialEntity = caseOfficialBLL.GetById(id); caseOfficialEntity.isDel = true; caseOfficialEntity.modifyDate = DateTime.Now; int rows = caseOfficialBLL.ActionDal.ActionDBAccess.Updateable(caseOfficialEntity).ExecuteCommand(); return(RedirectToAction("List")); }
/// <summary> /// 打赏官方案例 /// </summary> /// <param name="userEntity"></param> /// <param name="caseOfficialId"></param> /// <returns></returns> private DataResult SponsorCaseOfficial(UserEntity userEntity, int caseOfficialId) { DataResult dr = new DataResult(); CaseOfficialBLL caseOfficialBLL = new CaseOfficialBLL(); CaseOfficialEntity caseOfficialEntity = caseOfficialBLL.GetById(caseOfficialId); if (caseOfficialEntity.isDel) { dr.code = "201"; dr.msg = "说说已被删除"; return(dr); } if (caseOfficialEntity.userId < 10000) { dr.code = "201"; dr.msg = "无主案例"; return(dr); } var result = caseOfficialBLL.ActionDal.ActionDBAccess.Ado.UseTran(() => { //积分减1 userEntity.integral = userEntity.integral - 1; var rows1 = caseOfficialBLL.ActionDal.ActionDBAccess.Updateable(userEntity).ExecuteCommand(); IntegralDetailEntity integralDetailEntity = new IntegralDetailEntity() { createDate = DateTime.Now, integral = -1, isDel = false, modifyDate = DateTime.Now, objId = caseOfficialId, type = (int)Entity.TypeEnumEntity.TypeEnum.官方案例, userId = userEntity.userId }; var rows2 = caseOfficialBLL.ActionDal.ActionDBAccess.Insertable(integralDetailEntity).ExecuteCommand(); //积分加1 UserEntity user = caseOfficialBLL.ActionDal.ActionDBAccess.Queryable <UserEntity>().Where(it => it.userId == caseOfficialEntity.userId).First(); user.integral = user.integral + 1; var rows3 = caseOfficialBLL.ActionDal.ActionDBAccess.Updateable(user).ExecuteCommand(); IntegralDetailEntity integralDetail = new IntegralDetailEntity() { createDate = DateTime.Now, integral = 1, isDel = false, modifyDate = DateTime.Now, objId = caseOfficialId, type = (int)Entity.TypeEnumEntity.TypeEnum.说说, userId = user.userId }; var rows4 = caseOfficialBLL.ActionDal.ActionDBAccess.Insertable(integralDetail).ExecuteCommand(); caseOfficialEntity.integral = caseOfficialEntity.integral + 1; var rows5 = caseOfficialBLL.ActionDal.ActionDBAccess.Updateable(caseOfficialEntity).ExecuteCommand(); }); //增加阅读记录 ReadBLL readBLL = new ReadBLL(); readBLL.Create(userEntity.userId, (int)Entity.TypeEnumEntity.TypeEnum.官方案例, caseOfficialId); if (result.IsSuccess) { dr.code = "200"; dr.msg = "成功"; } else { dr.code = "201"; dr.msg = "失败"; } return(dr); }
/// <summary> /// /// </summary> public CaseOfficialController() { this.caseOfficialBLL = new CaseOfficialBLL(); }
public JsonResult Newest([FromForm] string token, [FromForm] int pageNumber = 1, [FromForm] int pageSize = 10) { DataResult dr = new DataResult(); try { CaseBLL caseBLL = new CaseBLL(); ShareBLL shareBLL = new ShareBLL(); CaseOfficialBLL caseOfficialBLL = new CaseOfficialBLL(); int caseCount = caseBLL.Count(); int shareCount = shareBLL.Count(); int caseOfficialCount = caseOfficialBLL.Count(); int totalItemCount = caseCount + shareCount + caseOfficialCount; UserEntity userEntity = new UserEntity(); if (!string.IsNullOrWhiteSpace(token)) { userEntity = this.GetUserByToken(token); } List <CircleResultHelper> circleResultHelpers = caseBLL.CaseAndShareList(pageNumber: pageNumber, pageSize: pageSize, totalCount: totalItemCount, thisUserId: userEntity.userId > 10000 ? userEntity.userId : -1); List <CaseEntity> caseEntities = circleResultHelpers.Where(it => it.type == (int)Entity.TypeEnumEntity.TypeEnum.案例).Select(it => it.caseEntity).ToList(); if (caseEntities.Count > 0) { caseEntities = CaseListEndorseCountByList(caseEntities, userEntity.userId > 10000 ? userEntity.userId : -1); caseEntities = CaseListCommentCountByList(caseEntities); caseEntities.ForEach(it => { circleResultHelpers.Find(itt => itt.id == it.caseId).caseEntity = it; }); } List <ShareEntity> shareEntities = circleResultHelpers.Where(it => it.type == (int)Entity.TypeEnumEntity.TypeEnum.说说).Select(it => it.shareEntity).ToList(); if (shareEntities.Count > 0) { shareEntities = ShareListEndorseCountByList(shareEntities, userEntity.userId > 10000 ? userEntity.userId : -1); shareEntities = ShareListCommentCountByList(shareEntities); shareEntities.ForEach(it => { circleResultHelpers.Find(itt => itt.id == it.shareId).shareEntity = it; }); } List <CaseOfficialEntity> caseOfficialEntities = circleResultHelpers.Where(it => it.type == (int)Entity.TypeEnumEntity.TypeEnum.官方案例).Select(it => it.caseOfficialEntity).ToList(); if (caseOfficialEntities.Count > 0) { caseOfficialEntities = CaseOfficialEndorseCountByList(caseOfficialEntities, userEntity.userId > 10000 ? userEntity.userId : -1); caseOfficialEntities = CaseOfficialCommentCountByList(caseOfficialEntities); caseOfficialEntities.ForEach(it => { circleResultHelpers.Find(itt => itt.id == it.caseOfficialId).caseOfficialEntity = it; }); } circleResultHelpers = (from crh in circleResultHelpers orderby crh.createDate descending select crh ).ToList(); PageData pageData = new PageData(circleResultHelpers, pageNumber, pageSize, totalItemCount); dr.code = "200"; dr.data = pageData; } catch (Exception ex) { dr.code = "999"; dr.msg = ex.Message; } return(Json(dr)); }
public JsonResult Attention([FromForm] string token, [FromForm] int pageNumber = 1, [FromForm] int pageSize = 10) { DataResult dr = new DataResult(); try { UserEntity userEntity = this.GetUserByToken(token); FansBLL fansBLL = new FansBLL(); List <FansUserResult> fansUserResults = fansBLL.AttentionList(userEntity.userId); if (fansUserResults.Count < 1) { dr.code = "200"; dr.data = new PageData(null, pageNumber, pageSize, 0); dr.msg = "未关注任何人"; return(Json(dr)); } CaseBLL caseBLL = new CaseBLL(); ShareBLL shareBLL = new ShareBLL(); CaseOfficialBLL caseOfficialBLL = new CaseOfficialBLL(); int[] userIdInts = fansUserResults.Select(it => it.userId).ToArray(); int caseCount = caseBLL.CountByUserIdInts(userIdInts); int shareCount = shareBLL.CountByUserIdInts(userIdInts); int caseOfficialCount = caseOfficialBLL.CountByUserIdInts(userIdInts); int totalItemCount = caseCount + shareCount + caseOfficialCount; List <CircleResultHelper> circleResultHelpers = caseBLL.CaseAndShareList(pageNumber: pageNumber, pageSize: pageSize, totalCount: totalItemCount, userIdInte: userIdInts); List <CaseEntity> caseEntities = circleResultHelpers.Where(it => it.type == (int)Entity.TypeEnumEntity.TypeEnum.案例).Select(it => it.caseEntity).ToList(); if (caseEntities.Count > 0) { caseEntities = CaseListEndorseCountByList(caseEntities, userEntity.userId); caseEntities = CaseListCommentCountByList(caseEntities); caseEntities.ForEach(it => { circleResultHelpers.Find(itt => itt.id == it.caseId).caseEntity = it; }); } List <ShareEntity> shareEntities = circleResultHelpers.Where(it => it.type == (int)Entity.TypeEnumEntity.TypeEnum.说说).Select(it => it.shareEntity).ToList(); if (shareEntities.Count > 0) { shareEntities = ShareListEndorseCountByList(shareEntities, userEntity.userId); shareEntities = ShareListCommentCountByList(shareEntities); shareEntities.ForEach(it => { circleResultHelpers.Find(itt => itt.id == it.shareId).shareEntity = it; }); } List <CaseOfficialEntity> caseOfficialEntities = circleResultHelpers.Where(it => it.type == (int)Entity.TypeEnumEntity.TypeEnum.官方案例).Select(it => it.caseOfficialEntity).ToList(); if (caseOfficialEntities.Count > 0) { caseOfficialEntities = CaseOfficialEndorseCountByList(caseOfficialEntities, userEntity.userId); caseOfficialEntities = CaseOfficialCommentCountByList(caseOfficialEntities); caseOfficialEntities.ForEach(it => { circleResultHelpers.Find(itt => itt.id == it.caseOfficialId).caseOfficialEntity = it; }); } circleResultHelpers = (from crh in circleResultHelpers orderby crh.createDate descending select crh ).ToList(); PageData pageData = new PageData(circleResultHelpers, pageNumber, pageSize, totalItemCount); dr.code = "200"; dr.data = pageData; } catch (Exception ex) { dr.code = "999"; dr.msg = ex.Message; } return(Json(dr)); }