// PUT api/Training/5 public IHttpActionResult PutTraining(Training training) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //if (id != training.Id) //{ // return BadRequest(); //} db.Entry(training).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { //if (!TrainingExists(id)) //{ // return NotFound(); //} //else //{ // throw; //} } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create(Trainer trainer) { if (ModelState.IsValid) { context.Trainers.Add(trainer); context.SaveChanges(); return(RedirectToAction("Index")); } return(View(trainer)); }
public IHttpActionResult PostTrainingCategory(TrainingCategory trainingCategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.TrainingCategories.Add(trainingCategory); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = trainingCategory.Id }, trainingCategory)); }
public ActionResult Create(Training training) { if (ModelState.IsValid) { context.Trainings.Add(training); context.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PossibleTrainers = context.Trainers; return(View(training)); }
public void AddNewContestant() { try { _contestant.TournamentId = TournamentId; //TODO: VALIDATION var queryName = (from c in _context.Contestants where c.FirstName.Equals(_contestant.FirstName) && c.LastName.Equals(_contestant.LastName) select c).ToList(); if (queryName.Count >= 1) { OutputMessage = "A contestant with this name already exists in the database!"; } else { _context.Contestants.AddOrUpdate(_contestant); _context.SaveChanges(); OutputMessage += "\nSuccessfully added a new contestant to the database!\n" + _contestant.GetContestantDataString(); } MessageBox.Show(OutputMessage); } catch (Exception e) { OutputMessage += "\nERROR adding new contestant to database!\nErrormessage = " + e.Message + "\n" + _contestant.GetContestantDataString(); MessageBox.Show(OutputMessage); } ClearData(); RaisePropertyChangedEvent("Contestant"); }
public IHttpActionResult PostTrainer(Trainer objOfTrainer) { objOfTrainer.ModificationDate = DateTime.Now; objOfTrainer.CreateDate = DateTime.Now; objOfTrainer.ModifiedBy = "Foysal"; objOfTrainer.CreatedBy = "Mahedee"; objOfTrainer.IsActive = true; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Trainers.Add(objOfTrainer); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = objOfTrainer.Id }, objOfTrainer)); }
public void AddNewTournament() { try { TMSContext context = new TMSContext(); //validate ID var queryID = (from t in context.Tournaments where t.TournamentId == _tournament.TournamentId select t) .ToList(); //TODO: VALIDATION if (queryID.Count >= 1) { OutputMessage = "A tournament with this ID already exists in the database!"; MessageBox.Show(OutputMessage, "ERROR", MessageBoxButtons.OK); } var queryName = (from t in context.Tournaments where t.Name == _tournament.Name select t).ToList(); if (queryName.Count >= 1) { OutputMessage = "A tournament with this name already exists in the database!"; MessageBox.Show(OutputMessage, "ERROR", MessageBoxButtons.OK); } else { context.Tournaments.AddOrUpdate(_tournament); context.SaveChanges(); OutputMessage += "\nSuccessfully added a new tournament to the database!\n"; OutputMessage += _tournament.GetTournamentDataString(); MessageBox.Show(OutputMessage, "SUCCESS"); } } catch (Exception e) { OutputMessage += "\nERROR adding new tournament to database!\nErrormessage = " + e.Message + "\n"; OutputMessage += _tournament.GetTournamentDataString(); MessageBox.Show(OutputMessage, "ERROR"); } CleanUp(); Messenger.Default.Send(new ChangeView() { ViewName = "Tournaments" }); }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return(RedirectToAction("Manage")); } if (ModelState.IsValid) { // Insert a new user into the database using (TMSContext db = new TMSContext()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); db.SaveChanges(); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public void AddNewContestant() { try { TMSContext context = new TMSContext(); //TODO: VALIDATION context.Contestants.AddOrUpdate(_contestant); context.SaveChanges(); OutputMessage += "\nSuccessfully added a new contestant to the database!\n"; RaisePropertyChangedEvent("OutputMessage"); OutputMessage += _contestant.GetContestantDataString(); RaisePropertyChangedEvent("OutputMessage"); } catch (Exception e) { OutputMessage += "\nERROR adding new contestant to database!\nErrormessage = " + e.Message + "\n"; RaisePropertyChangedEvent("OutputMessage"); OutputMessage += _contestant.GetContestantDataString(); RaisePropertyChangedEvent("OutputMessage"); } }
public async Task SaveListings(TMSContext context) { foreach (var listing in Listings) { var oldListing = context.Listings.FirstOrDefault(x => x.CRN == listing.CRN && x.Term.TermID == listing.Term.TermID); if (oldListing != null && !oldListing.IsEqual(listing)) { oldListing.Subject = listing.Subject; oldListing.CourseNumber = listing.CourseNumber; oldListing.InstructionType = listing.InstructionType; oldListing.InstructionMethod = listing.InstructionMethod; oldListing.Section = listing.Section; oldListing.MaxEnroll = listing.MaxEnroll; oldListing.Enroll = listing.Enroll; oldListing.CourseTitle = listing.CourseTitle; oldListing.Times = listing.Times; oldListing.Instructor = listing.Instructor; oldListing.ModifiedDate = DateTime.Now; Updated += 1; } else { New += 1; context.Add(listing); } } foreach (var term in Terms) { if (context.Terms.Any(x => x.LookupLabel == term.LookupLabel)) { var oldTerm = context.Terms.First(x => x.LookupLabel == term.LookupLabel); context.Entry(oldTerm).CurrentValues.SetValues(term); } else { context.Add(term); } } context.SaveChanges(); }
public void AddWeightClass() { try { _context.WeightClasses.Add(_weightClass); _context.SaveChanges(); MessageBox.Show("Successfully added new weight class to database!\n" + "Name = " + _weightClass.WeightClassName + "\nID = " + _weightClass.WeightClassId + "\nAgeClass ID = " + _weightClass.AgeClassId + "\nMinimum weight = " + _weightClass.MinWeight + "\nMaximum weight = " + _weightClass.MaxWeight ); Messenger.Default.Send(new ChangeView() { ViewName = "CurrentTournament" }); } catch (Exception e) { MessageBox.Show("ERROR adding weightclass to database!\n" + e.Message); ClearData(); } }
public void Save() { _context.SaveChanges(); }
public int Create(TEntity entity) { _dbSet.Add(entity); return(_context.SaveChanges()); }