Esempio n. 1
0
        public void bl_should_create_field()
        {
            var obj = _bl.CreateField();

            obj.Slug = "test";
            Assert.NotNull(obj);
        }
Esempio n. 2
0
        private List <DeviceViewModel> CreateDeviceNoInvNum(DeviceViewModel vmdl)
        {
            var response = new List <DeviceViewModel>();

            // Check for new fields and add them
            vmdl.DeviceMeta.ForEach(i =>
            {
                var fg = _bl.GetFieldGroup(i.FieldGroupSlug);
                if (fg.Fields.Count(j => j.Name == i.Field) == 0)
                {
                    _bl.UpdateFieldGroup(fg);
                    var field = _bl.CreateField();
                    var fvmdl = new FieldViewModel {
                        Name = i.Field
                    };
                    fvmdl.ApplyChanges(field, _bl);
                    fg.Fields.Add(field);
                }
            });

            for (var i = 0; i < vmdl.Quantity; i++)
            {
                var d = _bl.CreateDevice();
                d.CreateDate         = DateTime.Now;
                vmdl.DeviceGroupSlug = vmdl.Name + "-" + _bl.GetCurrentUid();
                vmdl.ApplyChanges(d, _bl);
                response.Add(new DeviceViewModel(d).LoadMeta(d));
            }

            _bl.SaveChanges();

            return(response);
        }
Esempio n. 3
0
        public void ApplyChanges(FieldGroup fg, IBusinessLogicFacade bl)
        {
            var target = fg;
            var source = this;


            if (target.Name == null)
            {
                target.Slug = SlugGenerator.GenerateSlug(bl, source.Name, "fieldGroup");
            }
            if (target.Name != null && !target.Name.Equals(source.Name))
            {
                target.Slug = SlugGenerator.GenerateSlug(bl, source.Name, "fieldGroup");
            }
            target.Name = source.Name;

            target.Fields = new List <Field>();
            source.Fields.ForEach(i =>
            {
                var f = bl.CreateField();
                i.ApplyChanges(f, bl);
                target.Fields.Add(f);
            });
            target.IsCountable = source.IsCountable;
            target.IsActive    = source.IsActive;
        }
Esempio n. 4
0
        public IActionResult PostField(string groupSlug, [FromBody] FieldViewModel vmdl)
        {
            var obj = _bl.GetFieldGroup(groupSlug);

            _bl.UpdateFieldGroup(obj);

            var field = _bl.CreateField();

            vmdl.ApplyChanges(field, _bl);
            obj.Fields.Add(field);

            _bl.SaveChanges();
            vmdl.Refresh(field);
            _log.LogInformation("New Field '{0}' added to '{1}' by '{2}'", vmdl.Name, obj.Name, User.Identity.Name);
            return(Ok(vmdl));
        }