Beispiel #1
0
        //
        #endregion
        //
        // -------------------------------------------------------------------
        //	Public Access Methods
        //		GetById
        //		CompanyInsert
        //		ServerInsert
        //		CompanyUpdate
        //		ServerUpdate
        //		CompanyDelete
        //      ServerDelete
        //
        #region "Public Access Methods"
        //
        /// <summary>
        /// Return one row of Company
        /// </summary>
        /// <param name="companyId"></param>
        /// <returns></returns>
        public CompanyServerData GetById(int companyId)
        {
            CompanyServerData _companyServer = null;
            Company           _company       =
                _niEntities.Companies.FirstOrDefault(_r => _r.CompanyId == companyId);

            if (_company != null)
            {
                // See extensions.cs for ToCompanyServerData
                _companyServer = _company.ToCompanyServerData();
            }
            return(_companyServer);
        }
Beispiel #2
0
        //
        /// <summary>
        /// Extension method...
        /// can be called fluently by the class or as a static method.
        /// </summary>
        /// <param name="company"></param>
        /// <returns></returns>
        public static CompanyServerData ToCompanyServerData(this Company company)
        {
            CompanyServerData _csd = new CompanyServerData()
            {
                CompanyId        = company.CompanyId,
                CompanyShortName = company.CompanyShortName,
                CompanyName      = company.CompanyName,
                // servers must be instantiated incase no servers
                Servers = new List <ServerData>()
                          // Servers = company.Servers.AsEnumerable<ApplicationServer>()
                          //     .Select(_s => _s.ToServerData()).ToList()
            };

            foreach (ApplicationServer _s in company.Servers)
            {
                _csd.Servers.Add(_s.ToServerData());
            }
            return(_csd);
        }
Beispiel #3
0
        //
        /// <summary>
        /// Insert one row into Company
        /// </summary>
        /// <param name="companyId"></param>
        /// <param name="companyName"></param>
        /// <param name="servers"></param>
        /// <returns></returns>
        public int CompanyInsert(CompanyServerData companyServerData)
        {
            int     _return  = 0;
            Company _company = new Company();

            _company.CompanyShortName = companyServerData.CompanyShortName;
            _company.CompanyName      = companyServerData.CompanyName;
            // See extensions.cs for ToServer
            if (companyServerData.Servers != null)
            {
                foreach (ServerData _s in companyServerData.Servers)
                {
                    _company.Servers.Add(_s.ToServer());
                }
            }
            //
            _niEntities.Companies.Add(_company);
            _niEntities.SaveChanges();
            companyServerData.CompanyId = _company.CompanyId;
            _return = 1 + (companyServerData.Servers != null ? companyServerData.Servers.Count : 0);    // one row updated
            return(_return);
        }
Beispiel #4
0
        //
        /// <summary>
        /// Update one row of Company
        /// </summary>
        /// <param name="companyServerData"></param>
        /// <returns></returns>
        public int CompanyUpdate(CompanyServerData companyServerData)
        {
            int _return    = 0;
            var _companies =
                from _r in _niEntities.Companies
                where _r.CompanyId == companyServerData.CompanyId
                select _r;

            if (_companies.Count() > 0)
            {
                Company _company = _companies.First();
                if (_company.CompanyShortName != companyServerData.CompanyShortName)
                {
                    _company.CompanyShortName = companyServerData.CompanyShortName;
                }
                if (_company.CompanyName != companyServerData.CompanyName)
                {
                    _company.CompanyName = companyServerData.CompanyName;
                }
                _niEntities.SaveChanges();
                _return = 1;    // one row updated
            }
            return(_return);
        }