private void InsertOrUpdateDeviceStudent(List <Device> devices, Student student) { // can only be one device atm, so hardcoding it... Device newDevice = devices[0]; try { Device d = db.devices.First(x => x.id.Equals(newDevice.id)); if (d != null) { d.Student = student; d.deviceType = newDevice.deviceType; d.token = newDevice.token; db.Entry(d).State = EntityState.Modified; db.SaveChanges(); } else { newDevice.Student = student; db.devices.Add(newDevice); db.SaveChanges(); } } catch { newDevice.Student = student; db.devices.Add(newDevice); db.SaveChanges(); } }
public ActionResult Create([Bind(Include = "id,name,adress,url,facebook,linkedIn,description,logo")] Company company) { if (ModelState.IsValid) { db.companies.Add(company); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(company)); }
/// <summary> /// Creates a new user based on a external access token. /// </summary> /// <param name="provider"></param> /// <param name="verifiedAccessToken"></param> /// <param name="externalAccessToken"></param> /// <returns></returns> private async Task <IHttpActionResult> CreateNewUserFromExternalAccesToken(string provider, ParsedExternalAccessToken verifiedAccessToken, string externalAccessToken) { RegisterExternalBindingModel model = new RegisterExternalBindingModel() { UserName = verifiedAccessToken.email, // this is null Provider = provider, ExternalAccessToken = externalAccessToken }; Student student = new Student(); student.username = verifiedAccessToken.email; student.email = verifiedAccessToken.email; KompetansetorgetServerContext db = new KompetansetorgetServerContext(); db.students.Add(student); db.SaveChanges(); return(await RegisterExternal(model)); }