Пример #1
0
        public void bl_should_delete_field()
        {
            var s   = "delete-me";
            var obj = _bl.CreateField();

            obj.Slug = s;
            var getObj = _bl.GetField(s);

            Assert.True(obj.Equals(getObj));
            _bl.DeleteField(getObj);
            var getDel = _bl.GetField(s);

            Assert.Null(getDel);
        }
Пример #2
0
        public IActionResult PutFieldGroups(string slug, [FromBody] FieldGroupViewModel vmdl)
        {
            if (slug != vmdl.Slug)
            {
                return(BadRequest());
            }

            try
            {
                var fg = _bl.GetFieldGroup(vmdl.Slug);
                _bl.UpdateFieldGroup(fg);
                var f = fg.Fields.ToList();
                f.ForEach(i => _bl.DeleteField(i));
                fg.Fields.Clear();
                _bl.SaveChanges();
                vmdl.ApplyChanges(fg, _bl);
                vmdl.Refresh(fg);

                var meta = _bl.GetDeviceMeta()
                           .Where(i => i.FieldGroupSlug.Equals(slug))
                           .ToList();
                meta.ForEach(i => i.FieldGroupSlug = vmdl.Slug);

                _bl.SaveChanges();
                _log.LogInformation("FieldGroup '{0}' updated by '{1}'", vmdl.Name, User.Identity.Name);

                vmdl.Refresh(fg);
                return(Ok(vmdl));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_bl.FieldGroupExists(vmdl.Slug))
                {
                    _log.LogWarning("Not Found: FieldGroup '{0}' not found", slug);
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }