Example #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(); }
        }
Example #2
0
        /// <summary>
        /// Adds one division to Chronos
        /// </summary>
        /// <param name="Head">Authorization header with current user information</param>
        /// <param name="Division">Division 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 AddDivision(AuthHead Head, DivisionEntity Division)
        {
            Head.CommandID = "CHRONOS.MODULES.CORE.FOUNDATION.DIVISIONSERVICE";
            Head.CommandOptionID = "ADDDIVISION";

            if (userService.CanDoIt(Head))
            {
                if ((from division in dataConn.Divisions where division.CompanyID == Division.CompanyID && division.DivisionID == Division.DivisionID select division).Count() == 0)
                {
                    Divisions newDivision = new Divisions();
                    newDivision.CompanyID = Division.CompanyID;
                    newDivision.DivisionID = Division.DivisionID;
                    newDivision.Name = Division.Name;
                    newDivision.Description = Division.Description;

                    dataConn.Divisions.Add(newDivision);

                    if (dataConn.SaveChanges() <= 0)
                    { throw new ChronosException("It wasn't possible to add the new division."); }
                }
                else
                { throw new DataAlreadyExistsException(); }
            }
            else
            { throw new NotAuthorizedException(); }
        }
Example #3
0
        /// <summary>
        /// Adds one user to the users table
        /// </summary>
        /// <param name="Head">Authorization header with current user information</param>
        /// <param name="User">User 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 user already exists.</exception>
        /// <exception cref="Chronos.Exceptions.NotAuthorizedException">Throws this exception when the user is not allowed to use this function.</exception>
        public void AddUser(AuthHead Head, UserEntity User)
        {
            Head.CommandID = "CHRONOS.MODULES.CORE.SECURITY.USERSERVICE";
            Head.CommandOptionID = "ADDUSER";

            if (CanDoIt(Head))
            {
                if ((from user in dataConn.Users where user.UserID == User.UserID select user).Count() == 0)
                {
                    Users newUser = new Users();
                    newUser.UserID = User.UserID;
                    newUser.Password = User.Password;
                    newUser.Name = User.Name;
                    newUser.EMail = User.EMail;

                    dataConn.Users.Add(newUser);

                    if (dataConn.SaveChanges() <= 0)
                    { throw new ChronosException("It wasn't possible to add the new user."); }
                }
                else
                { throw new DataAlreadyExistsException(); }
            }
            else
            { throw new NotAuthorizedException(); }
        }
Example #4
0
        /// <summary>
        /// Edits the provided division
        /// </summary>
        /// <param name="Division">Division entity with the data to edit</param>
        /// <exception cref="Chronos.Exceptions.ChronosException">Thrown when an unknown error occurs.</exception>
        /// <exception cref="Chronos.Exceptions.NotAuthorizedException">Throws this exception when the user is not allowed to use this function.</exception>
        public void EditDivision(AuthHead Head, DivisionEntity Division)
        {
            Head.CommandID = "CHRONOS.MODULES.CORE.FOUNDATION.DIVISIONSERVICE";
            Head.CommandOptionID = "EDITDIVISION";

            if (userService.CanDoIt(Head))
            {
                var varDivision = (from division in dataConn.Divisions where division.CompanyID == Division.CompanyID && division.DivisionID == Division.DivisionID select division).FirstOrDefault();
                if (varDivision != null)
                {
                    varDivision.Name = Division.Name;
                    varDivision.Description = Division.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(); }
        }
Example #5
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(); }
        }
Example #6
0
        /// <summary>
        /// Obtains all available users in the system
        /// </summary>
        /// <param name="Head">Authorization header with current user information</param>
        /// <returns>UserEntity for the supplied ID</returns>
        /// <exception cref="Chronos.Exceptions.NotAuthorizedException">Throws this exception when the user is not allowed to use this function.</exception>
        public List<UserEntity> GetAllUsers(AuthHead Head)
        {
            Head.CommandID = "CHRONOS.MODULES.CORE.SECURITY.USERSERVICE";
            Head.CommandOptionID = "GETALLUSERS";

            if (CanDoIt(Head))
            {
                List<UserEntity> lstReturn = new List<UserEntity>();

                foreach (var varUser in dataConn.Users)
                {
                    UserEntity userEntity = new UserEntity();
                    userEntity.UserID = varUser.UserID;
                    userEntity.Name = varUser.Name;
                    userEntity.EMail = varUser.EMail;
                    userEntity.Password = varUser.Password;

                    lstReturn.Add(userEntity);
                }

                return lstReturn;
            }
            else
            { throw new NotAuthorizedException(); }
        }
Example #7
0
        /// <summary>
        /// Edits the provided user
        /// </summary>
        /// <param name="Head">Authorization header with current user information</param>
        /// <param name="User">User entity with the data to edit</param>
        /// <exception cref="Chronos.Exceptions.ChronosException">Thrown when an unknown error occurs.</exception>
        /// <exception cref="Chronos.Exceptions.NotAuthorizedException">Throws this exception when the user is not allowed to use this function.</exception>
        public void EditUser(AuthHead Head, UserEntity User)
        {
            Head.CommandID = "CHRONOS.MODULES.CORE.SECURITY.USERSERVICE";
            Head.CommandOptionID = "EDITUSER";

            if (CanDoIt(Head))
            {
                var varUser = (from user in dataConn.Users where user.UserID == User.UserID select user).FirstOrDefault();
                if (varUser != null)
                {
                    varUser.Name = User.Name;
                    varUser.Password = User.Password;
                    varUser.EMail = User.EMail;

                    if (dataConn.SaveChanges() <= 0)
                    { throw new ChronosException("It wasn't possible to save the changes in the user."); }
                }
                else
                { throw new DataNotFoundException("The specified user do not exist."); }
            }
            else
            { throw new NotAuthorizedException(); }
        }
Example #8
0
        /// <summary>
        /// Checks if the user is allowed to perform the requested task
        /// </summary>
        /// <param name="Head">Authorization header</param>
        /// <returns>True if user is allowed</returns>
        public bool CanDoIt(AuthHead Head)
        {
            if (Head.DivisionID == "") { Head.DivisionID = "ALL"; }

            bool boolReturn = false;

            boolReturn = (from userRole in dataConn.RelUsersRoles
                          join roles in dataConn.Roles on new { co1 = userRole.CompanyID, co2 = userRole.DivisionID, co3 = userRole.RoleID } equals new { co1 = roles.CompanyID, co2 = roles.DivisionID, co3 = roles.RoleID }
                          join commandOptionsRoles in dataConn.RelCommandOptionsRoles on new { co1 = roles.CompanyID, co2 = roles.DivisionID, co3 = roles.RoleID } equals new { co1 = commandOptionsRoles.CompanyID, co2 = commandOptionsRoles.DivisionID, co3 = commandOptionsRoles.RoleID }
                          join commandOptions in dataConn.CommandOptions on new { co1 = commandOptionsRoles.CommandID, co2 = commandOptionsRoles.CommandOptionID } equals new { co1 = commandOptions.CommandID, co2 = commandOptions.CommandOptionID }
                          where
                            userRole.CompanyID == Head.CompanyID &&
                            userRole.UserID == Head.UserID &&
                            roles.CompanyID == Head.CompanyID &&
                            roles.DivisionID == Head.DivisionID  &&
                            commandOptions.CommandID == Head.CommandID &&
                            commandOptions.CommandOptionID == Head.CommandOptionID &&
                            commandOptions.Status == true
                          select userRole
                ).Count() > 0;

            return boolReturn;
        }