// PUT api/Note/5 public HttpResponseMessage PutNote(Note note) { if (ModelState.IsValid) { //db.Entry(Note).State = EntityState.Modified; //note.GroupReference.Attach(db.Groups.Where(gw => gw.ID == note.GroupID).First()); //note.GroupReference.Load(); //db.Notes.Attach(note); //note.GroupReference.Load(); //Note existingNote = db.Notes.Find(note.ID); //db.Entry(existingNote).CurrentValues.SetValues(note); Note existingNote = db.Notes.Single(nw => nw.ID == note.ID); db.ApplyCurrentValues("Notes", note); //db.ObjectStateManager.ChangeObjectState(note, EntityState.Modified); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
// PUT api/Group/5 public HttpResponseMessage PutGroup(int id, Group group) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != group.ID) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } if (group.TeamID == 0) { group.TeamID = null; } string name = group.Name; db.Groups.Attach(group); db.ObjectStateManager.ChangeObjectState(group, EntityState.Modified); try { db.SaveChanges(); Utilities.Write_Admin_Log(db, Utilities.App_Label.FoxTick, typeof(Group), Utilities.Action_Flag.CHANGE, group.ID.ToString(), group.Name, "Updated Group Name from \"" + name + "\"", true); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
// PUT api/Sport/5 public HttpResponseMessage PutSport(int id, Sport sport) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != sport.ID) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.Sports.Attach(sport); db.ObjectStateManager.ChangeObjectState(sport, EntityState.Modified); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
// PUT api/GameStatus/5 public HttpResponseMessage PutGameStatus(byte id, GameStatus gamestatus) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != gamestatus.ID) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.GameStatuses.Attach(gamestatus); db.ObjectStateManager.ChangeObjectState(gamestatus, EntityState.Modified); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
// PUT api/GroupAnimationType/5 public HttpResponseMessage PutGroupAnimationType(int id, GroupAnimationType groupanimationtype) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != groupanimationtype.ID) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.GroupAnimationTypes.Attach(groupanimationtype); db.ObjectStateManager.ChangeObjectState(groupanimationtype, EntityState.Modified); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public ActionResult Create(Group group) { if (ModelState.IsValid) { db.Groups.AddObject(group); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(group)); }
//public DataSourceResult Get(string id, [ModelBinder(typeof(Ticker.ModelBinders.DataSourceRequestModelBinder))] DataSourceRequest request) //{ // var suppress = db.suppressgames.Where(gw => gw.CorrelationID == id); // if (suppress == null) // { // throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); // } // return suppress.AsEnumerable().ToDataSourceResult(request, g => new // { // g.id, // g.LeagueCode, // g.ClientID, // g.CorrelationID // }); ; //} // GET: api/Suppress/5 //public IHttpActionResult Get(string correlationid) //{ // FoxTickerEntities db = new FoxTickerEntities(); // bool status = false; // if(db.suppressgames.Where(a=>a.CorrelationID== correlationid).Any()) // { // status = true; // } // return Json(status); //} // POST: api/Suppress public HttpResponseMessage Post(string id, string league, int client) { FoxTickerEntities db = new FoxTickerEntities(); // suppressgame Suppress = db.suppressgames.Where(a => a.CorrelationID == id && a.ClientID == client && a.LeagueCode == league).FirstOrDefault(); suppressgame suppress = new suppressgame(); suppress.ClientID = client; suppress.CorrelationID = id; suppress.LeagueCode = league; db.suppressgames.AddObject(suppress); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK, suppress)); }
// PUT api/BreakingNewsTypes/5 public HttpResponseMessage PutBreakingNewsType(int id, BreakingNewsType BreakingNewsType) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != BreakingNewsType.ID) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.BreakingNewsTypes.Attach(BreakingNewsType); db.ObjectStateManager.ChangeObjectState(BreakingNewsType, EntityState.Modified); try { db.SaveChanges(); Utilities.BreakingNewsTypesLoad(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); /*if (ModelState.IsValid && id == BreakingNewsType.BreakingNewsTypeID) * { * //db.Entry(Playlist).State = EntityState.Modified; * * try * { * db.SaveChanges(); * } * catch (DbUpdateConcurrencyException) * { * return Request.CreateResponse(HttpStatusCode.NotFound); * } * * return Request.CreateResponse(HttpStatusCode.OK); * } * else * { * return Request.CreateResponse(HttpStatusCode.BadRequest); * }*/ }
// PUT api/PlaylistDetail/5 public HttpResponseMessage PutPlaylistDetail(int id, PlaylistDetail PlaylistDetail) { if (ModelState.IsValid && id == PlaylistDetail.ID) { PlaylistDetail.SDMLeagueCode = db.PlaylistDetails.Where(p => p.ID == id).Select(p => p.SDMLeagueCode).FirstOrDefault(); //db.Entry(PlaylistDetail).State = EntityState.Modified; db.PlaylistDetails.Attach(PlaylistDetail); db.ObjectStateManager.ChangeObjectState(PlaylistDetail, EntityState.Modified); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public ActionResult Edit(Game Game) { if (ModelState.IsValid) { db.Games.Attach(Game); Game.LastUpdated = DateTime.Now; db.ObjectStateManager.ChangeObjectState(Game, EntityState.Modified); db.SaveChanges(); return(Json(new { success = true }, "text/html")); //JavaScriptResult result = new JavaScriptResult(); //result.Script = "ClosePopupandRefresh('#winGameEditor');"; //return Json("ClosePopupandRefresh('#winGameEditor');"); //return View(); //return RedirectToAction("Index"); } return(Json(new { error = "Can't Save Game." }, "text/html")); //return View(Game); }
// POST api/Client public HttpResponseMessage PostClientShare(int id, Client client) { if (ModelState.IsValid) { Client clientShareTo = db.Clients.Single(c => c.ID == id); clientShareTo.ClientsTo.Add(db.Clients.Single(c => c.ID == client.ID)); db.Clients.Attach(clientShareTo); db.ObjectStateManager.ChangeObjectState(clientShareTo, EntityState.Modified); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, client); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = client.ID })); return(response); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
// PUT api/Game/5 public HttpResponseMessage PutGame(int id, Game Game) { if (ModelState.IsValid && id == Game.ID) { //db.Entry(Game).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
// POST api/leaguessettings public dynamic Post([FromBody] LeaguesSetting value) { // db.LeaguesSettings.Add(value); if (value.LeagueCode != null) { string ClientID = Request.Headers.GetValues("ClientID").FirstOrDefault().Replace('{', ' ').Replace('}', ' ').Trim(); value.ClientID = Convert.ToInt32(ClientID); bool exists = db.LeaguesSettings.Any(l => l.ClientID == value.ClientID && l.LeagueCode == value.LeagueCode && l.SettingsID == value.SettingsID && l.OptionsID == value.OptionsID); if (!exists) { db.LeaguesSettings.AddObject(value); try { db.SaveChanges(); } catch (Exception e) { return("FAILURE"); } var retvalue = new LeaguesSetting(); retvalue.Id = value.Id; retvalue.ClientID = value.ClientID; retvalue.LeagueCode = value.LeagueCode; retvalue.SettingsID = value.SettingsID; retvalue.OptionsID = value.OptionsID; return(retvalue); } else { return("Exists"); } } else { return("Error"); } }
// PUT api/Default1/5 public HttpResponseMessage PutNote(int id, Note note) { if (ModelState.IsValid && id == note.ID) { db.Notes.Attach(note); db.ObjectStateManager.ChangeObjectState(note, EntityState.Modified); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
// PUT api/Playlist/5 public HttpResponseMessage PutPlaylist(int id, Playlist Playlist) { if (ModelState.IsValid && id == Playlist.ID) { //db.Entry(Playlist).State = EntityState.Modified; Playlist play = db.Playlists.Single(p => p.ID == id); string existingName = play.Name; play.Name = Playlist.Name; //they can only change the name play.PlaylistTypeID = Playlist.PlaylistTypeID; if (Playlist.ScoreboardID == 0) { Playlist.ScoreboardID = null; } play.ScoreboardID = Playlist.ScoreboardID; try { db.SaveChanges(); string clientName = db.Clients.Single(c => c.ID == Playlist.ClientID).Abbreviation; string msg = String.Format("Updated Playlist in \"{0}\"<br />(Existing) Name: \"{1}\"<br />(Updated) Name: \"{2}\"", clientName, existingName, play.Name); Utilities.Write_Admin_Log(db, Utilities.App_Label.FoxTick, typeof(Playlist), Utilities.Action_Flag.CHANGE, id.ToString(), play.Name, msg, true); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
// POST: api/Task public HttpResponseMessage Post(string name, string password) { FoxTickerEntities db = new FoxTickerEntities(); Mytask task = new Mytask(); task.Name = name; task.Password = password; db.Mytasks.AddObject(task); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK, task)); }
// PUT api/Note/5 public HttpResponseMessage PutNote(Note note) { if (ModelState.IsValid) { //db.Entry(Note).State = EntityState.Modified; //note.GroupReference.Attach(db.Groups.Where(gw => gw.ID == note.GroupID).First()); //note.GroupReference.Load(); //db.Notes.Attach(note); //note.GroupReference.Load(); //Note existingNote = db.Notes.Find(note.ID); Note existingNote = db.Notes.Single(nw => nw.ID == note.ID); if (note.TeamID == null) { note.TeamID = -1; } string groupName = db.Groups.Single(g => g.ID == note.GroupID).Name; //************ Following lines were commented for SDM Integration -- Start *********************// //string oldTeam = existingNote.TeamID == null ? "" : existingNote.TeamID != -1 ? db.Teams.Single(t => t.ID == existingNote.TeamID).NickName : ""; //string newTeam = note.TeamID != -1 ? db.Teams.Single(t => t.ID == note.TeamID).NickName : ""; //************ Following lines were commented for SDM Integration -- End *********************// string oldTeam = ""; string newTeam = ""; string msg = "Updated Note in \"" + groupName + "\"<br />(Existing) Team: \"" + oldTeam + "\" - Header: \"" + existingNote.Header + "\" - Note: \"" + existingNote.Note1 + "\"<br />(Updated) Team: \"" + newTeam + "\" - Header: \"" + note.Header + "\" - Note: \"" + note.Note1 + "\""; //1st remove html tags for plain note, then convert to vz format note.NoteColor = HttpUtility.UrlDecode(note.NoteColor); note.NoteColor = WebUtility.HtmlDecode(note.NoteColor); note.Note1 = WebUtility.HtmlDecode(note.NoteColor); note.NoteColor = Utilities.ConvertFromHTML(note.NoteColor); // note.Note1 = Utilities.RemoveHTML(System.Web.HttpUtility.HtmlDecode(note.NoteColor)); // note.NoteColor = Utilities.ConvertFromHTML(System.Web.HttpUtility.HtmlDecode(note.NoteColor)); //clean note.Note1 = Regex.Replace(note.Note1, @"[^\u0000-\u02FF]", string.Empty); note.NoteColor = Regex.Replace(note.NoteColor, @"[^\u0000-\u02FF]", string.Empty); note.Note1 = note.Note1.Replace((char)0xA0, ' '); note.NoteColor = note.NoteColor.Replace((char)0xA0, ' '); note.Note1 = Regex.Replace(note.Note1, @"<[^>]*>", string.Empty); note.NoteColor = Regex.Replace(note.NoteColor, @"<[^>]*>", string.Empty); //note.Note1 = Regex.Replace(note.Note1, @"\&[A-Za-z]*?;", string.Empty); //note.NoteColor = Regex.Replace(note.NoteColor, @"\&[A-Za-z]*?;", string.Empty); note.NoteColor = note.NoteColor.Replace("@@", "<"); note.NoteColor = note.NoteColor.Replace("##", ">"); existingNote.Header = note.Header; existingNote.NoteColor = note.NoteColor; string oldNote = existingNote.Note1; existingNote.Note1 = note.Note1; existingNote.TeamID = note.TeamID; existingNote.LastUpdated = DateTime.Now; // existingNote.SortOrder = note.SortOrder; bool reOrder = false; bool first = false; if (existingNote.SortOrder != note.SortOrder) { if (note.SortOrder == 0 || note.SortOrder == 1) { first = true; } existingNote.SortOrder = note.SortOrder; reOrder = true; } //List<Note> lnotes = db.Notes.Where(n => n.GroupID == note.GroupID).OrderBy(o => o.SortOrder).ToList(); //for (int i = 0; i < lnotes.Count; i++) //{ // if (existingNote.SortOrder>=note.SortOrder) // { // lnotes[i].SortOrder = lnotes[i].SortOrder + 1; // } //} //db.ApplyCurrentValues("Notes",note); //db.ObjectStateManager.ChangeObjectState(note, EntityState.Modified); try { db.SaveChanges(); Utilities.Write_Admin_Log(db, Utilities.App_Label.FoxTick, typeof(Note), Utilities.Action_Flag.CHANGE, note.ID.ToString(), note.Note1, msg, true); if (reOrder) { List <Note> lgameNotes = new List <Note>(); if (first) { lgameNotes.Add(existingNote); lgameNotes.AddRange(db.Notes.Where(le => le.GroupID == existingNote.GroupID && le.ID != existingNote.ID).OrderBy(ob => ob.SortOrder).ToList()); } else { lgameNotes.AddRange(db.Notes.Where(le => le.GroupID == existingNote.GroupID).OrderBy(ob => ob.SortOrder).ToList()); lgameNotes.ForEach(ln => ln.LastUpdated = DateTime.Now); } } } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
// PUT api/BreakingNews/5 public HttpResponseMessage PutBreakingNew(int id, BreakingNew BreakingNew) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != BreakingNew.ID) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } updateSortOrder(id, BreakingNew.SortOrder); BreakingNew.Note = BreakingNew.Note.Replace((char)0xA0, ' '); BreakingNew.LastUpdated = DateTime.Now; string BreakingNewsType = db.BreakingNewsTypes.Where(b => b.ID == BreakingNew.BreakingNewsTypeID && b.Enabled == true).Select(b => b.Description).FirstOrDefault(); //**** Breaking News Alert **** -- Start ****// if (BreakingNewsType.ToLower().Trim() == "breaking news") { BreakingNew.ColorHex = "#c71d1d"; BreakingNew.IntroMovie = "BreakingNewsIntro.mov"; BreakingNew.IntroText = "BREAKING NEWS"; BreakingNew.TopicMovie = "BreakingNewsHeaderBackground.mov"; BreakingNew.TopicText = ""; BreakingNew.HeaderMovie = "BreakingNewsSubHeaderBackground.mov"; } //**** Breaking News **** -- End ****// //**** Program Alert **** -- Start ****// if (BreakingNewsType.ToLower().Trim() == "program alert") { BreakingNew.ColorHex = "#2828c8"; BreakingNew.IntroMovie = "ProgramAlertIntroMotion.mov"; BreakingNew.IntroText = "PROGRAM ALERT"; BreakingNew.TopicMovie = "ProgramAlertHeader.mov"; BreakingNew.TopicText = ""; BreakingNew.HeaderMovie = "ProgramAlertSubHeader.mov"; } //**** Program Alert **** -- End ****// db.BreakingNews.Attach(BreakingNew); db.ObjectStateManager.ChangeObjectState(BreakingNew, EntityState.Modified); try { db.SaveChanges(); Utilities.Write_Admin_Log(db, Utilities.App_Label.FoxTick, typeof(Group), Utilities.Action_Flag.CHANGE, BreakingNew.ID.ToString(), BreakingNew.Note, "Updated Alert from \"" + BreakingNew.HeaderText + "\" on \"" + BreakingNew.IntroText + "\"", true); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); /*if (ModelState.IsValid && id == BreakingNew.BreakingNewID) * { * //db.Entry(Playlist).State = EntityState.Modified; * * try * { * db.SaveChanges(); * } * catch (DbUpdateConcurrencyException) * { * return Request.CreateResponse(HttpStatusCode.NotFound); * } * * return Request.CreateResponse(HttpStatusCode.OK); * } * else * { * return Request.CreateResponse(HttpStatusCode.BadRequest); * }*/ }
// PUT api/Note/5 public HttpResponseMessage PutGameHiveNote(GameHiveNote note) { if (ModelState.IsValid) { //db.Entry(Note).State = EntityState.Modified; //note.GroupReference.Attach(db.Groups.Where(gw => gw.ID == note.GroupID).First()); //note.GroupReference.Load(); //db.GameHiveNotes.Attach(note); //note.GroupReference.Load(); //Note existingNote = db.GameHiveNotes.Find(note.ID); GameHiveNote existingNote = db.GameHiveNotes.Single(nw => nw.ID == note.ID); //updare sort order if (existingNote.SortOrder != note.SortOrder) { PutGameHiveNote(note.ID, note.HiveID, "GameHiveNote", Convert.ToInt32(note.SortOrder)); //new sort order } //1st remove html tags for plain note, then convert to vz format note.NoteColor = HttpUtility.UrlDecode(note.NoteColor); note.NoteColor = WebUtility.HtmlDecode(note.NoteColor); note.Note = WebUtility.HtmlDecode(note.NoteColor); note.NoteColor = Utilities.ConvertFromHTML(note.NoteColor); existingNote.Header = note.Header; existingNote.NoteColor = note.NoteColor; existingNote.Note = note.Note; if (note.TeamID > 0) { // note.SportID = db.Teams.Where(t => t.ID == note.TeamID).SingleOrDefault().SportID; existingNote.SportID = note.SportID; // existingNote.LeagueCode = db.Sports.Where(t => t.ID == note.SportID).SingleOrDefault().ShortDisplay; existingNote.LeagueCode = note.LeagueCode; existingNote.TeamID = note.TeamID; // existingNote.TeamCode = db.Teams.Where(t => t.ID == note.TeamID).SingleOrDefault().Abbreviation; existingNote.TeamCode = note.TeamCode; } else { existingNote.SportID = null; existingNote.LeagueCode = null; existingNote.TeamID = note.TeamID; existingNote.TeamCode = null; } existingNote.LastUpdated = DateTime.Now; existingNote.SortOrder = note.SortOrder; //db.ApplyCurrentValues("GameHiveNotes",note); //db.ObjectStateManager.ChangeObjectState(note, EntityState.Modified); //clean existingNote.Note = Regex.Replace(existingNote.Note, @"[^\u0000-\u02FF]", string.Empty); existingNote.NoteColor = Regex.Replace(existingNote.NoteColor, @"[^\u0000-\u02FF]", string.Empty); existingNote.Note = existingNote.Note.Replace((char)0xA0, ' '); existingNote.NoteColor = existingNote.NoteColor.Replace((char)0xA0, ' '); //existingNote.NoteColor = Regex.Replace(existingNote.NoteColor, @"<.*?>", string.Empty); existingNote.Note = Regex.Replace(existingNote.Note, @"<[^>]*>", string.Empty); existingNote.NoteColor = Regex.Replace(existingNote.NoteColor, @"<[^>]*>", string.Empty); // existingNote.Note = Regex.Replace(existingNote.Note, @"\&.*?;", string.Empty); // existingNote.NoteColor = Regex.Replace(existingNote.NoteColor, @"\&.*?;", string.Empty); try { db.SaveChanges(); ReSortNotes(note); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
// PUT api/Users/5 public HttpResponseMessage PutUser(int id, User user) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != user.UserID) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } User existingUser = db.Users.Single(u => u.UserID == id); string admin = existingUser.Admin == true ? "true" : "false"; string newAdmin = user.Admin == true ? "true" : "false"; string clientName = db.Clients.Single(c => c.ID == user.ClientID).Abbreviation; string msg = "Updated user in \"" + clientName + "\"<br />(Existing) Username: \"" + existingUser.Username + "\" - First Name: \"" + existingUser.FirstName + "\" - Last Name: \"" + existingUser.LastName + "\" - Admin: " + admin + "<br />(Updated) Username: \"" + user.Username + "\" - First Name: \"" + user.FirstName + "\" - Last Name: \"" + user.LastName + "\" - Admin: \"" + newAdmin + "\""; existingUser.Username = user.Username; existingUser.FirstName = user.FirstName; existingUser.LastName = user.LastName; existingUser.Admin = user.Admin; /** * db.Users.Attach(user); * db.ObjectStateManager.ChangeObjectState(user, EntityState.Modified); **/ try { db.SaveChanges(); Utilities.Write_Admin_Log(db, Utilities.App_Label.FoxTick, typeof(User), Utilities.Action_Flag.CHANGE, user.UserID.ToString(), user.Username, msg, true); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); /*if (ModelState.IsValid && id == user.UserID) * { * //db.Entry(Playlist).State = EntityState.Modified; * * try * { * db.SaveChanges(); * } * catch (DbUpdateConcurrencyException) * { * return Request.CreateResponse(HttpStatusCode.NotFound); * } * * return Request.CreateResponse(HttpStatusCode.OK); * } * else * { * return Request.CreateResponse(HttpStatusCode.BadRequest); * }*/ }
// PUT api/Note/5 public HttpResponseMessage PutGameNote(GameNote note) { if (ModelState.IsValid) { //db.Entry(Note).State = EntityState.Modified; //note.GroupReference.Attach(db.Groups.Where(gw => gw.ID == note.GroupID).First()); //note.GroupReference.Load(); //db.GameNotes.Attach(note); //note.GroupReference.Load(); //Note existingNote = db.GameNotes.Find(note.ID); GameNote existingNote = db.GameNotes.Single(nw => nw.ID == note.ID); string oldNote = existingNote.Note; bool reOrder = false; //1st remove html tags for plain note, then convert to vz format note.Note = Utilities.RemoveHTML(note.NoteColor); note.NoteColor = Utilities.ConvertFromHTML(note.NoteColor); existingNote.Header = note.Header; existingNote.NoteColor = note.NoteColor; existingNote.Note = note.Note; existingNote.TeamID = note.TeamID; bool first = false; if (existingNote.SortOrder != note.SortOrder) { if (note.SortOrder == 0 || note.SortOrder == 1) { first = true; } reOrder = true; } existingNote.SortOrder = note.SortOrder; existingNote.LastUpdated = DateTime.Now; //db.ApplyCurrentValues("GameNotes",note); //db.ObjectStateManager.ChangeObjectState(note, EntityState.Modified); try { db.SaveChanges(); Utilities.Write_Admin_Log(db, Utilities.App_Label.FoxTick, typeof(GameNote), Utilities.Action_Flag.CHANGE, note.ID.ToString(), note.Note, oldNote, true); if (reOrder) { List <GameNote> lgameGameNotes = new List <GameNote>(); if (first) { lgameGameNotes.Add(existingNote); lgameGameNotes.AddRange(db.GameNotes.Where(le => le.GameID == existingNote.GameID && le.ID != existingNote.ID).OrderBy(ob => ob.SortOrder).ToList()); } else { lgameGameNotes.AddRange(db.GameNotes.Where(le => le.GameID == existingNote.GameID).OrderBy(ob => ob.SortOrder).ToList()); } for (int i = 0; i < lgameGameNotes.Count; i++) { lgameGameNotes[i].SortOrder = i + 1; } lgameGameNotes.ForEach(ln => ln.LastUpdated = DateTime.Now); db.SaveChanges(); } } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }