Beispiel #1
0
        /// <summary>
        /// Adds one company to Chronos
        /// </summary>
        /// <param name="Head">Authorization header with current user information</param>
        /// <param name="Company">Company entity with the data to add</param>
        /// <exception cref="Chronos.Exceptions.ChronosException">Thrown when an unknown error occurs.</exception>
        /// <exception cref="Chronos.Exceptions.DataAlreadyExistsException">Thrown when the company already exists.</exception>
        /// <exception cref="Chronos.Exceptions.NotAuthorizedException">Throws this exception when the user is not allowed to use this function.</exception>
        public void AddCompany(AuthHead Head, CompanyEntity Company)
        {
            Head.CommandID = "CHRONOS.MODULES.CORE.FOUNDATION.COMPANYSERVICE";
            Head.CommandOptionID = "ADDCOMPANY";

            if (userService.CanDoIt(Head))
            {
                if ((from company in dataConn.Companies where company.CompanyID == Company.CompanyID select company).Count() == 0)
                {
                    Companies newCompany = new Companies();
                    newCompany.CompanyID = Company.CompanyID;
                    newCompany.Name = Company.Name;
                    newCompany.Description = Company.Description;

                    dataConn.Companies.Add(newCompany);

                    if (dataConn.SaveChanges() <= 0)
                    { throw new ChronosException("It wasn't possible to add the new company."); }
                }
                else
                { throw new DataAlreadyExistsException(); }
            }
            else
            { throw new NotAuthorizedException(); }
        }
Beispiel #2
0
        /// <summary>
        /// Edits the provided company
        /// </summary>
        /// <param name="Head">Authorization header with current user information</param>
        /// <param name="Company">Company entity with the data to edit</param>
        /// <exception cref="Chronos.Exceptions.ChronosException">Thrown when an unknown error occurs.</exception>
        public void EditCompany(AuthHead Head, CompanyEntity Company)
        {
            Head.CommandID = "CHRONOS.MODULES.CORE.FOUNDATION.COMPANYSERVICE";
            Head.CommandOptionID = "EDITCOMPANY";

            if (userService.CanDoIt(Head))
            {
                var varCompany = (from company in dataConn.Companies where company.CompanyID == Company.CompanyID select company).FirstOrDefault();
                if (varCompany != null)
                {
                    varCompany.Name = Company.Name;
                    varCompany.Description = Company.Description;

                    if (dataConn.SaveChanges() <= 0)
                    { throw new ChronosException("It wasn't possible to save the changes in the company."); }
                }
                else
                { throw new DataNotFoundException("The specified company do not exist."); }
            }
            else
            { throw new NotAuthorizedException(); }
        }
Beispiel #3
0
        /// <summary>
        /// Gets the company for the given Company ID
        /// </summary>
        /// <param name="CompanyID">Company ID to get</param>
        /// <returns>Selected company</returns>
        public CompanyEntity GetCompany(string CompanyID)
        {
            var varCompany = (
                    from company in dataConn.Companies
                    where company.CompanyID == CompanyID
                    select company
                ).FirstOrDefault();

            if (varCompany == null)
            { return null; }
            else
            {
                Models.CompanyEntity companyReturn = new Models.CompanyEntity();
                companyReturn.CompanyID = varCompany.CompanyID;
                companyReturn.Description = varCompany.Description;
                companyReturn.Name = varCompany.Name;

                return companyReturn;
            }
        }