Пример #1
0
        public HttpResponseMessage AddMasterFieldToDataset(JObject jsonData)
        {
            logger.Debug("Inside AddMasterFieldToDataset...");
            var     db   = ServicesContext.Current;
            dynamic json = jsonData;

            int DatasetId = json.DatasetId.ToObject <int>();

            logger.Debug("DatasetId = " + DatasetId);
            var dataset = db.Datasets.Find(DatasetId);

            int FieldId = json.FieldId.ToObject <int>();

            logger.Debug("FieldId = " + FieldId);
            var field = db.Fields.Find(FieldId);

            DatasetField df = new DatasetField();

            df.DatasetId      = dataset.Id;
            df.FieldId        = field.Id;
            df.FieldRoleId    = field.FieldRoleId;
            df.CreateDateTime = DateTime.Now;
            df.Label          = field.Name;
            df.DbColumnName   = field.DbColumnName;
            df.SourceId       = 1;
            df.ControlType    = field.ControlType;

            db.DatasetFields.Add(df);
            db.SaveChanges();
            logger.Debug("Added/saved the field: " + field.DbColumnName);

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, df);

            return(response);
        }
Пример #2
0
        public HttpResponseMessage SaveDatasetField(JObject jsonData)
        {
            var db = ServicesContext.Current;

            dynamic json = jsonData;

            User me = AuthorizationManager.getCurrentUser();

            DatasetField df = db.DatasetFields.Find(json.Id.ToObject <int>());

            if (df == null || me == null)
            {
                throw new System.Exception("Configuration error. Please try again.");
            }

            df.Label        = json.Label;
            df.Validation   = json.Validation;
            df.Rule         = json.Rule;
            df.DbColumnName = json.DbColumnName;
            df.FieldRoleId  = json.FieldRoleId.ToObject <int>();
            try
            {
                df.OrderIndex = json.OrderIndex.ToObject <int>();
            }
            catch (System.Exception)
            {
                logger.Debug("didn't have an orderindex.");
            }
            df.ControlType = json.ControlType;
            df.SourceId    = json.SourceId.ToObject <int>();

            db.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.OK, df));
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject jo = JObject.Load(reader);

            string           Name             = jo["name"].ToString();
            DatasetFieldType DatasetFieldType = (DatasetFieldType)Enum.Parse(typeof(DatasetFieldType), jo["type"]?.ToString(), true);
            string           currency_code    = (string)jo["currency_code"];
            string           defaultvalue     = (string)jo["defaultvalue"];
            DatasetField     result           = new DatasetField(DatasetFieldType, Name, currency_code, defaultvalue);


            return(result);
        }
Пример #4
0
        public void GivenAFieldWithAnInvalidKey_WhenIValidateIt_ThenIGetArgumentException(string fieldKey)
        {
            var field = new DatasetField
            {
                Key = fieldKey
            };

            Action validateAction = () => this._validator.ValidateField(field);

            validateAction
            .Should()
            .Throw <ArgumentException>()
            .WithMessage("fieldKey*");;
        }
Пример #5
0
        public void GivenAFieldDisplayNameGreaterThan255Chars_WhenIValidateIt_ThenIGetArgumentException()
        {
            var field = new DatasetField
            {
                Key         = StringGenerator.RandomString(10),
                DisplayName = StringGenerator.RandomString(256)
            };

            Action validateAction = () => this._validator.ValidateField(field);

            validateAction
            .Should()
            .Throw <ArgumentException>()
            .WithMessage("displayName cannot be longer than 255 characters*");;
        }
Пример #6
0
        public async Task <Result> AddFieldToDataset(string datasetId, string fieldId)
        {
            Result       result = new Result();
            DatasetField field  = new DatasetField
            {
                DatasetId = Convert.ToInt32(datasetId),
                FieldId   = Convert.ToInt32(fieldId)
            };

            _repo.Create(field);
            await _repo.SaveAsync();

            result.Message = "Field has been successfully added in the dataset.";
            result.Success = true;
            return(result);
        }
Пример #7
0
        public Result DeleteDatasetField(string id)
        {
            Result       result = new Result();
            DatasetField field  = _repo.GetById <DatasetField>(Convert.ToInt32(id));

            try
            {
                _repo.Delete(field);
                _repo.Save();
                result.Message = "Field has been successfully deleted in the dataset.";
                result.Success = true;
            }
            catch (Exception e)
            {
                result.Message   = "Error deleting field.";
                result.ErrorCode = ErrorCode.EXCEPTION;
                _logger.LogError("Error calling DeleteDatasetField: {0}", e.Message);
            }
            return(result);
        }
Пример #8
0
        public HttpResponseMessage AddDatasetToProject(JObject jsonData)
        {
            logger.Debug("Here we are adding a dataset to a project!");
            var db = ServicesContext.Current;

            dynamic   json        = jsonData;
            int       DatastoreId = json.DatastoreId.ToObject <int>();
            Datastore ds          = db.Datastores.Find(DatastoreId);

            int     ProjectId = json.ProjectId.ToObject <int>();
            Project p         = db.Projects.Find(ProjectId);

            logger.Debug("We have a datastore to save: " + ds.Name + " for Project: " + p.Name);

            //CREATE A TRANSACTION!

            Dataset new_ds = new Dataset();

            new_ds.ProjectId                 = p.Id;
            new_ds.Name                      = p.Name + "-" + ds.Name;
            new_ds.DefaultRowQAStatusId      = 1;
            new_ds.StatusId                  = 1;
            new_ds.CreateDateTime            = DateTime.Now;
            new_ds.DefaultActivityQAStatusId = 6;
            new_ds.DatastoreId               = ds.Id;
            new_ds.Config                    = null;

            //TODO: this should be configured somewhere not hardcoded... ***

            // Non-WaterTemp datasets get these.
            QAStatus qa1 = db.QAStatuses.Find(5);
            QAStatus qa2 = db.QAStatuses.Find(6);
            QAStatus qa3 = db.QAStatuses.Find(1); // Default rowQA

            // For WaterTemp, if necessary.
            // WaterTemp datasets get more RowQA statuses.
            QAStatus rqa2 = null;
            QAStatus rqa3 = null;
            QAStatus rqa4 = null;
            QAStatus rqa5 = null;
            QAStatus rqa6 = null;
            QAStatus rqa7 = null;

            if (ds.TablePrefix == "WaterTemp")
            {
                // OK, find the additional RowQA Statuses for WaterTemp.
                rqa2 = db.QAStatuses.Find(12);
                rqa3 = db.QAStatuses.Find(13);
                rqa4 = db.QAStatuses.Find(14);
                rqa5 = db.QAStatuses.Find(15);
                rqa6 = db.QAStatuses.Find(16);
                rqa7 = db.QAStatuses.Find(17);
            }

            new_ds.QAStatuses = new List <QAStatus>();
            new_ds.QAStatuses.Add(qa1);
            new_ds.QAStatuses.Add(qa2);

            new_ds.RowQAStatuses = new List <QAStatus>();
            new_ds.RowQAStatuses.Add(qa3);

            if (ds.TablePrefix == "WaterTemp")
            {
                // Now, add the additional RowQA statuses to WaterTemp
                new_ds.RowQAStatuses.Add(rqa2);
                new_ds.RowQAStatuses.Add(rqa3);
                new_ds.RowQAStatuses.Add(rqa4);
                new_ds.RowQAStatuses.Add(rqa5);
                new_ds.RowQAStatuses.Add(rqa6);
                new_ds.RowQAStatuses.Add(rqa7);
            }

            new_ds.Fields = new List <DatasetField>();

            foreach (var field in json.DatasetFields)
            {
                logger.Debug(" -- " + field.Id);
                int   field_id  = field.Id.ToObject <int>();
                Field the_field = db.Fields.Find(field_id);

                DatasetField the_ds_field = new DatasetField();

                the_ds_field.FieldId = the_field.Id;

                var field_role = (from d in db.DatasetFields
                                  where d.FieldId == the_field.Id
                                  select d.FieldRoleId).FirstOrDefault();

                //pick up the fieldroleid from the way it is used in datasetfields.
                the_ds_field.FieldRoleId = (field_role != 0) ? field_role : 2; //default to DETAIL (2)

                the_ds_field.CreateDateTime = DateTime.Now;
                the_ds_field.Label          = the_field.Name;
                the_ds_field.DbColumnName   = the_field.DbColumnName;
                the_ds_field.ControlType    = the_field.ControlType;
                the_ds_field.Validation     = the_field.Validation;
                the_ds_field.Rule           = the_field.Rule;
                the_ds_field.SourceId       = 1;


                new_ds.Fields.Add(the_ds_field);
                //logger.Debug(" -- added " + field.Id);
            }

            db.Datasets.Add(new_ds);
            db.SaveChanges();

            //logger.Debug(new_ds);

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
Пример #9
0
 internal static Func <Task> WhenTryingToAddFieldToDataset(this ISmartObjectsClient client, string datasetKey, DatasetField field)
 {
     return(async() => await client.Datalake.AddFieldAsync(datasetKey, field));
 }