Пример #1
0
        public bool AddNetworkUser(int networkId, int userId)
        {
            try
            {
                VestnDB db = new VestnDB();

                var n = new Network { id = networkId };
                var u = new User { id = userId };
                db.networks.Attach(n);
                db.users.Attach(u);

                n.networkUsers.Add(u);

                db.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogAccessor la = new LogAccessor();
                la.CreateLog(DateTime.Now, "Network Accessor AddAdmin", ex.StackTrace);
                return false;
            }
        }
Пример #2
0
        public string SetNetworkIdentifier(Network network)
        {
            try
            {
                Random r = new Random();
                string num = r.Next(100000, 999999).ToString();
                string newIdentifier = num + network.id.ToString();

                bool set = networkAccessor.UpdateNetworkIdentifier(network.id, newIdentifier);
                if (set)
                {
                    return newIdentifier;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                logAccessor.CreateLog(DateTime.Now, "Network Manager - SetNetworkIdentifier", ex.StackTrace);
                return null;
            }
        }
Пример #3
0
        public JsonModels.Network GetNetworkJson(Network network)
        {
            try
            {
                if (network != null)
                {
                    JsonModels.Network networkJson = new JsonModels.Network();
                    networkJson.id = network.id;
                    networkJson.coverPicture = network.coverPicture;
                    networkJson.description = network.description;
                    networkJson.name = network.name;
                    networkJson.privacy = network.privacy;
                    networkJson.profileURL = network.profileURL;
                    if (network.GetType().Name.Contains("Network_TopNetwork"))
                    {
                        Network_TopNetwork topNetwork = networkAccessor.GetTopNetwork(network.id);
                        if (topNetwork.subNetworks.Count > 0)
                        {
                            List<JsonModels.NetworkShell> subNetShells = new List<JsonModels.NetworkShell>();
                            foreach (Network_SubNetwork subNetwork in topNetwork.subNetworks)
                            {
                                if (subNetwork != null)
                                {
                                    JsonModels.NetworkShell netShell = new JsonModels.NetworkShell();
                                    netShell.id = subNetwork.id;
                                    netShell.name = subNetwork.name;
                                    netShell.profileURL = subNetwork.profileURL;
                                    netShell.coverPicture = subNetwork.coverPicture;
                                    netShell.privacy = subNetwork.privacy;
                                    subNetShells.Add(netShell);
                                }
                            }
                            networkJson.subNetworks = subNetShells;
                            networkJson.parentNetwork = null;
                        }
                        else
                        {
                            networkJson.subNetworks = null;
                        }
                    }
                    else if (network.GetType().Name.Contains("Network_SubNetwork"))
                    {
                        Network_SubNetwork subNetwork = (Network_SubNetwork)network;
                        if (subNetwork.groups.Count > 0)
                        {
                            List<JsonModels.NetworkShell> groupShells = new List<JsonModels.NetworkShell>();
                            foreach (Network_Group group in subNetwork.groups)
                            {
                                if (group != null)
                                {
                                    JsonModels.NetworkShell gShell = new JsonModels.NetworkShell();
                                    gShell.id = group.id;
                                    gShell.name = group.name;
                                    gShell.profileURL = group.profileURL;
                                    gShell.coverPicture = group.coverPicture;
                                    gShell.privacy = group.privacy;
                                    groupShells.Add(gShell);
                                }
                            }
                            networkJson.subNetworks = groupShells;

                            JsonModels.NetworkShell parentNetworkShell = new JsonModels.NetworkShell();
                            Network_TopNetwork topNet = subNetwork.Network_TopNetwork;

                            parentNetworkShell.id = topNet.id;
                            parentNetworkShell.name = topNet.name;
                            parentNetworkShell.profileURL = topNet.profileURL;
                            parentNetworkShell.coverPicture = topNet.coverPicture;
                            parentNetworkShell.privacy = topNet.privacy;
                            networkJson.parentNetwork = parentNetworkShell;
                        }
                        else
                        {
                            networkJson.subNetworks = null;

                            JsonModels.NetworkShell parentNetworkShell = new JsonModels.NetworkShell();
                            Network_TopNetwork topNet = subNetwork.Network_TopNetwork;

                            parentNetworkShell.id = topNet.id;
                            parentNetworkShell.name = topNet.name;
                            parentNetworkShell.profileURL = topNet.profileURL;
                            parentNetworkShell.coverPicture = topNet.coverPicture;
                            parentNetworkShell.privacy = topNet.privacy;
                            networkJson.parentNetwork = parentNetworkShell;
                        }

                    }
                    else if (network.GetType().Name.Contains("Network_Group"))
                    {
                        Network_Group networkGroup = (Network_Group)network;
                        JsonModels.NetworkShell parentNetworkShell = new JsonModels.NetworkShell();
                        Network_SubNetwork subNet = networkGroup.Network_SubNetwork;
                        parentNetworkShell.id = subNet.id;
                        parentNetworkShell.name = subNet.name;
                        parentNetworkShell.profileURL = subNet.profileURL;
                        parentNetworkShell.coverPicture = subNet.coverPicture;
                        parentNetworkShell.privacy = subNet.privacy;
                        networkJson.parentNetwork = parentNetworkShell;
                    }

                    if (network.admins.Count > 0)
                    {
                        List<JsonModels.NetworkUserShell> adminShells = new List<JsonModels.NetworkUserShell>();
                        foreach (User admin in network.admins)
                        {
                            if (admin != null)
                            {
                                JsonModels.NetworkUserShell adminJson = new JsonModels.NetworkUserShell();
                                adminJson.userId = admin.id;
                                adminJson.firstName = admin.firstName;
                                adminJson.lastName = admin.lastName;
                                adminJson.profileURL = admin.profileURL;
                                adminJson.pictureLocation = admin.networkPictureThumbnail;
                                if (admin.isPublic == 1)
                                {
                                    adminJson.visibility = "visible";
                                }
                                else
                                {
                                    adminJson.visibility = "hidden";
                                }
                                adminShells.Add(adminJson);
                            }
                        }
                        networkJson.admins = adminShells;
                    }
                    return networkJson;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                logAccessor.CreateLog(DateTime.Now, "Network Manager - GetNetworkJson", ex.StackTrace);
                return null;
            }
        }
Пример #4
0
 //public bool DeActivateIdentifier(Network network)
 //{
 //}
 public JsonModels.Network AddNetworkUsers(Network network, IEnumerable<string> userEmails)
 {
     try
     {
         if (network != null)
         {
             if (userEmails != null)
             {
                 foreach (string email in userEmails)
                 {
                     if (email != null)
                     {
                         ValidationEngine.ValidateEmail(email);
                         User addUser = userManager.GetUserByEmail(email);
                         if (addUser != null)
                         {
                             bool added = networkAccessor.AddNetworkUser(network.id, addUser.id);
                             if (network.GetType().Name.Contains("Network_SubNetwork"))
                             {
                                 Network_SubNetwork subNet = (Network_SubNetwork)network;
                                 bool added2 = networkAccessor.AddNetworkUser(subNet.Network_TopNetwork.id, addUser.id);
                             }
                             else if (network.GetType().Name.Contains("Network_Group"))
                             {
                                 Network_Group groupNet = (Network_Group)network;
                                 bool added3 = networkAccessor.AddNetworkUser(groupNet.Network_SubNetwork.id, addUser.id);
                                 bool added4 = networkAccessor.AddNetworkUser(groupNet.Network_SubNetwork.Network_TopNetwork.id, addUser.id);
                             }
                         }
                         else
                         {
                             CommunicationManager communicationManager = new CommunicationManager();
                             if (network.networkIdentifier == null)
                             {
                                 string identifier = SetNetworkIdentifier(network);
                                 communicationManager.SendRegisterNetworkInvite(email, identifier);
                             }
                             else
                             {
                                 communicationManager.SendRegisterNetworkInvite(email, network.networkIdentifier);
                             }
                         }
                     }
                 }
                 return GetNetworkJson(networkAccessor.GetNetwork(network.id));
             }
             else
             {
                 //no emails
                 return null;
             }
         }
         else
         {
             //no network
             return null;
         }
     }
     catch(Exception ex)
     {
         logAccessor.CreateLog(DateTime.Now, "Network Manager - AddNetworkUsers", ex.StackTrace);
         return null;
     }
 }
Пример #5
0
 public Network UpdateNetworkUrl(Network network)
 {
     try
     {
         VestnDB db = new VestnDB();
         var n = new Network { id = network.id };
         db.networks.Attach(n);
         n.profileURL = network.profileURL;
         db.SaveChanges();
         return network;
     }
     catch (Exception ex)
     {
         LogAccessor la = new LogAccessor();
         la.CreateLog(DateTime.Now, "Network Accessor Update Network", ex.StackTrace);
         return null;
     }
 }
Пример #6
0
 public Network UpdateNetworkInformation(Network network)
 {
     try
     {
         VestnDB db = new VestnDB();
         var n = new Network { id = network.id };
         db.networks.Attach(n);
         n.name = network.name;
         n.privacy = network.privacy;
         n.description = network.description;
         db.SaveChanges();
         return network;
     }
     catch (Exception ex)
     {
         LogAccessor la = new LogAccessor();
         la.CreateLog(DateTime.Now, "Network Accessor Update Network", ex.StackTrace);
         return null;
     }
 }
Пример #7
0
 public bool UpdateNetworkIdentifier(int networkId, string identifier)
 {
     try
     {
         VestnDB db = new VestnDB();
         Network n = new Network { id = networkId };
         db.networks.Attach(n);
         n.networkIdentifier = identifier;
         db.SaveChanges();
         return true;
     }
     catch (Exception ex)
     {
         LogAccessor la = new LogAccessor();
         la.CreateLog(DateTime.Now, "Network Accessor Update Network Identifier", ex.StackTrace);
         return false;
     }
 }
Пример #8
0
        public bool UpdateNetworkCoverPicture(int networkId, string coverPictureLocation)
        {
            try
            {
                VestnDB db = new VestnDB();
                var n = new Network {id = networkId};
                db.networks.Attach(n);
                n.coverPicture = coverPictureLocation;

                db.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogAccessor la = new LogAccessor();
                la.CreateLog(DateTime.Now, "Network Accessor UpdateNetworkCoverPicture", ex.StackTrace);
                return false;
            }
        }
Пример #9
0
        public Network CreateNetwork(Network network)
        {
            try
            {
                VestnDB db = new VestnDB();
                db.networks.Add(network);

                db.SaveChanges();
                return network;
            }
            catch (Exception ex)
            {
                LogAccessor la = new LogAccessor();
                la.CreateLog(DateTime.Now, "Network Accessor Create Network", ex.StackTrace);
                return null;
            }
        }