Guest User

Untitled

a guest
Nov 17th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. <ServiceContract>
  2. Public Interface IRegistrationService<OperationContract>
  3. Function GetRegistrationInfo(ByVal composite As RegistrationContract) As ExpirationDays
  4.  
  5. <WebGet>
  6. Public Function GetCustomerRegistrationInfo(composite As RegistrationContract) As ExpirationDays Implements IRegistrationService.GetRegistrationInfo
  7.  
  8. Dim ri as New RetrieveRegistrationInfo
  9. Dim daysLeft = ri.GetDaysLeft(composite)
  10. _logger.Info("Registration Days remaining " & daysLeft)
  11.  
  12. Dim exp As New ExpirationDays
  13. exp.daysLeft = daysLeft
  14. _logger.Info("Exp Days " & exp.daysLeft)
  15. Return exp
  16.  
  17. <DataContract(Name := "DaysLeft")>
  18. Public NotInheritable Class ExpirationDays
  19. <DataMember>
  20. Friend Property daysLeft() As Int32
  21. End Class
  22.  
  23. Shared ReadOnly _logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger
  24. Friend Function GetDaysLeft(ByVal RegContract As RegistrationContract) As Int32
  25.  
  26. Dim db As New CAPRegistrationEntities()
  27. ' Locate the customer
  28. Dim lCustomer = (From customer In db.Customers
  29. Join registration In db.Registrations On customer.Id Equals registration.Customer_Id
  30. Where customer.UserName = RegContract.UserName
  31. Where customer.Password = RegContract.Password
  32. Where customer.Active = True
  33. Where registration.Active = True
  34. Select customer).FirstOrDefault()
  35. Try
  36. ' Was there a customer
  37. If lCustomer IsNot Nothing Then
  38.  
  39. ' Find the registration
  40. Dim reg = (From regis In db.Registrations
  41. Where regis.Key = RegContract.RegKey
  42. Where regis.Customer_Id = lCustomer.Id
  43. Where regis.Active = True
  44. Select regis).Single
  45.  
  46. Dim daysDiff As Int32 = DateDiff(DateInterval.Day, Now, reg.ValidThrough)
  47. _logger.Info(daysDiff)
  48.  
  49. Return daysDiff
  50. End If
  51. Catch dbx As DataException
  52. _logger.Error(dbx)
  53. Catch ex As Exception
  54. _logger.Error(ex)
  55. End Try
  56. Return vbNull
  57. End Function
Add Comment
Please, Sign In to add comment