public void AddMessageType(MessageType messageType)
        {
            logger.logInfo("Attempting to add a new message type ... ");

            var validationResult = Validation.Validate <MessageType>(messageType);

            if (!validationResult.IsValid)
            {
                String message = "Invalid fields for message type " + messageType.MessageTypeName;
                logger.logError(message);
                throw new ValidationException(message);
            }

            MessageType oldMessageType = GetMessageTypeByName(messageType.MessageTypeName);

            if (oldMessageType != null)
            {
                String message = "Message Type " + messageType.MessageTypeName + " is already registered.";
                logger.logError(message);
                throw new DuplicateException(message);
            }

            DataMapperFactoryMethod.GetCurrentFactory().MessageTypeFactory.AddMessageType(messageType);
            logger.logInfo("Add message type operation ended.");
        }
        public void AddCurrencyRate(CurrencyRate currencyRate, Currency currency)
        {
            logger.logInfo("Attempting to add a new currency rate ... ");

            var validationResult = Validation.Validate <CurrencyRate>(currencyRate);

            if (!validationResult.IsValid)
            {
                String message = "Invalid fields for currency rate";
                logger.logError(message);
                throw new ValidationException(message);
            }

            CurrencyRate oldCurrencyRate = GetCurrencyRateByMonth(currencyRate.Valability, currencyRate.Currency);

            if (oldCurrencyRate != null)
            {
                String message = "Currency Rate is already registered.";
                logger.logError(message);
                throw new DuplicateException(message);
            }

            DataMapperFactoryMethod.GetCurrentFactory().CurrencyRateFactory.AddCurrencyRate(currencyRate, currency);
            logger.logInfo("Add currency rate type operation ended.");
        }
        public void AddSubscriptionType(SubscriptionType subscriptionType)
        {
            logger.logInfo("Attempting to add a new subscription type ... ");

            var validationResult = Validation.Validate <SubscriptionType>(subscriptionType);

            if (!validationResult.IsValid)
            {
                String message = "Invalid fields for subscription type " + subscriptionType.SubscriptionTypeName;
                logger.logError(message);
                throw new ValidationException(message);
            }

            SubscriptionType oldSubscriptionType = GetSubscriptionTypeByName(subscriptionType.SubscriptionTypeName);

            if (oldSubscriptionType != null)
            {
                String message = "Subscription Type " + subscriptionType.SubscriptionTypeName + " is already registered.";
                logger.logError(message);
                throw new DuplicateException(message);
            }

            DataMapperFactoryMethod.GetCurrentFactory().SubscriptionTypeFactory.AddSubscriptionType(subscriptionType);
            logger.logInfo("Add subscription type operation ended.");
        }
        void ICustomerService.AddCustomer(Customer customer)
        {
            logger.logInfo("Attempting to add a new customer ... ");

            var validationResult = Validation.Validate <Customer>(customer);

            if (!validationResult.IsValid || !customer.ValidateCNP())
            {
                String message = "Invalid fields for customer " + customer.FirstName + " " + customer.LastName;
                logger.logError(message);
                throw new ValidationException(message);
            }

            Customer oldCustomer = GetCustomerByCNP(customer.CNP);

            if (oldCustomer != null)
            {
                String message = "Customer " + customer.FirstName + " " + customer.LastName + " is already registered.";
                logger.logError(message);
                throw new DuplicateException(message);
            }

            DataMapperFactoryMethod.GetCurrentFactory().CustomerFactory.AddCustomer(customer);
            logger.logInfo("Add customer operation ended.");
        }
Example #5
0
        public void AddCurrency(Currency currency)
        {
            logger.logInfo("Attempting to add a new currency ... ");

            var validationResult = Validation.Validate <Currency>(currency);

            if (!validationResult.IsValid)
            {
                String message = "Invalid fields for currency " + currency.CurrencyName;
                logger.logError(message);
                throw new ValidationException(message);
            }

            Currency oldCurrency = GetCurrencyByName(currency.CurrencyName);

            if (oldCurrency != null)
            {
                String message = "Currency " + currency.CurrencyName + " is already registered.";
                logger.logError(message);
                throw new DuplicateException(message);
            }

            DataMapperFactoryMethod.GetCurrentFactory().CurrencyFactory.AddCurrency(currency);
            logger.logInfo("Add currency type operation ended.");
        }
Example #6
0
        public void UpdateSubscriptionEndDate(string subName, DateTime endDate)
        {
            logger.logInfo("Attempting to edit subscription end date ... ");
            Subscription subscription = GetSubscriptionByName(subName);

            if (subscription == null)
            {
                String message = "The subscription does not exist.";
                logger.logError(message);
                throw new EntityDoesNotExistException(message);
            }
            subscription.EndDate = endDate;
            var validationResult = Validation.Validate <Subscription>(subscription);

            if (!validationResult.IsValid || !subscription.CheckDateValidity())
            {
                String message = "Invalid fields for subscription";
                logger.logError(message);
                throw new ValidationException(message);
            }

            // change availability to
            if (subscription.Available == false)
            {
                subscription.Available = true;
                DataMapperFactoryMethod.GetCurrentFactory().SubscriptionFactory.UpdateSubscriptionAvailability(subscription);
            }

            DataMapperFactoryMethod.GetCurrentFactory().SubscriptionFactory.UpdateSubscriptionEndDate(subscription);
            logger.logInfo("Edit subscription end date operation ended.");
        }
 public Message GetMessageById(int id, MessageType messageType)
 {
     logger.logInfo("Attempting to retrieve message by id ...");
     if (id == 0)
     {
         String messageEr = "ID field is invalid!";
         logger.logError(messageEr);
         throw new ValidationException(messageEr);
     }
     logger.logInfo("Retrieve message operation ended.");
     return(DataMapperFactoryMethod.GetCurrentFactory().MessageFactory.GetMessageById(id, messageType));
 }
 public CurrencyRate GetCurrencyRateByMonth(string currencyRateMonth, Currency currency)
 {
     logger.logInfo("Attempting to retrieve currency rate ...");
     if (currencyRateMonth.Equals(""))
     {
         String message = "Currency Rate field is null!";
         logger.logError(message);
         throw new ValidationException(message);
     }
     logger.logInfo("Retrieve Currency Rate operation ended.");
     return(DataMapperFactoryMethod.GetCurrentFactory().CurrencyRateFactory.GetCurrencyRateByMonth(currencyRateMonth, currency));
 }
 public void DropCurrencyRate(string currencyRateMonth, Currency currency)
 {
     logger.logInfo("Attempting to drop currency rate ...");
     if (currencyRateMonth.Equals(""))
     {
         String message = "Currency Rate valability field is null!";
         logger.logError(message);
         throw new ValidationException(message);
     }
     DataMapperFactoryMethod.GetCurrentFactory().CurrencyRateFactory.DropCurrencyRate(currencyRateMonth, currency);
     logger.logInfo("Drop currency rate operation ended.");
 }
Example #10
0
 public void DropCurrency(string currencyName)
 {
     logger.logInfo("Attempting to drop currency ...");
     if (currencyName.Equals(""))
     {
         String message = "Currency Name field is null!";
         logger.logError(message);
         throw new ValidationException(message);
     }
     DataMapperFactoryMethod.GetCurrentFactory().CurrencyFactory.DropCurrency(currencyName);
     logger.logInfo("Drop currency operation ended.");
 }
Example #11
0
 public Currency GetCurrencyByName(string currencyName)
 {
     logger.logInfo("Attempting to retrieve currency by name ...");
     if (currencyName.Equals(""))
     {
         String message = "Currency Name field is null!";
         logger.logError(message);
         throw new ValidationException(message);
     }
     logger.logInfo("Retrieve Currency by Name operation ended.");
     return(DataMapperFactoryMethod.GetCurrentFactory().CurrencyFactory.GetCurrencyByName(currencyName));
 }
 public void DropSubscriptionType(string subscriptionTypeName)
 {
     logger.logInfo("Attempting to drop subscription type ...");
     if (subscriptionTypeName.Equals(""))
     {
         String message = "Subscription Type Name field is null!";
         logger.logError(message);
         throw new ValidationException(message);
     }
     DataMapperFactoryMethod.GetCurrentFactory().SubscriptionTypeFactory.DropSubscriptionType(subscriptionTypeName);
     logger.logInfo("Drop subscription type operation ended.");
 }
 public void DropMessage(int id, MessageType messageType)
 {
     logger.logInfo("Attempting to drop message ...");
     if (id == 0)
     {
         String messageEr = "Id field is null!";
         logger.logError(messageEr);
         throw new ValidationException(messageEr);
     }
     DataMapperFactoryMethod.GetCurrentFactory().MessageFactory.DropMessage(id, messageType);
     logger.logInfo("Drop message operation ended.");
 }
 public SubscriptionType GetSubscriptionTypeByName(string subscriptionTypeName)
 {
     logger.logInfo("Attempting to retrieve subscription type by name ...");
     if (subscriptionTypeName.Equals(""))
     {
         String message = "Subscription Type Name field is null!";
         logger.logError(message);
         throw new ValidationException(message);
     }
     logger.logInfo("Retrieve Subscription Type by Name operation ended.");
     return(DataMapperFactoryMethod.GetCurrentFactory().SubscriptionTypeFactory.GetSubscriptionTypeByName(subscriptionTypeName));
 }
 public void DropCustomerByCNP(String cnp)
 {
     logger.logInfo("Attempting to drop customer ...");
     if (cnp.Equals(""))
     {
         String message = "CNP field is null!";
         logger.logError(message);
         throw new ValidationException(message);
     }
     DataMapperFactoryMethod.GetCurrentFactory().CustomerFactory.DropCustomerByCNP(cnp);
     logger.logInfo("Drop customer operation ended.");
 }
 public Customer GetCustomerByCNP(String cnp)
 {
     logger.logInfo("Attempting to retrieve customer by CNP ...");
     if (cnp.Equals(""))
     {
         String message = "CNP field is null!";
         logger.logError(message);
         throw new ValidationException(message);
     }
     logger.logInfo("Retrieve customer operation ended.");
     return(DataMapperFactoryMethod.GetCurrentFactory().CustomerFactory.GetCustomerByCNP(cnp));
 }
        public void UpdateIncludedMessages(Message message)
        {
            logger.logInfo("Attempting to edit message included messages ...");
            var validationResult = Validation.Validate <Message>(message);

            if (!validationResult.IsValid)
            {
                String messageEr = "Invalid fields for message.";
                logger.logError(messageEr);
                throw new ValidationException(messageEr);
            }
            DataMapperFactoryMethod.GetCurrentFactory().MessageFactory.UpdateIncludedMessages(message);
        }
        public void UpdateExtraCharge(Minute minute)
        {
            logger.logInfo("Attempting to edit minute extra charge ...");
            var validationResult = Validation.Validate <Minute>(minute);

            if (!validationResult.IsValid)
            {
                String message = "Invalid fields for minute.";
                logger.logError(message);
                throw new ValidationException(message);
            }
            DataMapperFactoryMethod.GetCurrentFactory().MinuteFactory.UpdateExtraCharge(minute);
        }
Example #19
0
        public void UpdateSubscriptionAvailability(string subName, bool av)
        {
            logger.logInfo("Attempting to edit subscription availability ... ");
            Subscription subscription = GetSubscriptionByName(subName);

            if (subscription == null)
            {
                String message = "The subscription does not exist.";
                logger.logError(message);
                throw new EntityDoesNotExistException(message);
            }
            subscription.Available = av;
            DataMapperFactoryMethod.GetCurrentFactory().SubscriptionFactory.UpdateSubscriptionAvailability(subscription);
            logger.logInfo("Edit subscription availability operation ended.");
        }
        public void AddMessage(Message message, MessageType messageType)
        {
            logger.logInfo("Attempting to add a new message ... ");

            var validationResult = Validation.Validate <Message>(message);

            if (!validationResult.IsValid)
            {
                String messageErr = "Invalid fields for message.";
                logger.logError(messageErr);
                throw new ValidationException(messageErr);
            }

            DataMapperFactoryMethod.GetCurrentFactory().MessageFactory.AddMessage(message, messageType);
            logger.logInfo("Add message operation ended.");
        }
Example #21
0
        public void DropSubscription(String subName, SubscriptionType subscriptionType, Currency currency)
        {
            logger.logInfo("Attempting to drop subscription ...");
            if (subName.Equals(""))
            {
                String message = "Name field is null!";
                logger.logError(message);
                throw new ValidationException(message);
            }
            Subscription subscription = GetSubscriptionByName(subName);

            if (subscription == null)
            {
                String message = "The subscription does not exist.";
                logger.logError(message);
                throw new EntityDoesNotExistException(message);
            }
            DataMapperFactoryMethod.GetCurrentFactory().SubscriptionFactory.DropSubscriptionByName(subscription, subscriptionType, currency);
            logger.logInfo("Drop subscription operation ended.");
        }
Example #22
0
        public void DropContract(string contractName, Customer customer, Subscription subscription)
        {
            logger.logInfo("Attempting to drop contract ...");
            if (contractName.Equals(""))
            {
                String message = "Name field is null!";
                logger.logError(message);
                throw new ValidationException(message);
            }
            Contract contract = GetContractByName(contractName);

            if (contract == null)
            {
                String message = "The contract does not exist.";
                logger.logError(message);
                throw new EntityDoesNotExistException(message);
            }
            DataMapperFactoryMethod.GetCurrentFactory().ContractFactory.DropContractByName(contract, customer, subscription);
            logger.logInfo("Drop contract operation ended.");
        }
Example #23
0
        public void UpdateSubscriptionPrice(String subName, Double price)
        {
            logger.logInfo("Attempting to edit subscription price ... ");
            Subscription subscription = GetSubscriptionByName(subName);

            if (subscription == null)
            {
                String message = "The subscription does not exist.";
                logger.logError(message);
                throw new EntityDoesNotExistException(message);
            }

            // check that subscription has expired
            if (subscription.EndDate.CompareTo(DateTime.Now) > 0)
            {
                String message = "Subscription it's still valid. Cannont update price!";
                logger.logError(message);
                throw new ValidationException(message);
            }

            // check that subscription is not available
            if (subscription.Available == true)
            {
                String message = "Subscription it's still valid. Cannont update price!";
                logger.logError(message);
                throw new ValidationException(message);
            }

            subscription.Price = price;
            var validationResult = Validation.Validate <Subscription>(subscription);

            if (!validationResult.IsValid)
            {
                String message = "Invalid fields for subscription";
                logger.logError(message);
                throw new ValidationException(message);
            }
            DataMapperFactoryMethod.GetCurrentFactory().SubscriptionFactory.UpdateSubscriptionPrice(subscription);
            logger.logInfo("Edit subscription price operation ended.");
        }
        public void UpdateAdress(String cnp, string adress)
        {
            logger.logInfo("Attempting to edit customer adress ... ");
            Customer customer = GetCustomerByCNP(cnp);

            if (customer == null)
            {
                String message = "The customer with CNP " + cnp + " does not exist.";
                logger.logError(message);
                throw new EntityDoesNotExistException(message);
            }
            customer.Adress = adress;
            var validationResult = Validation.Validate <Customer>(customer);

            if (!validationResult.IsValid || !customer.ValidateCNP())
            {
                String message = "Invalid fields for customer " + customer.FirstName + " " + customer.LastName;
                logger.logError(message);
                throw new ValidationException(message);
            }
            DataMapperFactoryMethod.GetCurrentFactory().CustomerFactory.UpdateAdress(customer);
            logger.logInfo("Edit customer adress operation ended.");
        }
Example #25
0
        public void UpdateContractEndDate(string contractName, DateTime endDate)
        {
            logger.logInfo("Attempting to edit contract end date ... ");
            Contract contract = GetContractByName(contractName);

            if (contract == null)
            {
                String message = "The contract does not exist.";
                logger.logError(message);
                throw new EntityDoesNotExistException(message);
            }
            contract.EndDate = endDate;
            var validationResult = Validation.Validate <Contract>(contract);

            if (!validationResult.IsValid || !contract.CheckDateValidity())
            {
                String message = "Invalid fields for contract";
                logger.logError(message);
                throw new ValidationException(message);
            }
            DataMapperFactoryMethod.GetCurrentFactory().ContractFactory.UpdateContractEndDate(contract);
            logger.logInfo("Edit contract end date operation ended.");
        }
Example #26
0
        public void UpdateSubscriptionFixedPeriod(string subName, int period)
        {
            logger.logInfo("Attempting to edit subscription period ... ");
            Subscription subscription = GetSubscriptionByName(subName);

            if (subscription == null)
            {
                String message = "The subscription does not exist.";
                logger.logError(message);
                throw new EntityDoesNotExistException(message);
            }
            subscription.FixedPeriod = period;
            var validationResult = Validation.Validate <Subscription>(subscription);

            if (!validationResult.IsValid)
            {
                String message = "Invalid fields for subscription";
                logger.logError(message);
                throw new ValidationException(message);
            }
            DataMapperFactoryMethod.GetCurrentFactory().SubscriptionFactory.UpdateSubscriptionFixedPeriod(subscription);
            logger.logInfo("Edit subscription period operation ended.");
        }
Example #27
0
        public void AddContract(Contract contract, Customer customer, Subscription subscription)
        {
            logger.logInfo("Attempting to add a new contract ... ");

            Contract oldContract = GetContractByName(contract.ContractName);

            if (oldContract != null)
            {
                String message = "Contract already exists.";
                logger.logError(message);
                throw new DuplicateException(message);
            }

            // Deduct age
            if (DeductCustomerAge(customer.CNP) < 18)
            {
                throw new ValidationException("Customer must be at least 18 yo!");
            }

            // Price if is missing
            if (contract.Price == 0)
            {
                contract.Price = subscription.Price;
            }

            var validationResult = Validation.Validate <Contract>(contract);

            if (!validationResult.IsValid || !contract.CheckDateValidity())
            {
                String message = "Invalid fields for Contract.";
                logger.logError(message);
                throw new ValidationException(message);
            }

            DataMapperFactoryMethod.GetCurrentFactory().ContractFactory.AddContract(contract, customer, subscription);
            logger.logInfo("Add contract operation ended.");
        }