开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 319

TWT20161022/视频学习+在线考试+题库+直播

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (4)
标签 (8)
master
dev
beta
optimize
2.3
2.1.1.21041
2.0.8627
2.0.8499
2.0.8460
2.0.8384
2.0.8355
2.0Beta
master
分支 (4)
标签 (8)
master
dev
beta
optimize
2.3
2.1.1.21041
2.0.8627
2.0.8499
2.0.8460
2.0.8384
2.0.8355
2.0Beta
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (4)
标签 (8)
master
dev
beta
optimize
2.3
2.1.1.21041
2.0.8627
2.0.8499
2.0.8460
2.0.8384
2.0.8355
2.0Beta
Subject.cs 12.79 KB
一键复制 编辑 原始数据 按行查看 历史
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using System.Web.Mvc;
using Song.Entities;
using Song.ServiceInterfaces;
using Song.ViewData.Attri;
using WeiSha.Core;
using System.Data;
using Newtonsoft.Json.Linq;
using System.Web;
using System.IO;
namespace Song.ViewData.Methods
{
/// <summary>
/// 专业管理,或叫学科管理
/// </summary>
[HttpPut, HttpGet]
public class Subject : ViewMethod, IViewAPI
{
//资源的虚拟路径和物理路径
public static string VirPath = WeiSha.Core.Upload.Get["Subject"].Virtual;
public static string PhyPath = WeiSha.Core.Upload.Get["Subject"].Physics;
/// <summary>
/// 通过专业ID,获取专业信息
/// </summary>
/// <param name="id">专业id</param>
/// <returns></returns>
[Cache(AdminDisable = true)]
public Song.Entities.Subject ForID(long id)
{
Song.Entities.Subject sbj = Business.Do<ISubject>().SubjectSingle(id);
return _tran(sbj);
}
/// <summary>
/// 添加课程专业
/// </summary>
/// <param name="entity">专业的实体</param>
/// <returns></returns>
[Admin]
[HttpPost]
[Upload(Extension = "jpg,png,gif", MaxSize = 1024, CannotEmpty = false)]
[HtmlClear(Not = "entity")]
public Song.Entities.Subject Add(Song.Entities.Subject entity)
{
if (this.Files.Count > 0)
entity = this._upload_photo(this.Files, entity);
try
{
Business.Do<ISubject>().SubjectAdd(entity);
return entity;
}
catch (Exception ex)
{
if (this.Files.Count > 0)
WeiSha.Core.Upload.Get["Subject"].DeleteFile(entity.Sbj_Logo);
throw ex;
}
}
/// <summary>
/// 修改课程专业
/// </summary>
/// <param name="entity">专业的实体</param>
/// <returns></returns>
[Admin]
[HttpPost]
[Upload(Extension = "jpg,png,gif", MaxSize = 1024, CannotEmpty = false)]
[HtmlClear(Not = "entity")]
public Song.Entities.Subject Modify(Song.Entities.Subject entity)
{
Song.Entities.Subject old = Business.Do<ISubject>().SubjectSingle(entity.Sbj_ID);
if (old == null) throw new Exception("Not found entity for Subject!");
//上传的图片
string oldlogo = old.Sbj_Logo; //之前的图片
entity = this._upload_photo(this.Files, entity);
try
{
string nomidfy = "Sbj_CrtTime";
if (this.Files.Count < 1) nomidfy += "Sbj_Logo,Sbj_LogoSmall";
old.Copy<Song.Entities.Subject>(entity, nomidfy);
Business.Do<ISubject>().SubjectSave(old);
if ((this.Files.Count > 0 && !string.IsNullOrWhiteSpace(oldlogo))
|| (this.Files.Count < 1) && string.IsNullOrWhiteSpace(entity.Sbj_Logo) && !string.IsNullOrWhiteSpace(oldlogo))
{
WeiSha.Core.Upload.Get["Subject"].DeleteFile(oldlogo);
}
return _tran(old);
}
catch (Exception ex)
{
if (this.Files.Count > 0)
WeiSha.Core.Upload.Get["Subject"].DeleteFile(entity.Sbj_Logo);
throw ex;
}
}
private Song.Entities.Subject _upload_photo(HttpFileCollectionBase files, Song.Entities.Subject entity)
{
string filename = string.Empty, smallfile = string.Empty;
//只保存第一张图片
if (this.Files.Count > 0)
{
foreach (string key in this.Files)
{
HttpPostedFileBase file = this.Files[key];
filename = WeiSha.Core.Request.UniqueID() + Path.GetExtension(file.FileName);
file.SaveAs(PhyPath + filename);
try
{
//生成缩略图
smallfile = WeiSha.Core.Images.Name.ToSmall(filename);
WeiSha.Core.Images.FileTo.Thumbnail(PhyPath + filename, PhyPath + smallfile, 320, 180, 0);
}
catch (Exception ex)
{
//WeiSha.Core.Upload.Get["Subject"].DeleteFile(filename);
//throw ex;
}
break;
}
}
entity.Sbj_Logo = filename;
entity.Sbj_LogoSmall = smallfile;
return entity;
}
/// <summary>
/// 更改专业的排序
/// </summary>
/// <param name="list">专业的数组</param>
/// <returns></returns>
[HttpPost]
[Admin]
public bool ModifyTaxis(Song.Entities.Subject[] list)
{
try
{
Business.Do<ISubject>().UpdateTaxis(list);
return true;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 删除课程专业
/// </summary>
/// <param name="id">账户id,可以是多个,用逗号分隔</param>
/// <returns></returns>
[Admin]
[HttpDelete,HttpGet(Ignore =true)]
public int Delete(string id)
{
int i = 0;
if (string.IsNullOrWhiteSpace(id)) return i;
string[] arr = id.Split(',');
foreach (string s in arr)
{
long idval = 0;
long.TryParse(s, out idval);
if (idval == 0) continue;
try
{
Business.Do<ISubject>().SubjectDelete(idval);
i++;
}
catch (Exception ex)
{
throw ex;
}
}
return i;
}
/// <summary>
/// 某个机构下的所有专业
/// </summary>
/// <param name="orgid">机构id</param>
/// <param name="search"></param>
/// <param name="isuse"></param>
/// <returns>专业列表</returns>
public List<Song.Entities.Subject> List(int orgid, string search, bool? isuse)
{
List<Song.Entities.Subject> sbjs = Business.Do<ISubject>().SubjectCount(orgid, search, isuse, -1, -1);
for (int i = 0; i < sbjs.Count; i++)
{
sbjs[i] = _tran(sbjs[i]);
}
return sbjs;
}
/// <summary>
/// 某个机构下的专业,用于前端展示,被禁用的专业不显示
/// </summary>
/// <param name="orgid">机构id</param>
/// <returns>专业列表</returns>
[Cache]
public JArray TreeFront(int orgid)
{
List<Song.Entities.Subject> sbjs = Business.Do<ISubject>().SubjectCount(orgid, string.Empty, true, -1, -1);
for (int i = 0; i < sbjs.Count; i++)
{
sbjs[i] = _tran(sbjs[i]);
}
return sbjs.Count > 0 ? _SubjectNode(null, sbjs) : null;
}
/// <summary>
/// 机构下的专业,树形数据
/// </summary>
/// <param name="orgid">机构id</param>
/// <param name="search">按名称检索</param>
/// <param name="isuse">是否启用</param>
/// <returns></returns>
public JArray Tree(int orgid, string search, bool? isuse)
{
List<Song.Entities.Subject> sbjs = Business.Do<ISubject>().SubjectCount(orgid, search, isuse, -1, -1);
for (int i = 0; i < sbjs.Count; i++)
{
sbjs[i] = _tran(sbjs[i]);
}
return sbjs.Count > 0 ? _SubjectNode(null, sbjs) : null;
}
/// <summary>
/// 生成菜单子节点
/// </summary>
/// <param name="item">当前菜单项</param>
/// <param name="items">所有菜单项</param>
/// <returns></returns>
private JArray _SubjectNode(Song.Entities.Subject item, List<Song.Entities.Subject> items)
{
JArray jarr = new JArray();
foreach (Song.Entities.Subject m in items)
{
if (item == null)
{
if (m.Sbj_PID != 0) continue;
}
else
{
if (m.Sbj_PID != item.Sbj_ID) continue;
}
string j = m.ToJson("", "Sbj_CrtTime");
JObject jo = JObject.Parse(j);
jarr.Add(jo);
//计算下级
JArray charray = _SubjectNode(m, items);
if (charray.Count > 0)
jo.Add("children", charray);
}
return jarr;
}
/// <summary>
/// 供前端显示的专业最顶级分类
/// </summary>
/// <param name="orgid"></param>
/// <param name="count"></param>
/// <returns></returns>
[Cache]
public List<Song.Entities.Subject> ShowRoot(int orgid, int count)
{
List<Song.Entities.Subject> sbjs = Business.Do<ISubject>().SubjectCount(orgid, string.Empty, true, 0, count);
string path = WeiSha.Core.Upload.Get["Subject"].Virtual;
for(int i = 0; i < sbjs.Count; i++)
{
Song.Entities.Subject c = sbjs[i];
c = _tran(c);
//如果别名为空,则别名等于专业名称
if (string.IsNullOrWhiteSpace(c.Sbj_ByName) || c.Sbj_ByName.Trim() == "")
c.Sbj_ByName = c.Sbj_Name;
c.Sbj_Intro = HTML.ClearTag(c.Sbj_Intro);
}
return sbjs;
}
/// <summary>
/// 分页获取专业(前端页面)
/// </summary>
/// <param name="orgid">机构id</param>
/// <param name="pid">上级id,默认是0</param>
/// <param name="index">页码,即第几页</param>
/// <param name="size">每页多少条记录</param>
/// <returns></returns>
public ListResult PagerFront(int orgid,long pid,int index, int size)
{
int sum = 0;
Song.Entities.Subject[] list = Business.Do<ISubject>().SubjectPager(orgid, pid, true, string.Empty, size, index, out sum);
for (int i = 0; i < list.Length; i++)
{
list[i] = _tran(list[i]);
}
Song.ViewData.ListResult result = new ListResult(list);
result.Index = index;
result.Size = size;
result.Total = sum;
return result;
}
/// <summary>
/// 专业下的课程数,包括专业下的子级专业
/// </summary>
/// <param name="sbjid">专业id</param>
/// <param name="use">是否包括启用的课程,null取所有,true取启用的,false取未启用的</param>
/// <returns></returns>
[Cache(AdminDisable = true)]
public int CountOfCourse(long sbjid, bool? use)
{
Business.Do<ICourse>().CourseOfCount(sbjid);
return Business.Do<ICourse>().CourseOfCount(-1, sbjid, -1, use, null);
}
/// <summary>
/// 当前专业所包含的所有下级专业数量(不包括自身)
/// </summary>
/// <param name="orgid">机构id</param>
/// <param name="sbjid">当前专业id,为0时为顶级</param>
/// <param name="use">是否包括启用的课程,null取所有,true取启用的,false取未启用的</param>
/// <returns></returns>
public int CountOfChildren(int orgid,long sbjid, bool? use)
{
return Business.Do<ISubject>().SubjectOfCount(orgid, sbjid, use, true);
}
#region 私有方法,处理对象的关联信息
/// <summary>
/// 处理专业信息,图片转为全路径,并生成clone对象
/// </summary>
/// <param name="obj">专业对象</param>
/// <returns></returns>
private Song.Entities.Subject _tran(Song.Entities.Subject obj)
{
if (obj == null) return obj;
obj.Sbj_Logo = System.IO.File.Exists(PhyPath + obj.Sbj_Logo) ? VirPath + obj.Sbj_Logo : "";
obj.Sbj_LogoSmall = System.IO.File.Exists(PhyPath + obj.Sbj_LogoSmall) ? VirPath + obj.Sbj_LogoSmall : "";
if (string.IsNullOrWhiteSpace(obj.Sbj_LogoSmall) && !string.IsNullOrWhiteSpace(obj.Sbj_Logo))
obj.Sbj_LogoSmall = obj.Sbj_Logo;
return obj;
}
#endregion
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

前后端分离,C#、Vue。web端采用ElementUI,手机端采用VantUI,管理后台采用WebdeskUI。直播、视频学习、试题练习、测试、考试、学习证明、成绩打印,实现"学、练、考"一体。
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/wtt2016/LearningSystem.git
git@gitee.com:wtt2016/LearningSystem.git
wtt2016
LearningSystem
视频学习+在线考试+题库+直播
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /