public ServiceResult Insert(SymptomLog s, bool validateFirst = true) { using (var context = new TreeMonDbContext(this._connectionKey)) { if (validateFirst) { SymptomLog dbU = context.GetAll <SymptomLog>().FirstOrDefault(wu => wu.Name.EqualsIgnoreCase(s.Name) && wu.AccountUUID == s.AccountUUID); if (dbU != null) { return(ServiceResponse.Error("SymptomLog already exists.")); } } s.UUID = Guid.NewGuid().ToString("N"); s.UUIDType = "SymptomLog"; if (!this.DataAccessAuthorized(s, "POST", false)) { return(ServiceResponse.Error("You are not authorized this action.")); } if (context.Insert <SymptomLog>(s)) { return(ServiceResponse.OK("", s)); } } return(ServiceResponse.Error("An error occurred inserting SymptomLog " + s.Name)); }
public void SymptomManager_DeleteSymptomLog() { SymptomManager m = new SymptomManager(new TreeMonDbContext(connectionKey)); SymptomLog s = new SymptomLog() { AccountId = "a", Name = "DELETERECORD", CreatedBy = "TESTUSER", DateCreated = DateTime.UtcNow, DoseUUID = "D" }; m.InsertLog(s); //Test the delete flag Assert.IsTrue(m.DeleteSymptomLog(s) > 0); m.GetSymptomLog("DELETERECORD"); SymptomLog d = m.GetSymptomLog("DELETERECORD"); Assert.IsNotNull(d); Assert.IsTrue(d.Deleted == true); Assert.IsTrue(m.DeleteSymptomLog(s, true) > 0); d = m.GetSymptomLog("DELETERECORD"); Assert.IsNull(d); }
public ServiceResult UpdateSymptomLogField(string symptomLogUUID, string fieldName, string fieldValue) { if (string.IsNullOrWhiteSpace(symptomLogUUID)) { return(ServiceResponse.Error("You must provide a UUID.")); } if (string.IsNullOrWhiteSpace(fieldName)) { return(ServiceResponse.Error("You must provide a field name.")); } if (string.IsNullOrWhiteSpace(fieldValue)) { return(ServiceResponse.Error("You must provide a field value.")); } if (CurrentUser == null) { return(ServiceResponse.Error("You must be logged in to access this function.")); } SymptomManager symptomManager = new SymptomManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); SymptomLog sl = symptomManager.GetSymptomLogBy(symptomLogUUID); if (sl == null) { return(ServiceResponse.Error("Could not find the log item.")); } if (CurrentUser.UUID != sl.CreatedBy) { return(ServiceResponse.Error("You are not authorized to change this item.")); } bool success = false; fieldName = fieldName.ToLower(); switch (fieldName) { case "duration": sl.Duration = fieldValue.ConvertTo <float>(out success); if (!success) { return(ServiceResponse.Error("Invalid field value.")); } break; case "durationmeasure": sl.DurationMeasure = fieldValue; break; default: return(ServiceResponse.Error("Field " + fieldName + " not supported.")); } return(symptomManager.Update(sl)); }
public ServiceResult Delete(SymptomLog s) { if (s == null || string.IsNullOrWhiteSpace(s.UUID)) { return(ServiceResponse.Error("Invalid account was sent.")); } SymptomManager symptomManager = new SymptomManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); return(symptomManager.Delete(s)); }
public ServiceResult Delete(SymptomLog s) { if (s == null || string.IsNullOrWhiteSpace(s.UUID)) { return(ServiceResponse.Error("Invalid account was sent.")); } SymptomManager symptomManager = new SymptomManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter); return(symptomManager.Delete(s)); }
public void SymptomManager_GetSymptomLog() { SymptomManager m = new SymptomManager(new TreeMonDbContext(connectionKey)); ServiceResult sr = m.InsertLog(new SymptomLog() { AccountId = "a", Name = "ALPHA", DateCreated = DateTime.UtcNow , DoseUUID = "D" }, false); Assert.AreEqual(sr.Code, 200, sr.Message); SymptomLog s = m.GetSymptomLog("ALPHA"); Assert.IsNotNull(s); }
public ServiceResult GetSymptomLog(string name = "") { if (string.IsNullOrWhiteSpace(name)) { return(ServiceResponse.Error("You must provide a name for the SymptomLog.")); } SymptomManager symptomManager = new SymptomManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); SymptomLog s = symptomManager.GetSymptomLog(name); if (s == null) { return(ServiceResponse.Error("SymptomLog could not be located for the name " + name)); } return(ServiceResponse.OK("", s)); }
public ServiceResult Update(SymptomLog s) { if (s == null) { return(ServiceResponse.Error("Invalid SymptomLog sent to server.")); } SymptomManager symptomManager = new SymptomManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); var dbS = symptomManager.GetSymptomLogBy(s.UUID); if (dbS == null) { return(ServiceResponse.Error("SymptomLog was not found.")); } if (s.Efficacy < -5 || s.Efficacy > 5) { return(ServiceResponse.Error("Efficacy is out of range.")); } if (CurrentUser == null) { return(ServiceResponse.Error("You must be logged in to access this function.")); } if (CurrentUser.UUID != dbS.CreatedBy) { return(ServiceResponse.Error("You are not authorized to change this item.")); } dbS.Name = s.Name; dbS.Status = s.Status; dbS.Duration = s.Duration; dbS.DurationMeasure = s.DurationMeasure; dbS.Efficacy = s.Efficacy; dbS.Severity = s.Severity; dbS.SymptomDate = s.SymptomDate; //test this.make sure date, status, severity, efficacy etc is copied over. return(symptomManager.Update(dbS)); }
public void SymptomManager_UpdateSymptomLog() { SymptomManager m = new SymptomManager(new TreeMonDbContext(connectionKey)); m.InsertLog(new SymptomLog() { AccountId = "a", Name = "TESTRECORD", DoseUUID = "D" }); SymptomLog s = m.GetSymptomLog("TESTRECORD"); s.Name = "UPDATEDRECORD"; Assert.AreEqual(m.UpdateSymptomLog(s).Code, 200); SymptomLog u = m.GetSymptomLog("UPDATEDRECORD"); Assert.IsNotNull(u); }
public ServiceResult Delete(SymptomLog s, bool purge = false) { ServiceResult res = ServiceResponse.OK(); if (s == null) { return(ServiceResponse.Error("No record sent.")); } if (!this.DataAccessAuthorized(s, "DELETE", false)) { return(ServiceResponse.Error("You are not authorized this action.")); } if (purge) { using (var context = new TreeMonDbContext(this._connectionKey)) { if (context.Delete <SymptomLog>(s) == 0) { return(ServiceResponse.Error(s.Name + " failed to delete. ")); } } } //get the SymptomLog from the table with all the data so when its updated it still contains the same data. s = this.GetSymptomLogBy(s.UUID); if (s == null) { return(ServiceResponse.Error("Symptom not found")); } s.Deleted = true; using (var context = new TreeMonDbContext(this._connectionKey)) { if (context.Update <SymptomLog>(s) == 0) { return(ServiceResponse.Error(s.Name + " failed to delete. ")); } } return(res); }
public void SymptomManager_GetSymptomLogBy() { SymptomManager m = new SymptomManager(new TreeMonDbContext(connectionKey)); Assert.AreEqual( m.InsertLog(new SymptomLog() { AccountId = "a", Name = "TESTRECORD", DateCreated = DateTime.UtcNow , DoseUUID = "D" }, false) .Code, 200); SymptomLog s = m.GetSymptomLog("TESTRECORD"); Assert.IsNotNull(s); SymptomLog suid = m.GetSymptomLogBy(s.UUID); Assert.IsNotNull(suid); }
public ServiceResult Update(SymptomLog s) { if (s == null) { return(ServiceResponse.Error("Invalid SymptomLog data.")); } if (!this.DataAccessAuthorized(s, "PATCH", false)) { return(ServiceResponse.Error("You are not authorized this action.")); } using (var context = new TreeMonDbContext(this._connectionKey)) { if (context.Update <SymptomLog>(s) > 0) { return(ServiceResponse.OK()); } } return(ServiceResponse.Error("System error, SymptomLog was not updated.")); }
public ServiceResult SetRating(string uuid, string type, float score) { if (CurrentUser == null) { return(ServiceResponse.Error("You must be logged in to access this function.")); } if (string.IsNullOrWhiteSpace(uuid)) { return(ServiceResponse.Error("You must supply a unique identifier.")); } if (string.IsNullOrWhiteSpace(type)) { return(ServiceResponse.Error("You must supply a type identifier.")); } type = type.ToUpper().Trim(); switch (type) { case "SYMPTOMLOG": SymptomManager symptomManager = new SymptomManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter); SymptomLog sl = symptomManager.GetSymptomLogBy(uuid); if (sl == null) { return(ServiceResponse.Error("Could not find symptom.")); } if (sl.CreatedBy != CurrentUser.UUID) //|| sl.AccountId != currentUser.AccountId) { return(ServiceResponse.Error("You are not authorized to rate this item.")); } sl.Efficacy = score; return(symptomManager.Update(sl)); } return(ServiceResponse.Error("Invalid type:" + type)); }
public void Api_PollController_SaveRating_SYMPTOMLOG() { TreeMonDbContext context = new TreeMonDbContext(connectionKey); //User user = TestHelper.GenerateTestUser(Guid.NewGuid().ToString("N")); //string userJson = JsonConvert.SerializeObject(user); SessionManager sessionManager = new SessionManager(connectionKey); // UserSession us = sessionManager.SaveSession("127.1.1.40", user.UUID, userJson, false); UserSession us = sessionManager.GetSession(_ownerAuthToken); Assert.IsNotNull(us); User user = JsonConvert.DeserializeObject <User>(us.UserData); SymptomLog mdl = new SymptomLog(); mdl.AccountUUID = SystemFlag.Default.Account; mdl.CreatedBy = user.UUID; mdl.Name = Guid.NewGuid().ToString("N"); mdl.UUID = Guid.NewGuid().ToString("N"); mdl.DateCreated = DateTime.Now; mdl.SymptomDate = DateTime.Now; Assert.IsTrue(context.Insert <SymptomLog>(mdl)); int score = new Random().Next(1, 100000);//this is big for the test to reduce chance of collission when checking the result. Task.Run(async() => { ServiceResult res = await TestHelper.SentHttpRequest("POST", "api/Ratings/SYMPTOMLOG/" + mdl.UUID + "/Save/" + score.ToString(), "", _ownerAuthToken); Assert.IsNotNull(res); Assert.AreEqual(res.Code, 200); SymptomLog dblog = context.GetAll <SymptomLog>().FirstOrDefault(w => w.UUID == mdl.UUID); Assert.IsNotNull(dblog); Assert.AreEqual(mdl.Name, dblog.Name); Assert.AreEqual(score, dblog.Efficacy); }).GetAwaiter().GetResult(); }
public ServiceResult AddSymptomLog(SymptomLog s) { if (CurrentUser == null) { return(ServiceResponse.Error("You must be logged in to access this function.")); } if (string.IsNullOrWhiteSpace(s.AccountUUID) || s.AccountUUID == SystemFlag.Default.Account) { s.AccountUUID = CurrentUser.AccountUUID; } if (string.IsNullOrWhiteSpace(s.CreatedBy)) { s.CreatedBy = CurrentUser.UUID; } SymptomManager symptomManager = new SymptomManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); if (!string.IsNullOrWhiteSpace(s.UUParentID)) { SymptomLog parentLog = symptomManager.GetSymptomLogBy(s.UUParentID); if (parentLog == null) { return(ServiceResponse.Error("Invalid log parent id. The UUParentID must belong to a valid Symptom Log entry.")); } s.DoseUUID = parentLog.DoseUUID; if (string.IsNullOrWhiteSpace(s.UUParentIDType)) { s.UUParentIDType = parentLog.UUIDType; } } s.Active = true; if (string.IsNullOrWhiteSpace(s.UUIDType)) { s.UUIDType = "SymptomLog"; } //backlog go to dosehistory selsect a dose and in the symptomps list //click add . fill in the data and click //VERIFY the fields here. //rules for parent list symptom creation //Name <- may need to create //SymptomUUID <- may need to create if (string.IsNullOrWhiteSpace(s.Name) && string.IsNullOrWhiteSpace(s.SymptomUUID)) { return(ServiceResponse.Error("You must select a symptom.")); } else if (string.IsNullOrWhiteSpace(s.Name) && string.IsNullOrWhiteSpace(s.SymptomUUID) == false) { //get and assign the name var res = symptomManager.Get(s.SymptomUUID); if (res.Code != 200) { return(res); } Symptom symptom = (Symptom)res.Result; s.Name = symptom.Name; } else if (!string.IsNullOrWhiteSpace(s.Name) && string.IsNullOrWhiteSpace(s.SymptomUUID)) { //create the symptoms and assign it to the symptomuuid Symptom symptom = (Symptom)symptomManager.Search(s.Name)?.FirstOrDefault(); if (symptom != null) { s.SymptomUUID = symptom.UUID; } else { symptom = new Symptom() { Name = s.Name, AccountUUID = s.AccountUUID, Active = true, CreatedBy = CurrentUser.UUID, DateCreated = DateTime.UtcNow, Deleted = false, UUIDType = "Symptom", Category = "General" }; ServiceResult sr = symptomManager.Insert(symptom); if (sr.Code == 500) { return(ServiceResponse.Error(sr.Message)); } s.SymptomUUID = symptom.UUID; } } if (s.SymptomDate == null || s.SymptomDate == DateTime.MinValue) { s.SymptomDate = DateTime.UtcNow; } if (string.IsNullOrWhiteSpace(s.Status))//Status start middle end. Query StatusMessage table { return(ServiceResponse.Error("You must provide a status.")); } if (s.Severity > 5) { return(ServiceResponse.Error("Severity must not be greater than 5.")); } if (s.Efficacy > 5) { return(ServiceResponse.Error("Efficacy must not be greater than 5.")); } return(symptomManager.Insert(s)); }