Exemple #1
0
        private ActionResult GetVoteResultView(VoteProject voteProject)
        {
            if (voteProject == null)
            {
                ViewBag.Message = "Wowo~~, we cannot find the vote.";
                return View("Alert");
            }

            var itemModels = GetVoteItems(voteProject.Id);

            var voteModel = new VoteModel() { Items = itemModels.OrderByDescending(i => i.Count).ToList(), Project = voteProject };

            return View("Result", voteModel);
        }
Exemple #2
0
        private VoteModel GetVoteModel(VoteProject voteProject)
        {
            //Get the VoteItems
            var voteItems = db.VoteItems.Where(i => i.PId == voteProject.Id && i.State == 0).ToList();
            var userId = User.Identity.Name.Split(',')[0];
            var voteDetails = db.VoteDetails.Where(d => d.State == 0 && d.PId == voteProject.Id && d.Voter == userId);

            var itemModels = new List<VoteItemModel>();

            foreach (var i in voteItems)
            {
                var itemModel = new VoteItemModel()
                {
                    Id = i.Id,
                    Comment = i.Comment,
                    PId = i.PId,
                    Name = i.Name,
                    Members = i.Nominees,
                    Nominator = i.Nominator,
                    State = 0
                };

                var detail = voteDetails.FirstOrDefault(d => d.IId == i.Id);

                itemModel.IsSelected = detail == null;//?false:true;
                itemModel.PreSelected = detail != null;//?false:true;

                itemModels.Add(itemModel);
            }

            var voteModel = new VoteModel() { Items = itemModels, Project = voteProject, CurrentUserVoteNum = voteDetails.ToList().Count };

            return voteModel;
        }
Exemple #3
0
 public ActionResult VoteProjectEdit(VoteProject voteproject)
 {
     if (ModelState.IsValid)
     {
         if (voteproject.BeginTime <= DateTime.Now && GetVoteItems(voteproject.Id).Count() <= 0)
         {
             ViewBag.ErrorMsg = "Please nominate before updating VoteBeginTime.";
             return View(ConvertProjectToModel(voteproject));
         }
         if (voteproject.BeginTime >= voteproject.EndTime)
         {
             ViewBag.ErrorMsg = "Create failed! The BeginTime's value cannot greater than the EndTime's vlaue.";
             return View(ConvertProjectToModel(voteproject));  //Convert VoteProject to VoteProjectModel
         }
         voteproject.ModifiedTime = DateTime.Now;
         voteproject.ModifiedBy = User.Identity.Name.Split(',')[0];
         db.Entry(voteproject).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("VoteProjectIndex");
     }
     return View(voteproject);
 }
Exemple #4
0
 /// <summary>
 /// Convert VoteProject to VoteProjectModel
 /// </summary>
 /// <param name="voteproject"></param>
 /// <returns></returns>
 private VoteProjectModel ConvertProjectToModel(VoteProject voteproject)
 {
     VoteProjectModel vpModel = new VoteProjectModel();
     vpModel.Id = voteproject.Id;
     vpModel.Name = voteproject.Name;
     vpModel.TermFrom = Convert.ToDateTime(voteproject.TermFrom);
     vpModel.TermTo = Convert.ToDateTime(voteproject.TermTo);
     vpModel.State = voteproject.State;
     vpModel.VoteNum = voteproject.VoteNum;
     vpModel.BeginTime = Convert.ToDateTime(voteproject.BeginTime);
     vpModel.EndTime = Convert.ToDateTime(voteproject.EndTime);
     return vpModel;
 }
Exemple #5
0
        public ActionResult VoteProjectAdd(VoteProject project)
        {
            if (ModelState.IsValid)
            {
                if (project.TermFrom >= project.TermTo)
                {
                    ViewBag.ErrorMsg = "Create failed! The TermFrom's value cannot greater than the TermTo's vlaue.";
                    return View(ConvertProjectToModel(project));  //Convert VoteProject to VoteProjectModel
                }
                if (project.BeginTime >= project.EndTime)
                {
                    ViewBag.ErrorMsg = "Create failed! The BeginTime's value cannot greater than the EndTime's vlaue.";
                    return View(ConvertProjectToModel(project));  //Convert VoteProject to VoteProjectModel
                }

                project.State = 0;
                project.CreatedTime = DateTime.Now;
                project.CreatedBy = User.Identity.Name.Split(',')[0];
                project.ModifiedTime = DateTime.Now;
                project.ModifiedBy = User.Identity.Name.Split(',')[0];
                db.VoteProjects.Add(project);
                db.SaveChanges();

                return RedirectToAction("VoteProjectIndex");
            }
            else
            { return View(project); }
        }