public bool CreateSms(Sms sms, bool isInbound)
        {
            Check.If(sms).IsNotNull();

            if (sms.IsInvalid())
                return false;

            sms.IsInbound = isInbound;

            sms.GenerateReference(_referenceGenerator);

            return _smsRepository.CreateSms(sms);
        }
        public bool CreateSms(Sms sms)
        {
            using (var context = new CommunicationsContext(_databaseSettings.ConnectionString))
            {

                //ensure phone numbers are valid
                if (!sms.To.IsValidPhoneNumber() || !sms.From.IsValidPhoneNumber())
                    return false;

                //create phone numbers for to or from (this wont create duplicates)
                _phoneNumberService.CreatePhoneNumber(sms.To);
                _phoneNumberService.CreatePhoneNumber(sms.From);

                //use newly created (or existing) Phone Number objects in the context for to and from
                sms.From =
                    context.PhoneNumbers.FirstOrDefault(x => x.Number == sms.From.Number);
                sms.To =
                    context.PhoneNumbers.FirstOrDefault(x => x.Number == sms.To.Number);

                context.Sms.Add(sms);

                return context.SaveChanges() > 0;
            }
        }
 public bool UpdateSms(string smsReference, Sms sms)
 {
     Check.If(smsReference).IsNotNullOrEmpty();
     Check.If(sms).IsNotNull();
     return _smsRepository.UpdateSms(smsReference, sms);
 }
        public bool UpdateSms(string smsReference, Sms sms)
        {
            using (var context = new CommunicationsContext(_databaseSettings.ConnectionString))
            {
                var currentSms = context.Sms.FirstOrDefault(x => x.SmsReference == smsReference);

                if (currentSms == null) return false;

                _smsMapper.Map(sms, currentSms);

                return context.SaveChanges() > 0;
            }
        }