public static PTMessage AddMessage(PTMessage message, byte[] imageData) { try { // add the message to the db, set message.ID, and return the message //TODO: default return values //TODO: handle video... using (PTLinkDatabaseDataContext db = new PTLinkDatabaseDataContext()) { Message dbMessage = new Message(); dbMessage.ContentTypeId = (from c in db.ContentTypes where c.Name == message.type select c.Id).SingleOrDefault(); dbMessage.ExerciseId = message.exerciseID; dbMessage.PersonId = message.senderID; dbMessage.ProtocolId = message.protocolID; dbMessage.Timestamp = (long)message.timestamp; if (imageData != null) { //TODO: handle images and video and such dbMessage.Value = message.imageName; } else { dbMessage.Value = message.text; } db.Messages.InsertOnSubmit(dbMessage); db.SubmitChanges(); message.ID = dbMessage.Id; } return message; } catch { return null; } }
public static PTExerciseProgress AddProgress(PTExerciseProgress progress) { try { //TODO: method not going to work without an exercise id using (PTLinkDatabaseDataContext db = new PTLinkDatabaseDataContext()) { ExerciseProgressXref dbProgress = new ExerciseProgressXref(); dbProgress.Timestamp = (long)progress.timestamp; dbProgress.ExerciseId = progress.exerciseID; dbProgress.ProgressId = progress.value; db.ExerciseProgressXrefs.InsertOnSubmit(dbProgress); db.SubmitChanges(); progress.ID = dbProgress.Id; } return progress; } catch { return null; } }
public static PTLocalPatient CreatePatient(PTLocalPatient patient) { try { //TODO: if user does not yet exist, we add the user, but it probably shouldn't add with status as confirmed. // add the patient to the db, set patient.ID, and return the patient using (PTLinkDatabaseDataContext db = new PTLinkDatabaseDataContext()) { Person person = new Person(); User user = (from u in db.Users where u.Email == patient.email && u.Password == patient.password select u).SingleOrDefault(); person.FirstName = patient.firstName; person.LastName = patient.lastName; person.Permissions = "Patient"; person.PushToken = patient.pushtoken; person.IsActive = true; if (user == null) { user = new User(); user.Email = patient.email; user.Password = patient.password; user.RegistrationStatus = (from r in db.RegistrationStatus where r.Status == "Confirmed" select r ).SingleOrDefault(); user.Persons.Add(person); db.Users.InsertOnSubmit(user); db.SubmitChanges(); } else { user.Persons.Add(person); db.SubmitChanges(); } patient.ID = user.Persons.SingleOrDefault().Id; return patient; } } catch { return null; } }