Example #1
0
        /// <summary>
        /// Update existing sms
        /// </summary>
        /// <param name="sms"></param>
        public void Update(SmsDomain sms)
        {
            var smsDb = _context.Sms.FirstOrDefault(x => x.SmsId == sms.Id);

            smsDb.FromDomainModel(sms);
            _context.SaveChanges();
        }
Example #2
0
 /// <summary>
 /// Update an sms
 /// </summary>
 /// <param name="sms"></param>
 public void UpdateSms(SmsDomain sms)
 {
     ValidateSmsModel(sms);
     ValidationHelper.GreaterThanZero(sms.Id, NotificationMessages.SmsInvalidId);
     ValidationHelper.NotNull(_smsRepository.GetById(sms.Id), NotificationMessages.SmsWithIdDoesNotExists);
     _smsRepository.Update(sms);
 }
Example #3
0
 private void ValidateSmsModel(SmsDomain sms)
 {
     ValidationHelper.NotNull(sms, NotificationMessages.SmsNotProvided);
     ValidationHelper.GreaterThanZero(sms.NotificationId, NotificationMessages.SmsInvalidNotificationId);
     ValidationHelper.NotNull(_notificationRepository.GetById(sms.NotificationId), NotificationMessages.SmsNotificationWithIdDoesNotExists);
     ValidationHelper.IsPhoneNumberValid(sms.From, NotificationMessages.SmsInvalidSenderPhoneNumberFormat);
     ValidationHelper.IsPhoneNumberValid(sms.PhoneNumber, NotificationMessages.SmsInvalidPhoneNumberFormat);
 }
Example #4
0
        /// <summary>
        /// Add new sms
        /// </summary>
        /// <param name="sms"></param>
        /// <returns></returns>
        public int Add(SmsDomain sms)
        {
            var smsDb = new Sms().FromDomainModel(sms);

            _context.Sms.Add(smsDb);
            _context.SaveChanges();
            return(smsDb.SmsId);
        }
Example #5
0
        /// <summary>
        /// Delete sms
        /// </summary>
        /// <param name="Id"></param>
        public void DeleteSms(int Id)
        {
            SmsDomain smsDomain = _smsRepository.GetById(Id);

            if (smsDomain == null)
            {
                throw new NsiArgumentException(NotificationMessages.SmsWithIdDoesNotExists);
            }
            _smsRepository.Delete(smsDomain);
        }
Example #6
0
        /// <summary>
        /// Delete an sms
        /// </summary>
        /// <param name="sms"></param>
        public void Delete(SmsDomain sms)
        {
            var smsDb = _context.Sms.First(x => x.SmsId == sms.Id);

            if (smsDb != null)
            {
                smsDb.FromDomainModel(sms);
                _context.Sms.Remove(smsDb);
                _context.SaveChanges();
            }
        }
Example #7
0
        public static Sms FromDomainModel(this Sms obj, SmsDomain smsDomain)
        {
            if (obj == null)
            {
                obj = new Sms();
            }

            obj.SmsId          = smsDomain.Id;
            obj.PhoneNumber    = smsDomain.PhoneNumber;
            obj.From           = smsDomain.From;
            obj.NotificationId = smsDomain.NotificationId;
            return(obj);
        }
Example #8
0
        public IHttpActionResult AddSms(AddSmsRequest request)
        {
            request.ValidateNotNull();
            SmsDomain smsDomain = new SmsDomain()
            {
                PhoneNumber    = request.PhoneNumber,
                From           = request.From,
                NotificationId = request.NotificationId
            };

            return(Ok(new AddSmsResponse()
            {
                Data = _smsManipulation.AddSms(smsDomain),
                Success = Common.Enumerations.ResponseStatus.Succeeded
            }));
        }
Example #9
0
        public IHttpActionResult UpdateSms(UpdateSmsRequest request)
        {
            request.ValidateNotNull();
            SmsDomain smsDomain = _smsManipulation.GetSmsById(request.Id);

            if (smsDomain == null)
            {
                return(NotFound());
            }

            smsDomain.PhoneNumber    = request.PhoneNumber;
            smsDomain.From           = request.From;
            smsDomain.NotificationId = request.NotificationId;
            _smsManipulation.UpdateSms(smsDomain);

            return(Ok(new UpdateSmsResponse()
            {
                Success = Common.Enumerations.ResponseStatus.Succeeded
            }));
        }
Example #10
0
 /// <summary>
 /// Add an sms
 /// </summary>
 /// <param name="sms"></param>
 /// <returns></returns>
 public int AddSms(SmsDomain sms)
 {
     ValidateSmsModel(sms);
     return(_smsRepository.Add(sms));
 }