Exemple #1
0
        public ClientDTO AddNewClient(ClientDTO newClient)
        {
            if (string.IsNullOrEmpty(newClient.Name))
            {
                Log.Logger.Error(" => [AddNewClient] The App found an ERROR -> The name field must be filled ");
                throw new EmptyNameException("The name field must be filled.");
            }
            if (string.IsNullOrEmpty(newClient.Ci))
            {
                Log.Logger.Error(" => [AddNewClient] The App found an ERROR -> The CI field must be filled ");
                throw new EmptyCiException("The CI field must be filled.");
            }
            if (!(string.IsNullOrEmpty(newClient.Ranking)))
            {
                if (System.Convert.ToInt32(newClient.Ranking) < 0 || System.Convert.ToInt32(newClient.Ranking) > 5)
                {
                    Log.Logger.Error(" => [AddNewClient] The App found an ERROR -> The Ranking value is not correct ");
                    throw new RankingOutOfBoundException("Ranking must be between 0 and 5.");
                }
            }

            // Mappers => function: client.FromDTOtoEntity
            Client client = new Client()
            {
                Name    = newClient.Name,
                Ci      = newClient.Ci,
                Address = newClient.Address,
                Phone   = newClient.Phone,
                Ranking = newClient.Ranking,
                Code    = GenerateCodeLetters(newClient.Name) + "-" + newClient.Ci
            };

            List <ClientDTO> tmp        = DTOUtil.MapClientDTOList(_clientTableDB.GetAll());
            ClientDTO        tmp_client = tmp.Find(x => x.Code.Contains(client.Code));

            if (tmp_client != null)
            {
                Log.Logger.Error(" => [AddNewClient] The App found an ERROR -> The Client Code Already Exists ");
                throw new CodeAlreadyExistsException("Invalid code, it already exists, please enter another one");
            }

            Log.Logger.Information(" => The Client : {0} was added to the Database ", client.Code);

            // Add to DB
            return(DTOUtil.MapClientDTO(_clientTableDB.AddNewClient(client)));
        }
Exemple #2
0
        public List <RankingDTO> GetRankings()
        {
            // Retrieve all clients from database
            List <Client> allClients = _clientTableDB.GetAll();

            List <RankingDTO> rankingsToAssign = GetEmptyRankings();

            // Process all clients
            foreach (Client client in allClients)
            {
                // Asign Cient to a Group
                assignToRanking(rankingsToAssign, client);
            }
            Log.Logger.Information(" => The App gets a Client Ranking List ");

            return(rankingsToAssign);
        }