Exemplo n.º 1
0
        // private
        private void AddServerToUser(string userId, string serverShortName)
        {
            // Make sure the server exists
            ApplicationServer _server = _dbContext.Servers.FirstOrDefault(r => r.ServerShortName == serverShortName);

            if (_server == null)
            {
                // "{0} - 'server/device' not found: {1}"
                throw new ArgumentNullException(string.Format(
                                                    NSG.Identity.Constants.ServerNotFoundException, _codeName, serverShortName));
            }
            //
            ApplicationUser _user = _dbContext.Users.FirstOrDefault(r => r.Id == userId);

            if (_user == null)
            {
                // "{0} - 'user' not found: {1}"
                throw new ArgumentNullException(string.Format(
                                                    NSG.Identity.Constants.UserNotFoundException, _codeName, userId));
            }
            // Make sure the user doesn't already have this server
            if (_user.Servers.FirstOrDefault(r => r.ServerShortName == serverShortName) != null)
            {
                // "{0} - user: {1}, 'server/device' already assigned: {2}"
                throw new ArgumentNullException(string.Format(
                                                    NSG.Identity.Constants.ServerAlreadyAssignedException, _codeName, userId, serverShortName));
            }
            _user.Servers.Add(_server);
            this._dbContext.Entry(_user).State = EntityState.Modified;
        }
Exemplo n.º 2
0
        //
        /// <summary>
        /// Delete a server from ApplicationServer
        /// </summary>
        /// <param name="server">an ApplicationServer</param>
        /// <returns>nothing</returns>
        public void Delete(ApplicationServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException(_invalidServerArgument);
            }
            ApplicationServer _server = FindById(server.ServerId);

            if (_server != null)
            {
                //
                var netlogs = this._dbContext.NetworkLogs.Where(_nl => _nl.ServerId == server.ServerId);
                foreach (NetworkLog _l in netlogs)
                {
                    //         string _invalidServerInUse = "{0}, Server shortName: {1} in use by incident {2}.";
                    if (_l.IncidentId > 0)
                    {
                        throw new ArgumentNullException(
                                  string.Format(_invalidServerInUse, _codeName,
                                                _server.ServerShortName, _l.IncidentId));
                    }
                    //
                    this._dbContext.NetworkLogs.Remove(_l);
                }
                this._dbContext.Servers.Remove(_server);
                this._dbContext.SaveChanges();
            }
            //
        }
Exemplo n.º 3
0
 //
 /// <summary>
 /// Insert a new server to ApplicationServer
 /// </summary>
 /// <param name="server">an ApplicationServer</param>
 /// <returns>nothing</returns>
 public void Create(ApplicationServer server)
 {
     if (server == null)
     {
         throw new ArgumentNullException(_invalidServerArgument);
     }
     //
     this._dbContext.Servers.Add(server);
     this._dbContext.SaveChanges();
 }
Exemplo n.º 4
0
 // non-async version
 public int Delete(ApplicationServer server)
 {
     if (server == null)
     {
         throw new ArgumentNullException("Server");
     }
     //
     this._dbContext.Servers.Remove(server);
     return(this._dbContext.SaveChanges());
 }
Exemplo n.º 5
0
        // non-async version
        public int Create(ApplicationServer Server)
        {
            if (Server == null)
            {
                throw new ArgumentNullException("Server");
            }

            this._dbContext.Servers.Add(Server);
            return(this._dbContext.SaveChanges());
        }
Exemplo n.º 6
0
 // non-async version
 public int Update(ApplicationServer Server)
 {
     if (Server == null)
     {
         throw new ArgumentNullException("Server");
     }
     //
     this._dbContext.Entry(Server).State = EntityState.Modified;
     return(this._dbContext.SaveChanges());
 }
Exemplo n.º 7
0
        // private delete server from user
        private void DeleteServerFromUser(string userId, string serverShortName)
        {
            //
            ApplicationUser _user = _dbContext.Users.FirstOrDefault(r => r.Id == userId);

            if (_user == null)
            {
                // "{0} - 'user' not found: {1}"
                throw new ArgumentNullException(string.Format(
                                                    NSG.Identity.Constants.UserNotFoundException, _codeName, userId));
            }
            ApplicationServer _server = _user.Servers.FirstOrDefault(r => r.ServerShortName == serverShortName);

            if (_server == null)
            {
                // "{0} - user: {1}, server: {2} not found."
                throw new ArgumentNullException(string.Format(
                                                    NSG.Identity.Constants.UserServerNotFoundException, _codeName, userId, serverShortName));
            }
            _user.Servers.Remove(_server);
            this._dbContext.Entry(_user).State = EntityState.Modified;
        }
Exemplo n.º 8
0
 //
 /// <summary>
 /// Removes a user from a server
 /// </summary>
 /// <param name="user"></param>
 /// <param name="shortName">server short name</param>
 /// <returns></returns>
 public void RemoveFromServer(ApplicationUser user, string shortName)
 {
     if (user == null)
     {
         throw new ArgumentNullException(_invalidUserArgument);
     }
     if (string.IsNullOrEmpty(shortName))
     {
         throw new ArgumentException(_invalidShortNameArgument);
     }
     //
     if (user.Servers.Where(_s => _s.ServerShortName.Contains(shortName)).Select(_s => _s.ServerId).Count() > 0)
     {
         //
         ApplicationServer _server = FindByName(shortName);
         if (_server != null)
         {
             user.Servers.Remove(_server);
             this._dbContext.SaveChanges();
         }
         //
     }
 }
Exemplo n.º 9
0
 //
 /// <summary>
 /// Inserts an entry in the UserServers table
 /// </summary>
 /// <param name="user">User to have server added</param>
 /// <param name="shortName">Name of the server to be added to user</param>
 /// <returns></returns>
 public void AddToServer(ApplicationUser user, string shortName)
 {
     if (user == null)
     {
         throw new ArgumentNullException(_invalidUserArgument);
     }
     if (string.IsNullOrEmpty(shortName))
     {
         throw new ArgumentException(_invalidShortNameArgument);
     }
     //
     //if (user.Servers.Where(_s => _s.ServerShortName.Contains(shortName)) == null)
     if (user.Servers.FirstOrDefault(r => r.ServerShortName == shortName) == null)
     {
         //
         ApplicationServer _server = FindByName(shortName);
         if (_server != null)
         {
             user.Servers.Add(_server);
             this._dbContext.SaveChanges();
         }
         //
     }
 }
Exemplo n.º 10
0
 // non-async version
 public void Update(ApplicationServer server)
 {
     _serverStore.Update(server);
 }
Exemplo n.º 11
0
 public Task UpdateAsync(ApplicationServer server)
 {
     return(_serverStore.UpdateAsync(server));
 }
Exemplo n.º 12
0
 public void Delete(ApplicationServer server)
 {
     _serverStore.Delete(server);
 }
Exemplo n.º 13
0
 // Asynchronously deletes a server.
 public Task DeleteAsync(ApplicationServer server)
 {
     return(_serverStore.DeleteAsync(server));
 }
Exemplo n.º 14
0
 public void Create(ApplicationServer server)
 {
     _serverStore.Create(server);
 }
Exemplo n.º 15
0
 //
 /// <summary>
 /// Update a server
 /// </summary>
 /// <param name="server">an ApplicationServer</param>
 /// <returns>nothing</returns>
 public Task UpdateAsync(ApplicationServer server)
 {
     Update(server);
     return(Task.FromResult <object>(null));
 }
Exemplo n.º 16
0
        //
        /// <summary>
        /// Update a server
        /// </summary>
        /// <param name="server">an ApplicationServer</param>
        /// <returns>nothing</returns>
        public void Update(ApplicationServer server)
        {
            var _server = this._dbContext.Servers.FirstOrDefault(s => s.ServerId == server.ServerId);

            if (_server != null)
            {
                //
                if (_server.CompanyId != server.CompanyId)
                {
                    _server.CompanyId = server.CompanyId;
                }
                if (_server.ServerShortName != server.ServerShortName)
                {
                    _server.ServerShortName = server.ServerShortName;
                }
                if (_server.ServerName != server.ServerName)
                {
                    _server.ServerName = server.ServerName;
                }
                if (_server.WebSite != server.WebSite)
                {
                    _server.WebSite = server.WebSite;
                }
                if (_server.ServerDescription != server.ServerDescription)
                {
                    _server.ServerDescription = server.ServerDescription;
                }
                if (_server.ServerLocation != server.ServerLocation)
                {
                    _server.ServerLocation = server.ServerLocation;
                }
                if (_server.FromName != server.FromName)
                {
                    _server.FromName = server.FromName;
                }
                if (_server.FromNicName != server.FromNicName)
                {
                    _server.FromNicName = server.FromNicName;
                }
                if (_server.FromEmailAddress != server.FromEmailAddress)
                {
                    _server.FromEmailAddress = server.FromEmailAddress;
                }
                if (_server.TimeZone != server.TimeZone)
                {
                    _server.TimeZone = server.TimeZone;
                }
                if (_server.DST != server.DST)
                {
                    _server.DST = server.DST;
                }
                if (_server.TimeZone_DST != server.TimeZone_DST)
                {
                    _server.TimeZone_DST = server.TimeZone_DST;
                }
                if (_server.DST_Start != server.DST_Start)
                {
                    _server.DST_Start = server.DST_Start;
                }
                if (_server.DST_End != server.DST_End)
                {
                    _server.DST_End = server.DST_End;
                }
                //
                this._dbContext.SaveChanges();
            }
        }