public ActionResult Create(Exhibit exhibit)
        {
            if (!Authorization.GetAccess(table, HttpContext.User.Identity.Name, write))
                return RedirectToAction("Index", "Home");

            if (ModelState.IsValid)
            {
                exhibit.ID = Guid.NewGuid();
                exhibit.CreatedBy = Guid.Parse(Session["userid"].ToString());
                exhibit.CreatedOn = DateTime.Now;
                db.Exhibits.AddObject(exhibit);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            populateListsWithSelection(exhibit);
            return View(exhibit);
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Exhibits EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToExhibits(Exhibit exhibit)
 {
     base.AddObject("Exhibits", exhibit);
 }
 /// <summary>
 /// Create a new Exhibit object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="thresholdID">Initial value of the ThresholdID property.</param>
 /// <param name="regimeID">Initial value of the RegimeID property.</param>
 /// <param name="uniqueID">Initial value of the UniqueID property.</param>
 public static Exhibit CreateExhibit(global::System.Guid id, global::System.String title, global::System.Guid thresholdID, global::System.Guid regimeID, global::System.Int32 uniqueID)
 {
     Exhibit exhibit = new Exhibit();
     exhibit.ID = id;
     exhibit.Title = title;
     exhibit.ThresholdID = thresholdID;
     exhibit.RegimeID = regimeID;
     exhibit.UniqueID = uniqueID;
     return exhibit;
 }
 private void populateListsWithSelection(Exhibit exhibit)
 {
     ViewBag.RegimeID = new SelectList(db.Regimes.Where(r => r.IsDeleted == null || r.IsDeleted == false).OrderBy(r => r.Regime1), "ID", "Regime1", exhibit.RegimeID);
     ViewBag.ThresholdID = new SelectList(db.Thresholds.Where(r => r.IsDeleted == null || r.IsDeleted == false).OrderBy(t => t.Threshold1), "ID", "Threshold1", exhibit.ThresholdID);
     ViewBag.TimeUnitID = new SelectList(db.TimeUnits.Where(tu => tu.IsDeleted == null || tu.IsDeleted == false), "ID", "TimeUnit1", exhibit.TimeUnitID);
     ViewBag.CreatedBy = new SelectList(db.Users, "ID", "UserName", exhibit.CreatedBy);
     ViewBag.ModifiedBy = new SelectList(db.Users, "ID", "UserName", exhibit.ModifiedBy);
 }
        public ActionResult Edit(Exhibit exhibit)
        {
            if (!Authorization.GetAccess(table, HttpContext.User.Identity.Name, write))
                return RedirectToAction("Index", "Home");

            if (ModelState.IsValid)
            {
                exhibit.ModifiedBy = Guid.Parse(Session["userid"].ToString());
                exhibit.ModifiedOn = DateTime.Now;
                db.Exhibits.Attach(exhibit);
                db.ObjectStateManager.ChangeObjectState(exhibit, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            populateListsWithSelection(exhibit);
            return View(exhibit);
        }
        private bool isValid(Timeline timeline, Exhibit exhibit)
        {
            if (timeline == null)
            {
                ModelState.AddModelError("TimelineID", "Timeline is required.");
                return false;
            }

            if (exhibit == null)
            {
                ModelState.AddModelError("ExhibitID", "Exhibit is required.");
                return false;
            }

            return isInBoundsWithParent(exhibit, timeline);
        }
        private bool isInBoundsWithParent(Exhibit exhibit, Timeline timeline)
        {
            bool isYearValid = true;
            string childTimeUnit = exhibit.TimeUnit.TimeUnit1.ToUpper();
            string parentFromTimeUnit = timeline.TimeUnit.TimeUnit1.ToUpper();
            string parentToTimeUnit = timeline.TimeUnit1.TimeUnit1.ToUpper();

            decimal parentTime = timeline.FromContentYear * determineFactor(parentFromTimeUnit);
            decimal childTime = exhibit.ContentYear.Value * determineFactor(childTimeUnit);

            //if both the timeunits are CE then the totime must be greater than the from time. Otherwise its vice versa
            if (parentFromTimeUnit == "CE" && childTimeUnit == "CE")
            {
                if (childTime < parentTime)
                    isYearValid = false;
            }
            else
            {
                if (childTime > parentTime)
                    isYearValid = false;
            }

            if (!isYearValid)
            {
                ModelState.AddModelError("ExhibitID", "Exhibit ContentYear and Timeunit must be within the bounds of the timeline");
                return false;
            }

            if (!(timeline.ToContentYear == 0 && (parentToTimeUnit == "GA" || parentToTimeUnit == "MA" || parentToTimeUnit  == "KA"))) //if 0 then its today
            {
                parentTime = timeline.ToContentYear * determineFactor(parentToTimeUnit);
                if (parentToTimeUnit == "CE" && parentToTimeUnit == "CE")
                {
                    if (childTime > parentTime)
                        isYearValid = false;
                }
                else
                {
                    if (childTime < parentTime)
                        isYearValid = false;
                }
            }

            if (!isYearValid)
            {
                ModelState.AddModelError("ExhibitID", "Exhibit ContentYear and Timeunit must be within the bounds of the timeline");
                return false;
            }

            return true;
        }