Exemplo n.º 1
0
        public ServiceResult Update(Symptom s)
        {
            if (s == null)
            {
                return(ServiceResponse.Error("Invalid Symptom sent to server."));
            }

            SymptomManager symptomManager = new SymptomManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            var dbS = (Symptom)symptomManager.GetBy(s.UUID);

            if (dbS == null)
            {
                return(ServiceResponse.Error("Symptom was not found."));
            }

            if (dbS.DateCreated == DateTime.MinValue)
            {
                dbS.DateCreated = DateTime.UtcNow;
            }
            dbS.Deleted   = s.Deleted;
            dbS.Name      = s.Name;
            dbS.Status    = s.Status;
            dbS.SortOrder = s.SortOrder;

            return(symptomManager.Update(dbS));
        }
Exemplo n.º 2
0
        public ServiceResult Update(Symptom s)
        {
            if (s == null)
            {
                return(ServiceResponse.Error("Invalid Symptom sent to server."));
            }

            SymptomManager symptomManager = new SymptomManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
            var            res            = symptomManager.Get(s.UUID);

            if (res.Code != 200)
            {
                return(res);
            }

            var dbS = (Symptom)res.Result;

            if (dbS.DateCreated == DateTime.MinValue)
            {
                dbS.DateCreated = DateTime.UtcNow;
            }
            dbS.Deleted   = s.Deleted;
            dbS.Name      = s.Name;
            dbS.Status    = s.Status;
            dbS.SortOrder = s.SortOrder;

            return(symptomManager.Update(dbS));
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
        }