Ejemplo n.º 1
0
        private List <int> GetListOfModifiedRecipients()
        {
            _logger.Info($"Started creating list of recipients to update.");

            List <int> output = new List <int>();

            foreach (var item in RecipientsList)
            {
                //get original item with the same id
                SMSrecipientDefinition unmodifiedItem = _originalList.Where(x => x.Identity == item.Identity).ToList().First();

                if (unmodifiedItem == null)
                {
                    _logger.Error($"There is no SMS recipient in the orignal list with the identity of: {item.Identity}.");
                }
                else
                {
                    //check for differences
                    if (item.FirstName != unmodifiedItem.FirstName || item.LastName != unmodifiedItem.LastName ||
                        item.AreaCode != unmodifiedItem.AreaCode || item.PhoneNumber != unmodifiedItem.PhoneNumber)
                    {
                        output.Add(item.Identity);
                    }
                }
            }

            _logger.Info($"Amount of SMS recipients with changes: {output.Count}, total amount of recipients: {RecipientsList.Count}.");

            return(output);
        }
        public bool DeleteExistingSMSrecipient(int identity)
        {
            _logger.Info($"Method for deleting existing SMS recipient from DB fired.");

            try
            {
                SMSrecipientDefinition definition = _realm.All <SMSrecipientDefinition>().Single(x => x.Identity == identity);

                using (var trans = _realm.BeginWrite())
                {
                    _realm.Remove(definition);
                    trans.Commit();
                }

                _logger.Info($"Deleting of SMS recipient with ID = {identity} successfull.");

                DeleteRecipientFromGroups(identity);

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error($"Error while trying to delete existing SMS recipient from DB: {ex.Message}.");
                return(false);
            }
        }
Ejemplo n.º 3
0
        private void GetSMSrecipientsDefinitions()
        {
            //create recipients reader instance
            SMSrecipientReader reader = new SMSrecipientReader(_realmProvider);

            //read all rcipients from DB
            List <SMSrecipientDefinition> allRecipients = reader.GetAllActualRecipients();

            //read all recipients to export definitions
            foreach (var item in _recipientsIDList)
            {
                try
                {
                    //convert realm DB model into export model
                    SMSrecipientDefinition definition = allRecipients.Where(x => x.Identity == item).First();

                    SMSrecipientDefinitionExportModel exportModel = new SMSrecipientDefinitionExportModel()
                    {
                        Identity    = definition.Identity,
                        FirstName   = definition.FirstName,
                        LastName    = definition.LastName,
                        AreaCode    = definition.AreaCode,
                        PhoneNumber = definition.PhoneNumber,
                        NoErrors    = true,
                    };

                    _recipientsList.Add(exportModel);
                }
                catch (Exception ex)
                {
                    var logger = NLog.LogManager.GetCurrentClassLogger();
                    logger.Error($"Error while searching for {item} identity in actual SMS recipients group. Error: {ex.Message}.");
                }
            }
        }
Ejemplo n.º 4
0
        public bool ModifySMSrecipient(int identity, string firstName, string lastName,
                                       int areaCode, long phoneNumber)
        {
            _logger.Info($"Method for modification of SMS recipient fired. Identity = {identity}.");

            try
            {
                SMSrecipientDefinition definition = _realm.All <SMSrecipientDefinition>().Single(x => x.Identity == identity);

                using (var trans = _realm.BeginWrite())
                {
                    definition.FirstName   = firstName;
                    definition.LastName    = lastName;
                    definition.AreaCode    = areaCode;
                    definition.PhoneNumber = phoneNumber;
                    trans.Commit();
                }

                _logger.Info($" Changing definition of SMS recipient with ID: {identity} successfull.");

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error($"Error while trying to modify existing SMS recipient: {ex.Message}.");
                return(false);
            }
        }
Ejemplo n.º 5
0
        private bool SaveModificationdOfOneRecipientToDB(int identity)
        {
            _logger.Info($"Method for updating one SMS recipient definition started. Identity = {identity}.");

            SMSrecipientDefinition definition = RecipientsList.Where(x => x.Identity == identity).ToList().First();

            SMSrecipientModifier modifier = new SMSrecipientModifier(_realmProvider);

            return(modifier.ModifySMSrecipient(identity, definition.FirstName, definition.LastName, definition.AreaCode, definition.PhoneNumber));
        }
Ejemplo n.º 6
0
        public void AddRecipientToGroup(int identity)
        {
            _logger.Info($"Adding new recipient to current group. Recipient ID: {identity}.");

            //check if this item is already added
            if (GroupRecipientsList.Where(x => x.Identity == identity).Count() == 0)
            {
                SMSrecipientDefinition item = AvailableSMSrecipientsList.Where(x => x.Identity == identity).ToList().First();
                GroupRecipientsList.Add(item);
            }
        }
Ejemplo n.º 7
0
        public void RemoveRecipientFromGroup(int identity)
        {
            _logger.Info($"Removing recipient from current group. Recipient ID: {identity}.");

            if (GroupRecipientsList.Count >= 2)
            {
                SMSrecipientDefinition item = GroupRecipientsList.Where(x => x.Identity == identity).ToList().First();
                GroupRecipientsList.Remove(item);
            }
            else
            {
                _logger.Info($"The last recipient from recipients group cannot be deleted.");
                MessageBox.Show($"You cannot delete last recipient from the group. The SMS recipients group has to consists of at least one recipient.",
                                "Information", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }