Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ServiceContract>
- Public Interface IRegistrationService<OperationContract>
- Function GetRegistrationInfo(ByVal composite As RegistrationContract) As ExpirationDays
- <WebGet>
- Public Function GetCustomerRegistrationInfo(composite As RegistrationContract) As ExpirationDays Implements IRegistrationService.GetRegistrationInfo
- Dim ri as New RetrieveRegistrationInfo
- Dim daysLeft = ri.GetDaysLeft(composite)
- _logger.Info("Registration Days remaining " & daysLeft)
- Dim exp As New ExpirationDays
- exp.daysLeft = daysLeft
- _logger.Info("Exp Days " & exp.daysLeft)
- Return exp
- <DataContract(Name := "DaysLeft")>
- Public NotInheritable Class ExpirationDays
- <DataMember>
- Friend Property daysLeft() As Int32
- End Class
- Shared ReadOnly _logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger
- Friend Function GetDaysLeft(ByVal RegContract As RegistrationContract) As Int32
- Dim db As New CAPRegistrationEntities()
- ' Locate the customer
- Dim lCustomer = (From customer In db.Customers
- Join registration In db.Registrations On customer.Id Equals registration.Customer_Id
- Where customer.UserName = RegContract.UserName
- Where customer.Password = RegContract.Password
- Where customer.Active = True
- Where registration.Active = True
- Select customer).FirstOrDefault()
- Try
- ' Was there a customer
- If lCustomer IsNot Nothing Then
- ' Find the registration
- Dim reg = (From regis In db.Registrations
- Where regis.Key = RegContract.RegKey
- Where regis.Customer_Id = lCustomer.Id
- Where regis.Active = True
- Select regis).Single
- Dim daysDiff As Int32 = DateDiff(DateInterval.Day, Now, reg.ValidThrough)
- _logger.Info(daysDiff)
- Return daysDiff
- End If
- Catch dbx As DataException
- _logger.Error(dbx)
- Catch ex As Exception
- _logger.Error(ex)
- End Try
- Return vbNull
- End Function
Add Comment
Please, Sign In to add comment