Exemplo n.º 1
0
        public void CreateInvalidRegistration()
        {
            MessengerUtil messengerUtil = new MessengerUtil();
            Registration registration = new Registration();

            messengerUtil.Register(registration);
        }
Exemplo n.º 2
0
        public void CreateValidRegistration()
        {
            MessengerUtil messengerUtil = new MessengerUtil();
            Registration registration = new Registration();
            registration.UserId = 1;
            registration.URI = "FAKE URI";

            messengerUtil.Register(registration);
        }
Exemplo n.º 3
0
        //private TilePushNotificationMessage tilePushNotificationMessage = new TilePushNotificationMessage(MessageSendPriority.High);
        //private ToastPushNotificationMessage toastPushNotificationMessage = new ToastPushNotificationMessage(MessageSendPriority.High);

        public void Register(Registration registration)
        {
            try
            {
                using (CapitalContext context = new CapitalContext())
                {
                    registration.CreationDate = DateTime.Now;

                    ValidationContext valContext = new ValidationContext(this, null, null);
                    var errors = registration.Validate(valContext);
                    if (errors.Count() > 0)
                        throw new ModelException(errors);

                    // Check for existing registration first. 
                    if (context.Registration.Where(x => x.UserId == registration.UserId).FirstOrDefault() != null)
                    {
                        // Update
                        Registration reg = context.Registration.Where(x => x.UserId == registration.UserId).FirstOrDefault();
                        reg.URI = registration.URI;
                    }
                    else
                    {
                        // Insert
                        Registration reg = new Registration();
                        reg.URI = registration.URI;
                        reg.User = registration.User;
                        reg.UserId = registration.UserId;
                        reg.CreationDate = DateTime.Now;
                        context.Registration.Add(reg);
                    }
                    context.SaveChanges();
                }
            }
            catch (ModelException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                LogError(registration, ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }
Exemplo n.º 4
0
 public void Register(Registration registration)
 {
     try
     {
         MessengerUtil messenger = new MessengerUtil();
         messenger.Register(registration);
     }
     catch (ModelException ex)
     {
         CapitalError error = new CapitalError(ex);
         throw new FaultException<CapitalError>(error, error.Message);
     }
     catch (Exception)
     {
         return;
     }
 }