コード例 #1
0
ファイル: ActiveController.cs プロジェクト: Ivanhuan/Clubs
        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));
        }
コード例 #2
0
        public ActionResult GetActiveListData2(int page, int limit, string cid)
        {
            List <ActiveListModel>  models = new List <ActiveListModel>();
            IQueryable <Activities> actlist;

            if (string.IsNullOrEmpty(cid))
            {
                actlist = db.Activities.OrderByDescending(a => a.Id).Skip((page - 1) * limit).Take(limit);
            }
            else
            {
                actlist = db.Activities.Where(a => a.Club.ClubId == cid).OrderByDescending(a => a.Id).Skip((page - 1) * limit).Take(limit);
            }
            foreach (Activities act in actlist)
            {
                ActiveListModel model = new ActiveListModel()
                {
                    Id         = act.Id,
                    Title1     = act.Title1,
                    Title2     = act.Title2,
                    Time1      = act.Time1.ToString("yyyy/MM/dd hh:mm"),
                    Time2      = act.Time2.ToString("yyyy/MM/dd hh:mm"),
                    CreateDate = act.CreateDate.ToString(),
                    UserID     = act.User.UserId,
                    UserName   = act.User.UserName,
                    VoteCount  = db.Votings.Where(v => v.Active.Id == act.Id).Count().ToString(),
                    State      = Enum.GetName(typeof(ActiveState), act.State),
                    Votes0     = string.IsNullOrEmpty(act.Votes0) ? "0" : act.Votes0
                };
                if (act.State > (int)ActiveState.已取消)
                {
                    if (act.Time1 > DateTime.Now)
                    {
                        model.State = "未开始";
                    }
                    else if (act.Time2 > DateTime.Now)
                    {
                        model.State = "进行中";
                    }
                    else
                    {
                        model.State = "已结束";
                    }
                }

                models.Add(model);
            }
            PageDataModel dataModel = new PageDataModel()
            {
                code  = 0,
                msg   = "",
                count = db.Activities.Count(),
                data  = models.AsQueryable()
            };

            return(Json(dataModel, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
ファイル: ActiveController.cs プロジェクト: Ivanhuan/Clubs
        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"));
        }
コード例 #4
0
ファイル: ActiveController.cs プロジェクト: Ivanhuan/Clubs
 public ActionResult Add(ActiveListModel model)
 {
     return(View(model));
 }
コード例 #5
0
        public ActionResult GetActiveListData(int page, string cid)
        {
            int count = 6;//单页显示数量
            List <ActiveListModel>  models = new List <ActiveListModel>();
            IQueryable <Activities> actlist;

            if (string.IsNullOrEmpty(cid))
            {
                actlist = db.Activities.Where(a => a.State > 2).OrderByDescending(a => a.Id).Skip((page - 1) * count).Take(count);
            }
            else
            {
                actlist = db.Activities.Where(a => a.Club.ClubId == cid).OrderByDescending(a => a.Id).Skip((page - 1) * count).Take(count);
            }
            foreach (Activities act in actlist)
            {
                ActiveListModel model = new ActiveListModel()
                {
                    Id         = act.Id,
                    Labels     = act.Label.Split(',').ToList(),
                    HeadImg    = act.Club.HeadImg,
                    Title1     = act.Title1,
                    Title2     = act.Title2,
                    Content    = act.Content,
                    MaxUser    = act.MaxUser,
                    Area1      = act.Area?.Name,
                    Time1      = act.Time1.ToString("yyyy/MM/dd hh:mm"),
                    Time2      = act.Time2.ToString("yyyy/MM/dd hh:mm"),
                    CreateDate = act.CreateDate.ToString(),
                    UserID     = act.User.UserId,
                    UserName   = act.User.UserName,
                    ClubID     = act.Club.ClubId,
                    ClubName   = act.Club.Name,
                    VoteCount  = db.Votings.Where(v => v.Active.Id == act.Id).Count().ToString(),
                    // State = Enum.GetName(typeof(ActiveState), act.State),
                    Votes0 = string.IsNullOrEmpty(act.Votes0)?"0":act.Votes0
                };
                if (act.Time1 > DateTime.Now)
                {
                    model.State = "未开始";
                }
                else if (act.Time2 > DateTime.Now)
                {
                    model.State = "进行中";
                }
                else
                {
                    model.State = "已结束";
                }
                if (act.Area == null)
                {
                    if (string.IsNullOrEmpty(act.Area0))
                    {
                        model.Area1 = "未知";
                    }
                    else
                    {
                        model.Area1 = act.Area0;
                    }
                }

                models.Add(model);
            }
            PageDataModel dataModel = new PageDataModel()
            {
                code  = 0,
                msg   = "",
                count = (int)Math.Ceiling((double)db.Activities.Count() / count),
                data  = models.AsQueryable()
            };

            return(Json(dataModel, JsonRequestBehavior.AllowGet));
        }