コード例 #1
0
        //
        // POST: /Api/Subjects
        /// <summary>
        /// Retrieves and updates Seats Available data for the specified <see cref="Section"/>
        /// </summary>
        /// <param name="classID"></param>
        /// <returns></returns>
        public ActionResult GetSeats(string classID)
        {
            int? seats = null;
              string friendlyTime = string.Empty;

              string itemNumber = classID.Substring(0, 4);
              string yrq = classID.Substring(4, 4);

              CourseHPQuery query = new CourseHPQuery();
              int hpSeats = query.FindOpenSeats(itemNumber, yrq);

              using (ClassScheduleDb db = new ClassScheduleDb())
              {
            //if the HP query didn't fail, save the changes. Otherwise, leave the SeatAvailability table alone.
            //This way, the correct number of seats can be pulled by the app and displayed instead of updating the
            //table with a 0 for seats available.
            if (hpSeats >= 0)
            {
              IQueryable<SectionSeat> seatsAvailableLocal = from s in db.SectionSeats
                                                        where s.ClassID == classID
                                                        select s;
              int rows = seatsAvailableLocal.Count();

              if (rows > 0)
              {
            // TODO: Should only be updating one record
            //update the value
            foreach (SectionSeat seat in seatsAvailableLocal)
            {
              seat.SeatsAvailable = hpSeats;
              seat.LastUpdated = DateTime.Now;
            }
              }
              else
              {
            //insert the value
            SectionSeat newseat = new SectionSeat();
            newseat.ClassID = classID;
            newseat.SeatsAvailable = hpSeats;
            newseat.LastUpdated = DateTime.Now;

            db.SectionSeats.AddObject(newseat);
              }

              db.SaveChanges();
            }

            // retrieve updated seats data
            IQueryable<SectionSeat> seatsAvailable = from s in db.SectionSeats
                                                 where s.ClassID == classID
                                                 select s;

            SectionSeat newSeat = seatsAvailable.First();

            seats = newSeat.SeatsAvailable;
            friendlyTime = newSeat.LastUpdated.GetValueOrDefault().ToString("h:mm tt").ToLower();
              }

              string jsonReturnValue = string.Format("{0}|{1}", seats, friendlyTime);
              return Json(jsonReturnValue);
        }
コード例 #2
0
        public ActionResult UpdateSectionFootnote(string classId, string newFootnoteText)
        {
            bool result = false;

            // Trim any whitespace
            if (!String.IsNullOrEmpty(newFootnoteText))
            {
                newFootnoteText = newFootnoteText.Trim();
            }

            if (HttpContext.User.Identity.IsAuthenticated == true)
            {
                using (ClassScheduleDb db = new ClassScheduleDb())
                {
                    IQueryable<SectionsMeta> footnotes = db.SectionsMetas.Where(s => s.ClassID == classId);

                    if (footnotes.Count() > 0)
                    {
                        // Should only update one section
                        foreach (SectionsMeta footnote in footnotes)
                        {
                            if (!String.Equals(footnote.Footnote, newFootnoteText))
                            {
                                footnote.Footnote = newFootnoteText;
                                footnote.LastUpdated = DateTime.Now;
                                //footnote.LastUpdatedBy

                                result = true;
                            }
                        }
                    }
                    else if (classId != null && !String.IsNullOrWhiteSpace(newFootnoteText))
                    {
                        // Insert footnote
                        SectionsMeta newFootnote = new SectionsMeta();
                        newFootnote.ClassID = classId;
                        newFootnote.Footnote = newFootnoteText;
                        newFootnote.LastUpdated = DateTime.Now;

                        db.SectionsMetas.AddObject(newFootnote);
                        result = true;
                    }

                    db.SaveChanges();
                }
            }

            return Json(new { result = result, footnote = newFootnoteText });
        }
コード例 #3
0
        public ActionResult ClassEdit(FormCollection collection)
        {
            string referrer = collection["referrer"];

            if (HttpContext.User.Identity.IsAuthenticated)
            {
                string courseId = collection["CourseID"];
                string username = HttpContext.User.Identity.Name;
                string footnote = collection["Footnote"];

                footnote = Helpers.StripHtml(footnote);

                if (ModelState.IsValid)
                {
              CourseMeta itemToUpdate;

              using (ClassScheduleDb db = new ClassScheduleDb())
                    {
                      bool exists = db.CourseMetas.Any(c => c.CourseID == courseId);
                      itemToUpdate = exists ? db.CourseMetas.Single(c => c.CourseID == courseId) : new CourseMeta();

                        itemToUpdate.CourseID = courseId;
                        itemToUpdate.Footnote = footnote;
                        itemToUpdate.LastUpdated = DateTime.Now;
                        itemToUpdate.LastUpdatedBy = username;

                      if (!exists)
                      {
                        db.CourseMetas.AddObject(itemToUpdate);
                      }

                        db.SaveChanges();
                    }
                }
            }

            return Redirect(referrer);
        }