public IHttpActionResult PutVotingSession(VotingSession votingSession)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Entry(votingSession).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VotingSessionExists(votingSession.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PostVotingSession(VotingSession votingSession)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.VotingSessions.Add(votingSession);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = votingSession.Id }, votingSession));
        }
        public IHttpActionResult DeleteVotingSession(int id)
        {
            VotingSession votingSession = db.VotingSessions.Find(id);

            if (votingSession == null)
            {
                return(NotFound());
            }

            db.VotingSessions.Remove(votingSession);
            db.SaveChanges();

            return(Ok(votingSession));
        }
        public IHttpActionResult GetVotingSession(int id)
        {
            VotingSession votingSession = db.VotingSessions.Include(s => s.Candidates).Where(s => s.Id == id).SingleOrDefault();

            if (votingSession == null)
            {
                var latestDate = db.VotingSessions.Max(s => s.EndDate);
                votingSession = db.VotingSessions.Include(s => s.Candidates).Where(s => s.EndDate == latestDate).SingleOrDefault();
                if (votingSession == null)
                {
                    return(NotFound());
                }
            }
            return(Ok(votingSession));
        }
Ejemplo n.º 5
0
        public ActionResult CreateVotingSession(VotingSession model, string subject, string message)
        {
            #region voting session data validation
            var EmailString = "";
            foreach (var item in db.EligibleMembers)
            {
                EmailString += item.email + ",";
            }
            EmailString = EmailString.Remove(EmailString.Length - 1);
            var toEmail   = EmailString;
            var EmailSubj = subject;
            var EmailMsg  = message;
            //passing parameter to Email Method
            //SendEmail.Email_Without_Attachment(toEmail, EmailSubj, EmailMsg);

            var      sdate     = Convert.ToDateTime(model.startDate).ToShortDateString();
            var      stime     = Convert.ToDateTime(model.startTime.ToString()).ToLongTimeString();
            var      sdatetime = sdate + " " + stime;
            DateTime sDATEtime = Convert.ToDateTime(sdatetime);

            var      cdate     = Convert.ToDateTime(model.closeDate).ToShortDateString();
            var      ctime     = Convert.ToDateTime(model.closeTime.ToString()).ToLongTimeString();
            var      cdatetime = cdate + " " + ctime;
            DateTime cDATEtime = Convert.ToDateTime(cdatetime);

            if (sDATEtime > cDATEtime)
            {
                TempData["MessageType"] = "danger";
                TempData["Message"]     = "The start time is ahead of the close time!!";
                return(View(model));
            }
            if (db.VotingSessions.Where(dbl => dbl.PositionId == model.PositionId && dbl.status == true).Count() != 0)
            {
                TempData["MessageType"] = "danger";
                TempData["Message"]     = "You already have an active voting session for that position!!";
                return(View(model));
            }
            if (DateTime.Now > cDATEtime)
            {
                TempData["MessageType"] = "danger";
                TempData["Message"]     = "The time given has already elapsed!!";
                return(View(model));
            }
            var moment = "";
            if (DateTime.Now < sDATEtime)
            {
                moment = "Up Coming";
            }
            else if (DateTime.Now > sDATEtime && DateTime.Now < cDATEtime)
            {
                moment = "In Progress";
            }
            else if (DateTime.Now > cDATEtime)
            {
                moment = "Completed";
            }
            #endregion

            #region saving session data
            VotingSession c = new VotingSession
            {
                startDate     = model.startDate,
                startTime     = model.startTime,
                closeDate     = model.closeDate,
                closeTime     = model.closeTime,
                startDateTime = sDATEtime,
                closeDateTime = cDATEtime,
                PositionId    = model.PositionId,
                status        = true, // active or inactive!!
                moment        = moment,
            };
            VotingSession cc = db.VotingSessions.Add(c);
            db.SaveChanges();
            TempData["MessageType"] = "success";
            TempData["Message"]     = "Your Registration was successful!!";
            return(View());

            #endregion
        }