// PUT: api/Preference/5 public void Put([FromBody]object value) //int id, { JObject JPreference = JObject.FromObject(value, new Newtonsoft.Json.JsonSerializer()); Preference preference = new Preference(); foreach (JProperty app in JPreference.Properties()) { if (app.Name == "ReadingSpeed") preference.ReadingSpeed = (int)app.Value; if (app.Name == "FontSize") preference.FontSize = (int)app.Value; if (app.Name == "ScreenWidth") preference.ScreenWidth = (int)app.Value; if (app.Name == "ScreenHeight") preference.ScreenHeight = (int)app.Value; if (app.Name == "ScriptId") preference.ScriptId = (int)app.Value; if (app.Name == "ReaderId") preference.ReaderId = (int)app.Value; if (app.Name == "LastSectionId") preference.LastSectionId = (int)app.Value; } Reader currentActor = actorService.Get(actor => actor.Id == preference.ReaderId); currentActor.LastScriptId = preference.ScriptId; actorService.Put(currentActor); preferenceService.Put(preference); }
public void Post(Preference preference) { using (IPrompterDbContext context = _dbContextFactory.Create()) { context.Preferences.Add(preference); context.SaveChanges(); } }
public void Put(Preference preference) { using (IPrompterDbContext context = _dbContextFactory.Create()) { preference.Id = 0; Preference pref = this.Get(temp => preference.ReaderId == temp.ReaderId && preference.ScriptId == temp.ScriptId); if (pref == null) this.Post(preference); else { preference.Id = pref.Id; context.Entry(preference).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } }