public ActionResult Create(TimeUnit timeunit) { if (!Authorization.GetAccess(table, HttpContext.User.Identity.Name, write)) return RedirectToAction("Index", "Home"); if (ModelState.IsValid) { timeunit.ID = Guid.NewGuid(); timeunit.CreatedBy = Guid.Parse(Session["userid"].ToString()); timeunit.CreatedOn = DateTime.Now; db.TimeUnits.AddObject(timeunit); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.CreatedBy = new SelectList(db.Users, "ID", "UserName", timeunit.CreatedBy); ViewBag.ModifiedBy = new SelectList(db.Users, "ID", "UserName", timeunit.ModifiedBy); return View(timeunit); }
/// <summary> /// Deprecated Method for adding a new object to the TimeUnits EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToTimeUnits(TimeUnit timeUnit) { base.AddObject("TimeUnits", timeUnit); }
/// <summary> /// Create a new TimeUnit object. /// </summary> /// <param name="id">Initial value of the ID property.</param> /// <param name="timeUnit1">Initial value of the TimeUnit1 property.</param> public static TimeUnit CreateTimeUnit(global::System.Guid id, global::System.String timeUnit1) { TimeUnit timeUnit = new TimeUnit(); timeUnit.ID = id; timeUnit.TimeUnit1 = timeUnit1; return timeUnit; }
private bool isInBoundsWithParent(Timeline timeline, Timeline parentTimeline, TimeUnit fromTimeUnit, TimeUnit toTimeUnit) { bool isYearValid = true; decimal parentTime = 0, childTime = 0; string parentFromTimeUnit = parentTimeline.TimeUnit.TimeUnit1.ToUpper(); string childFromTimeUnit = fromTimeUnit.TimeUnit1.ToUpper(); string parentToTimeUnit = parentTimeline.TimeUnit1.TimeUnit1.ToUpper(); string childToTimeUnit = toTimeUnit.TimeUnit1.ToUpper(); parentTime = parentTimeline.FromContentYear * determineFactor(parentFromTimeUnit); childTime = timeline.FromContentYear * determineFactor(childFromTimeUnit); if (childTime < parentTime) { isYearValid = false; } if (!isYearValid) { ModelState.AddModelError("FromContentYear", "Child timeline must be within the bounds of the parent timeline"); return false; } if (!(parentTimeline.ToContentYear == 0 && (parentToTimeUnit == "GA" || parentToTimeUnit == "MA" || parentToTimeUnit == "KA"))) //if 0 then its today { parentTime = parentTimeline.ToContentYear * determineFactor(parentToTimeUnit); childTime = timeline.ToContentYear * determineFactor(childToTimeUnit); if (childTime > parentTime) { isYearValid = false; } } if (!isYearValid) { ModelState.AddModelError("ToContentYear", "Child timeline must be within the bounds of the parent timeline"); return false; } return true; }
private bool isInBounds(Timeline timeline, Timeline parentTimeline, TimeUnit fromTimeUnit, TimeUnit toTimeUnit) { decimal fromTime = 0, toTime = 0; string toTimeUnitValue = toTimeUnit.TimeUnit1.ToUpper(); string fromTimeUnitValue = fromTimeUnit.TimeUnit1.ToUpper(); if (timeline.ToContentYear == 0 && (toTimeUnitValue == "GA" || toTimeUnitValue == "MA" || toTimeUnitValue == "KA")) return true; if (timeline.FromContentYear == 0) { ModelState.AddModelError("FromContentYear", "From content year cannot be 0."); return false; } //Validate Toyear and timeunit if (timeline.ToContentYear == 0 && (toTimeUnitValue == "CE" || toTimeUnitValue == "BCE")) { ModelState.AddModelError("ToContentYear", "To content year cannot be 0 for timeunits CE and BCE."); return false; } if (!checkLimits(timeline.FromContentYear, fromTimeUnitValue)) { ModelState.AddModelError("FromContentYear", "From content year must be within the range of the selected timeunit."); return false; } if (!checkLimits(timeline.ToContentYear, toTimeUnitValue)) { ModelState.AddModelError("ToContentYear", "To content year must be within the range of the selected timeunit."); return false; } if (!checkTimeunits(fromTimeUnitValue, toTimeUnitValue)) { ModelState.AddModelError("ToTimeUnit", "ToTimeUnit must be within the bounds of the FromTimeUnit."); return false; } fromTime = timeline.FromContentYear * determineFactor(fromTimeUnitValue); toTime = timeline.ToContentYear * determineFactor(toTimeUnitValue); if (toTime < fromTime) { ModelState.AddModelError("ToContentYear", "ToContent year must be greater than the fromContent year."); return false; } if (parentTimeline != null) { return isInBoundsWithParent(timeline, parentTimeline, fromTimeUnit, toTimeUnit); } return true; }