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)); }
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; } } }