Exemple #1
0
        public void bl_should_delete_deviceMeta()
        {
            var id  = 2134;
            var obj = _bl.CreateDeviceMeta();

            obj.MetaId = id;
            Assert.NotNull(obj);
            var getObj   = _bl.GetDeviceMeta();
            var objToDel = getObj.SingleOrDefault(i => i.MetaId == id);

            _bl.DeleteMeta(objToDel);
            var getDel = getObj.SingleOrDefault(i => i.MetaId == id);

            Assert.Null(getDel);
        }
Exemple #2
0
        public IActionResult PutDevice(int id, [FromBody] DeviceViewModel vmdl)
        {
            if (id != vmdl.DeviceId)
            {
                return(BadRequest());
            }

            try
            {
                // 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();
                        field.FieldGroup = fg;
                        var fvmdl        = new FieldViewModel {
                            Name = i.Field
                        };
                        fvmdl.ApplyChanges(field, _bl);
                        fg.Fields.Add(field);
                    }
                });



                var dev = _bl.GetSingleDevice(vmdl.DeviceId);
                _bl.UpdateDevice(dev);
                var dm = dev.DeviceMeta.ToList();
                dm.ForEach(i => _bl.DeleteMeta(i));
                dev.DeviceMeta.Clear();
                vmdl.ApplyChanges(dev, _bl);
                _bl.SaveChanges();

                _log.LogInformation("Device '{0}({1})' updated by '{2}'", vmdl.InvNum, vmdl.Name, User.Identity.Name);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_bl.DeviceExists(id))
                {
                    _log.LogWarning("Not Found: Device '{0}' not found", id);
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            catch (SecurityException)
            {
                _log.LogWarning("Security: '{0}' tried to update Device '{1}'", User.Identity.Name, vmdl.InvNum);
            }
            catch (Exception ex)
            {
                _log.LogError("Exception: {0}", ex);
                return(StatusCode(500));
            }



            return(Ok(vmdl));
        }