public JToken registerJSONObject() { JObject stuff = new JObject(); var YearTermList = db.YearTerms.ToList(); var curYearTerm = new YearTerm(); foreach (YearTerm yearTerm in YearTermList) { if (yearTerm.IsDefault) { curYearTerm = yearTerm; break; } } var optionList = db.Options.ToList(); var validOptionsList = new List <Option>(); foreach (Option option in optionList) { if (option.IsActive) { validOptionsList.Add(option); } } var listUsers = appDb.Users.ToList(); stuff.Add("validOptionsList", JsonConvert.SerializeObject(validOptionsList)); stuff.Add("curYearTerm", JsonConvert.SerializeObject(curYearTerm)); stuff.Add("listUsersUserName", JsonConvert.SerializeObject(listUsers)); return(stuff); }
public ActionResult Edit([Bind(Include = "YearTermId,Year,Term,IsDefault")] YearTerm yearTerm) { var q = from y in db.YearTerms where y.IsDefault == true select y; var s = q.ToArray(); if (yearTerm.IsDefault == false && s.Length <= 1 && yearTerm.YearTermId == s[0].YearTermId) { ModelState.AddModelError("IsDefault", "There must be a default term"); } if (yearTerm.IsDefault == true) { for (var i = 0; i < s.Length; i++) { if (s[i].YearTermId != yearTerm.YearTermId) { s[i].IsDefault = false; } } } if (ModelState.IsValid) { try { db.Entry(yearTerm).State = EntityState.Modified; db.SaveChanges(); } catch (Exception) { } return(RedirectToAction("Index")); } return(View(yearTerm)); }
// GET: YearTerms/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } YearTerm yearTerm = db.YearTerms.Find(id); if (yearTerm == null) { return(HttpNotFound()); } List <SelectListItem> termList = new List <SelectListItem>(); var data = new[] { new SelectListItem { Value = "10", Text = "Winter" }, new SelectListItem { Value = "20", Text = "Spring/Summer" }, new SelectListItem { Value = "30", Text = "Fall" } }; termList = data.ToList(); ViewBag.Term = termList; return(View(yearTerm)); }
public async Task <ActionResult> Create(YearTerm yearTerm) { int check = yearTerm.term; if (check != 10 && check != 20 && check != 30) { ModelState.AddModelError(string.Empty, "Valid terms are 10, 20, and 30."); } if (ModelState.IsValid) { if (yearTerm.isDefault) { var query = from year in _context.YearTerms where year.isDefault == true select year; foreach (YearTerm year in query) { year.isDefault = false; } } _context.YearTerms.Add(yearTerm); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(yearTerm)); }
public async Task <ActionResult> Edit(int id, YearTerm yearTerm) { yearTerm.YearTermId = id; try { if (yearTerm.isDefault) { var query = from year in _context.YearTerms where year.isDefault == true && year.YearTermId != yearTerm.YearTermId select year; foreach (YearTerm year in query) { year.isDefault = false; } } _context.YearTerms.Attach(yearTerm); _context.Entry(yearTerm).State = EntityState.Modified; await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } catch (Exception) { ModelState.AddModelError(string.Empty, "Unable to save changes."); } return(View(yearTerm)); }
// GET: YearTerms/Edit/5 public ActionResult Edit(int?id) { var terms = db.YearTerms.OrderByDescending(x => x.Term).GroupBy(y => y.Term).Select(grp => grp.FirstOrDefault()) .ToList().Select(s => new { YearTermID = s.YearTermId, Term = s.Term, TermString = getTerm(s.Term) });; var years = db.YearTerms.OrderByDescending(x => x.Year).GroupBy(y => y.Year).Select(grp => grp.FirstOrDefault()) .ToList(); ViewBag.Years = new SelectList(years, "Year", "Year"); ViewBag.Terms = new SelectList(terms, "Term", "TermString"); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } YearTerm yearTerm = db.YearTerms.Find(id); if (yearTerm == null) { return(HttpNotFound()); } return(View(yearTerm)); }
public IHttpActionResult PutYearTerm(int id, YearTerm yearTerm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != yearTerm.YearTermId) { return(BadRequest()); } db.Entry(yearTerm).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!YearTermExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task<ActionResult> Create(YearTerm yearTerm) { int check = yearTerm.term; if (check!=10 && check!=20 && check!= 30) { ModelState.AddModelError(string.Empty, "Valid terms are 10, 20, and 30."); } if (ModelState.IsValid) { if (yearTerm.isDefault) { var query = from year in _context.YearTerms where year.isDefault == true select year; foreach (YearTerm year in query) { year.isDefault = false; } } _context.YearTerms.Add(yearTerm); await _context.SaveChangesAsync(); return RedirectToAction("Index"); } return View(yearTerm); }
public ActionResult Edit([Bind(Include = "YearTermId,Year,Term,IsDefault")] YearTerm yearTerm) { if (ModelState.IsValid) { if (yearTerm.IsDefault) { var c = (from x in db.YearTerms where x.IsDefault == true select x).First(); // do your stuff c.IsDefault = false; } else { return(RedirectToAction("Index")); } db.Entry(yearTerm).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(yearTerm)); }
public ActionResult Create([Bind(Include = "YearTermID,Year,Term,isDefault")] YearTerm yearTerm) { if (ModelState.IsValid) { // The user wants this term to be default, so make sure the others are set to false if (yearTerm.isDefault) { var terms = db.YearTerms.Where(yT => yT.isDefault == true); foreach (var term in terms) { term.isDefault = false; } } else { var defaultCount = db.YearTerms.Where( yT => yT.isDefault == true && yT.YearTermID != yearTerm.YearTermID).Count(); if (defaultCount <= 0) { yearTerm.isDefault = true; } } db.YearTerms.Add(yearTerm); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(yearTerm)); }
public ActionResult Create([Bind(Include = "YearTermId,Year,Term,IsDefault")] YearTerm yearTerm) { if (ModelState.IsValid) { db.YearTerms.Add(yearTerm); db.SaveChanges(); return(RedirectToAction("Index")); } List <SelectListItem> termList = new List <SelectListItem>(); var data = new[] { new SelectListItem { Value = "10", Text = "Winter" }, new SelectListItem { Value = "20", Text = "Spring/Summer" }, new SelectListItem { Value = "30", Text = "Fall" } }; termList = data.ToList(); ViewBag.Term = termList; return(View(yearTerm)); }
public ActionResult DeleteConfirmed(int id) { YearTerm yearTerm = db.YearTerms.Find(id); db.YearTerms.Remove(yearTerm); db.SaveChanges(); return(RedirectToAction("Index")); }
/* CREATE */ public static void Add_Year_Term(int Year_Term, string Day_Start, string Day_End) { var client = ConnectNeo4J.Connection(); var tmp = new YearTerm { year_term = Year_Term, day_start = Day_Start, day_end = Day_End, isDelete = false }; client.Cypher.Create("(:YearTerm {year_term})").WithParam("year_term", tmp).ExecuteWithoutResultsAsync().Wait(); }
public async Task <ActionResult> Edit(int id) { YearTerm yearTerm = await FindYearTermAsync(id); if (yearTerm == null) { Logger.LogInformation("Edit: Item not found {0}", id); return(HttpNotFound()); } return(View(yearTerm)); }
public IHttpActionResult GetYearTerm(int id) { YearTerm yearTerm = db.YearTerms.Find(id); if (yearTerm == null) { return(NotFound()); } return(Ok(yearTerm)); }
public ActionResult Create([Bind(Include = "YearTermId,Year,Term,IsDefault")] YearTerm yearTerm) { if (ModelState.IsValid) { db.YearTerms.Add(yearTerm); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(yearTerm)); }
public async Task <ActionResult> ConfirmDelete(int id, bool?retry) { YearTerm yearTerm = await FindYearTermAsync(id); if (yearTerm == null) { Logger.LogInformation("Delete: Item not found {0}", id); return(HttpNotFound()); } ViewBag.Retry = retry ?? false; return(View(yearTerm)); }
public IHttpActionResult PostYearTerm(YearTerm yearTerm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.YearTerms.Add(yearTerm); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = yearTerm.YearTermId }, yearTerm)); }
private async void Page_Loading(FrameworkElement sender, object args) { var obj = App.Current as App; StudentNumberBox.Text = obj.studentNumber; OptionManager.http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", obj.AccessToken); await OptionManager.GetActiveOptions(Options); YearTermManager.http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", obj.AccessToken); defaultYearTerm = await YearTermManager.DefaultYearTerm(defaultYearTerm); }
public ActionResult Details(int id) { YearTerm yearTerm = _context.YearTerms .Where(b => b.YearTermId == id) .FirstOrDefault(); if (yearTerm == null) { Logger.LogInformation("Details: Item not found {0}", id); return(HttpNotFound()); } return(View(yearTerm)); }
public IHttpActionResult DeleteYearTerm(int id) { YearTerm yearTerm = db.YearTerms.Find(id); if (yearTerm == null) { return(NotFound()); } db.YearTerms.Remove(yearTerm); db.SaveChanges(); return(Ok(yearTerm)); }
// GET: YearTerms/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } YearTerm yearTerm = db.YearTerms.Find(id); if (yearTerm == null) { return(HttpNotFound()); } return(View(yearTerm)); }
public async Task <ActionResult> Delete(int id) { try { YearTerm yearTerm = await FindYearTermAsync(id); _context.YearTerms.Remove(yearTerm); await _context.SaveChangesAsync(); } catch (Exception ex) { return(RedirectToAction("Delete", new { id = id, retry = true })); } return(RedirectToAction("Index")); }
private async void EditYearTerm_Click(object sender, RoutedEventArgs e) { int id; if (YearTermIdWillBeEdited.Text != "" && Int32.TryParse(YearTermIdWillBeEdited.Text, out id)) { int year = Int32.Parse((string)YearWillBeEdited.SelectionBoxItem); int term = Int32.Parse((string)TermWillBeEdited.SelectionBoxItem); bool isDefault = ((string)YearTermIsDefaultWillBeEdited.SelectionBoxItem == "Yes") ? true : false; var obj = new YearTerm() { YearTermId = id, Year = year, Term = term, IsDefault = isDefault }; await YearTermManager.EditYearTerm(new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json"), obj, YearTerms); } }
public ActionResult DeleteConfirmed(int id) { YearTerm yearTerm = db.YearTerms.Find(id); db.YearTerms.Remove(yearTerm); db.SaveChanges(); // Make the last yearTerm set to default // If the current default is deleted if (yearTerm.isDefault && db.YearTerms.Count() > 0) { int newYearTerm = db.YearTerms.Max(c => c.YearTermID); db.YearTerms.Find(newYearTerm).isDefault = true; } db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "YearTermId,Year,Term,IsDefault")] YearTerm yearTerm) { if (ModelState.IsValid) { if (yearTerm.IsDefault) { var c = (from x in db.YearTerms where x.IsDefault == true select x).First(); // do your stuff c.IsDefault = false; } //else //{ // return RedirectToAction("Index"); //} db.Entry(yearTerm).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } List <SelectListItem> termList = new List <SelectListItem>(); var data = new[] { new SelectListItem { Value = "10", Text = "Winter" }, new SelectListItem { Value = "20", Text = "Spring/Summer" }, new SelectListItem { Value = "30", Text = "Fall" } }; termList = data.ToList(); ViewBag.Term = termList; return(View(yearTerm)); }
public ActionResult Create([Bind(Include = "YearTermId,Year,Term,IsDefault")] YearTerm yearTerm) { var yearterms = db.YearTerms; if (ModelState.IsValid) { if (yearTerm.IsDefault) { foreach (var y in yearterms) { if (y.IsDefault && y.YearTermId != yearTerm.YearTermId) { y.IsDefault = false; } } } db.YearTerms.Add(yearTerm); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(yearTerm)); }
public async Task<ActionResult> Edit(int id, YearTerm yearTerm) { yearTerm.YearTermId = id; try { if (yearTerm.isDefault) { var query = from year in _context.YearTerms where year.isDefault == true && year.YearTermId != yearTerm.YearTermId select year; foreach (YearTerm year in query) { year.isDefault = false; } } _context.YearTerms.Attach(yearTerm); _context.Entry(yearTerm).State = EntityState.Modified; await _context.SaveChangesAsync(); return RedirectToAction("Index"); } catch (Exception) { ModelState.AddModelError(string.Empty, "Unable to save changes."); } return View(yearTerm); }