public bool AddGroupNetwork(int subNetId, int groupNetId) { try { VestnDB db = new VestnDB(); var s = new Network_SubNetwork { id = subNetId }; var g = new Network_Group { id = groupNetId}; db.networks.Attach(s); db.networks.Attach(g); s.groups.Add(g); db.SaveChanges(); return true; } catch (Exception ex) { return false; } }
public string DeleteGroupNetwork(Network_SubNetwork subNetwork, Network_Group groupNetwork) { try { if (groupNetwork.admins.Count > 0) { return "GroupNetwork contains Admins"; } if (groupNetwork.networkUsers.Count > 0) { return "GroupNetwork contains Members"; } if (networkAccessor.DeleteGroupNetwork(subNetwork.id, groupNetwork.id)) { return "Success"; } else { return "Error"; } } catch (Exception ex) { return "Error"; } }
public JsonModels.Network CreateGroupNetwork(int subNetworkId, string name = null) { try { Network_SubNetwork subNet = (Network_SubNetwork)networkAccessor.GetNetwork(subNetworkId); Network_Group returnNetwork; if (subNet != null) { Network_Group newGroup = new Network_Group(); newGroup.name = name; //newGroup.SubNetworkId = subNetworkId; returnNetwork = (Network_Group)networkAccessor.CreateNetwork(newGroup); bool created = networkAccessor.AddGroupNetwork(subNet.id, returnNetwork.id); if (created) { return GetNetworkJson(networkAccessor.GetGroupNetwork(returnNetwork.id)); } } else { //cant add a groud network without knowing the parent sub network return null; } return GetNetworkJson(returnNetwork); } catch (Exception ex) { logAccessor.CreateLog(DateTime.Now, "Network Manager - CreateSubNetwork", ex.StackTrace); return null; } }