Exemple #1
0
        public IActionResult PostGroup([FromBody] FieldGroupViewModel vmdl)
        {
            var obj = _bl.CreateFieldGroup();

            vmdl.ApplyChanges(obj, _bl);
            _bl.SaveChanges();
            vmdl.Refresh(obj);
            _log.LogInformation("New FieldGroup '{0}' created by '{1}'", vmdl.Name, User.Identity.Name);
            return(Ok(vmdl));
        }
Exemple #2
0
        public IActionResult GetFieldGroupsUsedFieldsType(string typeSlug)
        {
            var dt = _bl.GetDeviceType(typeSlug);

            var vmdl = _bl.GetFieldGroups()
                       .ToList()
                       .Where(i => i.DeviceTypes == null || i.DeviceTypes.Contains(dt))
                       .Select(i => new FieldGroupViewModel(i))
                       .ToList();


            var meta = _bl.GetFilteredDevices(null, typeSlug)
                       .ToList()
                       .Select(i => new DeviceViewModel(i).LoadMeta(i))
                       .ToList()
                       .SelectMany(i => i.DeviceMeta)
                       .ToList()
                       .Select(i => i.FieldSlug)
                       .ToList();


            // Bad?
            var res = new List <FieldGroupViewModel>();

            vmdl.ForEach(i =>
            {
                var fieldGroup = new FieldGroupViewModel
                {
                    Name        = i.Name,
                    Slug        = i.Slug,
                    Fields      = new List <FieldViewModel>(),
                    IsCountable = i.IsCountable
                };

                i.Fields.ForEach(y =>
                {
                    if (!meta.Contains(y.Slug))
                    {
                        return;
                    }
                    fieldGroup.Fields.Add(y);
                });

                res.Add(fieldGroup);
            });

            return(Ok(res));
        }
        public void ctr_should_update_fields_of_field_group()
        {
            var obj = Bl.GetFieldGroup("prozessoren");

            Assert.NotNull(obj);
            var vmdl = new FieldGroupViewModel(obj);

            Assert.NotNull(vmdl);
            vmdl.Fields.SingleOrDefault(i => "intel-i5".Equals(i.Slug)).Name = "Intel Core i5";
            var res = (ctr.PutFieldGroups(vmdl.Slug, vmdl) as OkObjectResult)?.Value as FieldGroupViewModel;

            Assert.NotNull(res);
            var obj2 = Bl.GetFieldGroup("prozessoren");

            Assert.True(obj2.Fields.Any(i => i.Name.Equals("Intel Core i5")));
        }
Exemple #4
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;
                }
            }
        }
        public static FieldGroupViewModel GetvalidFieldGroupViewModel()
        {
            var fvmdl = new FieldViewModel
            {
                Name = "TestField",
                Slug = SlugGenerator.GenerateSlug(_bl, "TestField", "field")
            };

            var vmdl = new FieldGroupViewModel
            {
                Name   = "Test",
                Slug   = SlugGenerator.GenerateSlug(_bl, "Test", "fieldGroup"),
                Fields = new List <FieldViewModel>
                {
                    fvmdl
                },
            };

            return(vmdl);
        }