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 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)); } }