public ActionResult ApplyClubSubmit(string cid) { if (cid == null) { return(RedirectToAction("MyClubs")); } ClubNumber club = db.ClubNumbers.Find(cid); if (club == null) { return(HttpNotFound("未发现社团" + cid)); } ApplyClubSubModel model = new ApplyClubSubModel() { ClubId = club.ClubId, Type = club.Type.Name, Name = club.Name, HeadImg = club.HeadImg, ShortDesc = club.ShortDesc, Desc = club.Desc, State = Enum.GetName(typeof(EnumState), club.State), CreateDate = club.CreateDate == null ? "未知" : club.CreateDate.ToString(), User = club.User.UserName }; return(View(model)); }
public ActionResult AddAct(string cid) { if (cid == null) { return(RedirectToAction("Index")); } ClubNumber club = db.ClubNumbers.Find(cid); if (club == null) { Session["Error"] = "未发现社团" + cid; return(RedirectToAction("Error404", "Home")); } if (club.State != (int)EnumState.正常) { Session["Error"] = "活动<" + club.ClubId.ToString() + "-" + club.Name + ">非正常状态,无法发布活动"; return(RedirectToAction("Error404", "Home")); } ActiveListModel model = new ActiveListModel(); model.ClubID = club.ClubId; model.ClubName = club.Name; List <Area> areas = db.Areas.Where(a => a.State == (int)EnumState.正常).ToList(); model.Areas = new Dictionary <int, string>(); foreach (Area a in areas) { model.Areas.Add(a.Id, a.Name); } return(View(model)); }
public ActionResult JoinClub(string cid) { if (cid == null) { return(RedirectToAction("Index")); } ClubNumber club = db.ClubNumbers.Find(cid); if (club == null) { return(HttpNotFound("未发现社团" + cid)); } List <UserClubs> ucs = db.UserClubs.Where(u => u.Club.ClubId == club.ClubId && u.State > 0 && u.State < 5).ToList(); JoinClubSubModel model = new JoinClubSubModel() { ClubId = club.ClubId, Type = club.Type.Name, Name = club.Name, HeadImg = club.HeadImg, ShortDesc = club.ShortDesc, Desc = club.Desc, State = Enum.GetName(typeof(EnumState), club.State), CreateDate = club.CreateDate == null ? "未知" : club.CreateDate.ToString(), User = club.User.UserName, UserCount = ucs.Count(), CanJoin = !ucs.Where(u => u.User.UserId == User.Identity.Name).Any() }; return(View(model)); }
public ActionResult AuditClubAN(int?id, string AuditDesc) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ClubNumber club = db.ClubNumbers.Where(c => c.AuditID == id).FirstOrDefault(); if (club == null) { Session["Error"] = "未发现社团"; return(RedirectToAction("Error404", "Home")); } int res = AuditFun(id ?? 0, EnumAuditState.拒绝, AuditDesc); if (res == 1) { club.State = (int)EnumState.已失效; db.Entry(club).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("AuditClub", new { Msg = "社团申请任务[" + id + "]拒绝成功" }));; } else { return(RedirectToAction("AuditClub", new { Msg = "失败!社团申请任务[" + id + "]拒绝失败" })); } }
public ActionResult AddClubNumber(AddUserNumModel model) { if (ModelState.IsValid) { if (model.MinNum > model.NowNum) { if (model.MaxNum >= model.MinNum) { List <ClubNumber> clublist = new List <ClubNumber>(); for (int min = model.MinNum; min <= model.MaxNum; min++) { ClubNumber newclub = new ClubNumber() { ClubId = min.ToString(), State = (int)EnumState.未使用 }; clublist.Add(newclub); } db.ClubNumbers.AddRange(clublist); int addcount = db.SaveChanges(); return(RedirectToAction("ClubNumber", new { Msg = "成功添加" + addcount + "个账户" })); } else { ModelState.AddModelError("", "最大序号不能小于起始序号"); } } else { ModelState.AddModelError("", "起始序号需要大于当前已存在的最大序号:" + model.NowNum.ToString()); } } return(View(model)); }
public ActionResult ApplyClubSubmit([Bind(Include = "ClubId,ApplyDesc,ApplyFile")] ApplyClubSubModel model) { try { ClubNumber club = db.ClubNumbers.Find(model.ClubId); if (string.IsNullOrWhiteSpace(model.ApplyFile)) { ModelState.AddModelError("", "申请任务未上传审批文件!"); return(View(model)); } if (club.User.UserId != User.Identity.Name) { ModelState.AddModelError("", "非用户" + User.Identity.Name + "创建的申请不能由用户" + User.Identity.Name + "提交!"); return(View(model)); } if (club.State != (int)EnumState.待提交) { ModelState.AddModelError("", "请求状态错误不允许提交审批"); return(View(model)); } ApplyAudit apply = new ApplyAudit() { Type = db.ApplyTypes.Find((int)SQType.注册社团), ApplicationDesc = model.ApplyDesc, ApplicationFiled = model.ApplyFile, ApplyUser = club.User, Club = club, ApplyDate = DateTime.Now, CheckState = (int)EnumAuditState.创建, AuditTimes = 0 }; db.ApplyAudits.Add(apply); db.SaveChanges(); AuditDetail audit = new AuditDetail() { ApplyId = apply.Id, CheckState = (int)EnumAuditState.创建, AuditUser = club.User, AuditDate = DateTime.Now }; db.AuditDetails.Add(audit); club.State = (int)EnumState.待审批; club.AuditID = apply.Id; if (string.IsNullOrEmpty(club.HeadImg)) { club.HeadImg = "Content/images/head5.jpg";//设置社团默认头像图片 } db.Entry(club).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("MyClubs", new { Msg = "社团编号[" + club.ClubId + "]一个申请已提交,牢记并使用申请任务凭证[" + apply.Id + "]查看申请进度" })); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View(model)); } }
public ActionResult AddAct(ActiveListModel model) { ClubNumber club = db.ClubNumbers.Find(model.ClubID); UserNumber u = db.UserNumbers.Find(User.Identity.Name); if (club == null) { Session["Error"] = "未发现社团" + model.ClubID; return(RedirectToAction("Error404", "Home")); } //保存活动信息 Activities Act = new Activities() { Title1 = model.Title1, Title2 = model.Title2, Content = model.Content, MaxUser = model.MaxUser, Area0 = model.Area0, Club = club, CreateDate = DateTime.Now, User = u, State = (int)ActiveState.待提交, Votes0 = "0" }; if (model.Area != null) { Area a = db.Areas.Find(model.Area); if (a != null) { Act.Area = a; } } int type; int.TryParse(model.Type, out type); Act.Type = type; if (model.LabelStr?.Length > 1) { Act.Label = model.LabelStr.Substring(1); } DateTime t1; DateTime.TryParse(model.Time1, out t1); if (t1 < DateTime.Now) { ModelState.AddModelError("", "活动开始时间不能小于当前时间"); return(View(model)); } Act.Time1 = t1; DateTime.TryParse(model.Time2, out t1); Act.Time2 = t1; db.Activities.Add(Act); db.SaveChanges(); return(View("Index")); }
// GET: Active public ActionResult Index(string cid) { if (cid != null) { ClubNumber club = db.ClubNumbers.Find(cid); if (club != null) { ViewBag.ClubId = cid; } } return(View()); }
public ActionResult Add(string cid) { if (cid == null) { return(RedirectToAction("Index")); } ClubNumber club = db.ClubNumbers.Find(cid); if (club == null) { return(HttpNotFound("未发现社团" + cid)); } ViewBag.Club = club.Name; return(View()); }
public ActionResult Manage(string cid) { if (cid == null) { return(RedirectToAction("MyClubs")); } ClubNumber club = db.ClubNumbers.Find(cid); if (club == null) { return(HttpNotFound("未发现社团" + cid)); } ViewBag.ClubId = cid; return(View()); }
public ActionResult Club(string cid) { if (cid == null) { return(RedirectToAction("MyClubs")); } ClubNumber club = db.ClubNumbers.Find(cid); if (club == null) { return(HttpNotFound("未发现社团" + cid)); } List <UserClubs> ucs = db.UserClubs.Where(u => u.Club.ClubId == club.ClubId && u.State > 0 && u.State < 5).ToList(); List <Activities> activities = db.Activities.Where(a => a.Club.ClubId == club.ClubId).OrderBy(a => a.Id).Take(5).ToList(); List <AnnounceMent> announceMents = db.AnnounceMents.Where(a => a.Club.ClubId == club.ClubId && a.state == (int)EnumState.正常).OrderBy(a => a.Id).Take(5).ToList(); ClubViewModel model = new ClubViewModel() { ClubId = club.ClubId, ClubType = club.Type.Name, Labels = club.Label?.Split(',').ToList(), Name = club.Name, HeadImg = club.HeadImg ?? "Content/images/head5.jpg", ShortDesc = club.ShortDesc, Desc = club.Desc, State = club.State == null ? "" : Enum.GetName(typeof(EnumState), club.State), CreateDate = club.CreateDate2 == null ? "未知" : club.CreateDate2.ToString(), User = club.User, UserCount = ucs.Count, Activities = activities, announceMents = announceMents, status = "0" }; if (User != null) { UserClubs uc = ucs.Where(u => u.User.UserId == User.Identity.Name).FirstOrDefault(); if (uc != null) { model.status = Enum.GetName(typeof(UCStatus), uc.Status); } } return(View(model)); }
public async Task <ActionResult> AuditClubAY(int?id, string AuditDesc = "") { if (id == null) { Session["Error"] = "错误操作!审批过程未发现任务编号"; return(RedirectToAction("Error404", "Home")); } ClubNumber club = db.ClubNumbers.Where(c => c.AuditID == id).FirstOrDefault(); if (club == null) { Session["Error"] = "未发现社团"; return(RedirectToAction("Error404", "Home")); } int res = AuditFun(id ?? 0, EnumAuditState.通过, AuditDesc); if (res == 1) { return(RedirectToAction("AuditClub", new { Msg = "社团申请任务[" + id + "]审批成功" })); } else if (res == 2) { club.State = (int)EnumState.正常; club.CreateDate2 = DateTime.Now; db.Entry(club).State = System.Data.Entity.EntityState.Modified; if (club.User != null) { AppUser uid = db.Users.Where(u => u.UserName == club.User.UserId).FirstOrDefault(); AppUserManager userManager = HttpContext.GetOwinContext().GetUserManager <AppUserManager>(); bool c = userManager.IsInRoleAsync(uid.Id, "CAdmin").Result; if (!c) { await userManager.AddToRoleAsync(uid.Id, "CAdmin"); } } db.SaveChanges(); return(RedirectToAction("AuditClub", new { Msg = "社团申请任务[" + id + "]审批成功" })); } else { return(RedirectToAction("AuditClub", new { Msg = "失败!社团申请任务[" + id + "]审批失败" })); } }
public ActionResult AuditClubA(int?id) { if (id == null) { Session["Error"] = "未找到指定的社团申请"; return(RedirectToAction("Error404", "Home")); } ApplyAudit AppA = db.ApplyAudits.Find(id); if (AppA == null) { Session["Error"] = "未找到指定的社团申请" + id; return(RedirectToAction("Error404", "Home")); } ClubNumber club = AppA.Club; if (club == null) { Session["Error"] = "未从申请任务[" + id + "]中发现社团信息"; return(RedirectToAction("Error404", "Home")); } ApplyClubSubModel model = new ApplyClubSubModel() { ClubId = club.ClubId, Type = club.Type.Name, Name = club.Name, HeadImg = club.HeadImg, ShortDesc = club.ShortDesc, Desc = club.Desc, State = Enum.GetName(typeof(EnumState), club.State), CreateDate = club.CreateDate == null ? "未知" : club.CreateDate.ToString(), User = club.User.UserName, ApplyDesc = AppA.ApplicationDesc, ApplyFile = AppA.ApplicationFiled, AuditDate = AppA.AuditDate == null ? "未知" : AppA.AuditDate.ToString(), AuditTime = AppA.AuditTimes ?? 0, AuditId = AppA.Id }; return(View(model)); }
public ActionResult ApplyClubInfo(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "未找到指定的社团申请")); } ApplyAudit AppA = db.ApplyAudits.Find(id); if (AppA == null) { return(HttpNotFound("未找到指定的社团申请")); } if (AppA.CheckState == (int)EnumAuditState.通过 && AppA.ApplyUser.UserId == User.Identity.Name) { ClubNumber model = new ClubNumber(); model = AppA.Club; return(View(model)); } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }
public ActionResult ApplyClubInfo(ClubNumber model) { return(View(model)); }
public ActionResult UploadActImg(string cid) { EditData data1 = new EditData() { src = "", title = "" }; EditJson data = new EditJson() { code = 1, msg = "", data = data1 }; try { List <string> imgtype = new List <string>(new string[] { ".jpg", ".gif", ".png" }); HttpFileCollectionBase file = Request.Files; ClubNumber club = db.ClubNumbers.Find(cid); if (club == null) { data.msg += "未发现有效的社团"; } else if (file == null || file.Count < 1) { data.msg += "未成功接收文件"; } else if (!imgtype.Contains(Path.GetExtension(file[0].FileName))) { data.msg = "文件格式错误(jpg/gif/png)"; } else if (file[0].ContentLength > 2048000) { data.msg += "文件大小不允许超过2M"; } else { string filepath = Server.MapPath("~/Content/upload/act/"); if (!Directory.Exists(filepath)) { Directory.CreateDirectory(filepath); } string name = Path.GetFileName(file[0].FileName); if (name.Length > 10) { name = name.Substring(name.Length - 10); } Random r1 = new Random(); name = DateTime.Now.ToString("yyyyMMddhhmmss") + r1.Next(10).ToString() + name; //string ext = Path.GetExtension(name); file[0].SaveAs(filepath + cid + "_" + name); data.code = 0; data.data.title = cid + "_" + name; data.data.src = "../Content/upload/act/" + cid + "_" + name; data.msg += "保存成功"; } return(Json(data, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { data.msg = ex.Message; return(Json(data, JsonRequestBehavior.AllowGet)); } }
public ActionResult ClubHeadImg(string cid) { try { List <string> imgtype = new List <string>(new string[] { ".jpg", ".gif", ".png" }); HttpFileCollectionBase file = Request.Files; JsonData data = new JsonData() { code = 1, src = "", name = "", msg = "" }; ClubNumber club = db.ClubNumbers.Find(cid); if (club == null) { data.msg += "未发现有效的社团"; } else if (file == null || file.Count < 1) { data.msg += "未成功接收文件"; } else if (!imgtype.Contains(Path.GetExtension(file[0].FileName))) { data.msg = "文件格式错误(jpg/gif/png)"; } else if (file[0].ContentLength > 2048000) { data.msg += "文件大小不允许超过2M"; } else { int a = club.State ?? 0; if (a == (int)EnumState.待审批) { throw new Exception("正在审批中的社团不允许更新信息"); } string filepath = Server.MapPath("~/Content/upload/clubimg/"); if (!Directory.Exists(filepath)) { Directory.CreateDirectory(filepath); } string name = Path.GetFileName(file[0].FileName); if (name.Length > 10) { name = name.Substring(name.Length - 10); } //string ext = Path.GetExtension(name); file[0].SaveAs(filepath + cid + "_head_" + name); club.HeadImg = "Content/upload/clubimg/" + cid + "_head_" + name; db.Entry(club).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); data.code = 0; data.src = "Content/upload/clubimg /" + cid + "_head_" + name; data.msg += "保存成功"; } return(Json(data, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { JsonData data = new JsonData() { code = 4, src = "", name = "", msg = ex.Message }; return(Json(data, JsonRequestBehavior.AllowGet)); } }
public ActionResult ApplyClub(ApplyClubModel model) { if (ModelState.IsValid) { try { UserNumber thisuser = db.UserNumbers.Find(User.Identity.Name); ApplyType applyType = db.ApplyTypes.Find((int)SQType.注册社团); if (applyType == null || applyType.Enable != 1) { throw new Exception("注册社团的申请通道暂未开通,请持续关注后续开通公告或联系管理员"); } ClubNumber club = db.ClubNumbers.Where(c => c.User.UserId == User.Identity.Name).OrderByDescending(c => c.CreateDate).FirstOrDefault(); if (club != null && club.CreateDate != null) { if (DateTime.Now.Subtract((DateTime)club.CreateDate).Days < 1) { throw new Exception("每个用户每天只能申请一次社团创建!用户已于" + club.CreateDate.ToString() + "创建过申请!"); } } ClubNumber newclub = GetRandomClubNumber(); if (newclub == null || newclub.State != (int)EnumState.未使用) { throw new Exception("社团账号已达上限,暂无法新建社团。请联系管理员"); } //ApplyAudit apply = new ApplyAudit() //{ // Type = applyType, // ApplicationDesc = model.ApplyDesc, // ApplicationFiled = model.ApplyFile, // ApplyDate=DateTime.Now, // ApplyUser=db.UserNumbers.Find(User.Identity.Name), // CheckState=(int)EnumAuditState.已创建, // AuditTimes=0 //}; newclub.Name = model.Name; if (model.Label?.Length > 1) { newclub.Label = model.Label.Substring(1); } newclub.Desc = model.Desc; newclub.ShortDesc = model.ShortDesc; newclub.CreateDate = DateTime.Now; newclub.Type = db.ClubTypes.Find(model.Type); newclub.User = thisuser; newclub.State = (int)EnumState.待提交; //添加关系 UserClubs uc = new UserClubs() { User = thisuser, Club = newclub, Status = (int)UCStatus.社长, CreateDate = DateTime.Now, State = (int)EnumState.正常 }; db.Entry(newclub).State = System.Data.Entity.EntityState.Modified; db.UserClubs.Add(uc); db.SaveChanges(); model = new ApplyClubModel(); model.ClubId = newclub.ClubId; ViewBag.Res = "ApplyOK"; } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } model.clubTypes = db.ClubTypes.ToList(); return(View(model)); }
public ActionResult JoinClub([Bind(Include = "ClubId,ApplyDesc,ApplyFile")] JoinClubSubModel model) { try { ClubNumber club = db.ClubNumbers.Find(model.ClubId); UserNumber me = db.UserNumbers.Find(User.Identity.Name); if (string.IsNullOrWhiteSpace(model.ApplyFile)) { ModelState.AddModelError("", "申请任务未上传审批文件!"); return(View(model)); } if (db.UserClubs.Where(uc => uc.Club.ClubId == model.ClubId && uc.User.UserId == User.Identity.Name && uc.State > 0 && uc.State < 5).Any()) { ModelState.AddModelError("", "你已经是该社团成员或已申请加入该社团,不允许重复申请加入"); return(View(model)); } if (club.State != (int)EnumState.正常 && club.State != (int)EnumState.待提交) { string state = club.State == null ? "未知" : Enum.GetName(typeof(EnumState), club.State); ModelState.AddModelError("", "社团" + club.ClubId + "状态为:" + state + " 不允许申请加入"); return(View(model)); } ApplyAudit apply = new ApplyAudit() { Type = db.ApplyTypes.Find((int)SQType.加入社团), ApplicationDesc = model.ApplyDesc, ApplicationFiled = model.ApplyFile, ApplyUser = me, Club = club, ApplyDate = DateTime.Now, CheckState = (int)EnumAuditState.创建, AuditTimes = 0 }; db.ApplyAudits.Add(apply); db.SaveChanges(); AuditDetail audit = new AuditDetail() { ApplyId = apply.Id, CheckState = (int)EnumAuditState.创建, AuditUser = me, AuditDate = DateTime.Now }; db.AuditDetails.Add(audit); UserClubs newuserClubs = new UserClubs() { User = me, Club = club, State = (int)EnumState.待审批, CreateDate = DateTime.Now, Status = (int)UCStatus.申请中, AuditID = apply.Id }; db.UserClubs.Add(newuserClubs); db.SaveChanges(); return(RedirectToAction("MyClubs", new { Msg = "加入社团[" + club.ClubId + "]的一个申请已提交,牢记并使用申请任务凭证[" + apply.Id + "]查看申请进度" })); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View(model)); } }
public ActionResult ApplyClubFile(string cid) { try { HttpFileCollectionBase file = Request.Files; JsonData data = new JsonData() { code = 1, src = "", name = "", msg = "" }; if (file == null) { data.msg += "未成功接收文件"; } else if (file.Count > 0) { if (file[0].ContentLength > 2048000) { data.msg += "上传文件大小超过2M!不允许上传"; } else if (string.IsNullOrEmpty(cid)) { data.msg += "未识别到正确的社团账号,文件不被接收!"; } else { ClubNumber club = db.ClubNumbers.Find(cid); if (club == null) { data.msg = "未识别到正确的社团账号,文件不被接收!"; } else if (club.State != (int)EnumState.待提交) { data.msg = cid + "社团当前状态不允许上传审批文件"; } else { string filepath = Server.MapPath("~/Content/upload/apply/"); if (!Directory.Exists(filepath)) { Directory.CreateDirectory(filepath); } string name = Path.GetFileName(file[0].FileName); //string ext = Path.GetExtension(name); file[0].SaveAs(filepath + cid + "_" + name); data.src = "Content/upload/apply/" + cid + "_" + name; data.name = cid + "_" + name; data.code = 0; data.msg += "上传成功!"; } } } else { data.msg = "错误!服务器接收到上载文件的个数为:" + file.Count; } return(Json(data, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { JsonData data = new JsonData() { code = 4, src = "", name = "", msg = ex.Message }; return(Json(data, JsonRequestBehavior.AllowGet)); } }