public async Task ProccessMessage(MessageModelRequest message) { try { bool isValidMessage = _messageValidator.IsValid(message); if (isValidMessage) { //CheckIfOptIn or Out //Return service ID //If OptIn //{ //the new GUID should be the returned service id Subscriber subscriber = await GetUserByMobileNumber(message.MobileNumber); if (IsAlreadySubscribed(Guid.NewGuid(), subscriber.Services)) { //should send to the SMS GetWay } else { subscriber.Services.Add(new ServiceSubscribtion() { IsActive = true, IsPending = true, ServiceId = Guid.NewGuid() }); await Subscribe(subscriber); //Send to the charging system //If the charging is not succeeded //should send to the SMS GetWay failure message } //} //If OptOut //{ //} } else { throw new ValidationException(); } } catch (DatabaseException dbException) { string exceptionMessage = "Mongo database exception "; DatabaseException modifiedException = new DatabaseException(exceptionMessage, dbException.InnerException); throw modifiedException; } catch (ValidationException validationException) { throw validationException; } catch (Exception exception) { throw exception; } }
public async Task ProccessMessage(MessageModelRequest message) { try { bool isValidMessage = _messageValidator.IsValid(message); if (isValidMessage) { //CheckIfOptIn or Out //Return service ID //the new GUID should be the returned service id Guid serviceId = Guid.NewGuid(); Subscriber subscriber = await GetUserByMobileNumber(message.MobileNumber); if (subscriber != null && serviceId != null) { //If OptIn //{ if (IsAlreadySubscribed(serviceId, subscriber.Services)) { //should send to the SMS GetWay } else { if (subscriber.Services == null) { subscriber.Services = new List <ServiceSubscribtion> (); } subscriber.Services.Add(new ServiceSubscribtion() { IsActive = true, IsPending = true, ServiceId = serviceId }); await Subscribe(subscriber); //get the service cost //Send to the charging system //If the charging is not succeeded //should send to the SMS GetWay failure message //If Charging } //} //If OptOut //{ if (!IsAlreadySubscribed(serviceId, subscriber.Services)) { //should send to the SMS GetWay } else { int serviceIndex = subscriber.Services.IndexOf(subscriber.Services.Where(s => s.ServiceId == serviceId).First()); subscriber.Services.ElementAt(serviceIndex).IsActive = false; subscriber.Services.ElementAt(serviceIndex).IsPending = false; subscriber.Services.ElementAt(serviceIndex).UnsubscribtionDate = DateTime.UtcNow; await UnSubscribe(subscriber); } //} } else { throw new ArgumentNullException("Invalid user or service"); } } else { throw new ValidationException(); } } catch (DatabaseException dbException) { string exceptionMessage = "Mongo database exception "; DatabaseException modifiedException = new DatabaseException(exceptionMessage, dbException.InnerException); throw modifiedException; } catch (ValidationException validationException) { throw validationException; } catch (ArgumentNullException argNullExcepton) { throw argNullExcepton; } catch (Exception exception) { throw exception; } }