Beispiel #1
0
        public override void HandleMessage(BrokeredMessage msg)
        {
            UserServiceWorker worker = new UserServiceWorker();

            // cast the message's body to our payload
            this.payload = msg.GetBody <UpdateUsersForStoreMessage>();
            // Symmetric difference craziness
            Dictionary <int, User> userDictionary = worker.GetDictionaryOfUsersByStoreCode(this.payload.storeid);
            // Make the JSON call to get the list of users for the store.
            List <User> userlist = FLJsonAdapter.getInstance().GetUsersByStore(this.payload.storeid);

            // update the DB with the list of users
            foreach (User user in userlist)
            {
                if (user.id == 0)
                {
                    // This means the user wasn't found in the DB, we have to add it.
                    worker.AddUser(user);
                }
                else
                {
                    // Already in the DB, update
                    worker.UpdateUser(user);
                    // remove from dictionary to create difference
                    userDictionary.Remove(user.id);
                }
            }
            // delete all users left in the dictionary
            foreach (KeyValuePair <int, User> kvp in userDictionary)
            {
                worker.DeleteUser(kvp.Value);
            }
            // complete the message
            msg.Complete();
        }
Beispiel #2
0
 public override void HandleMessage(BrokeredMessage msg)
 {
     this.customer = msg.GetBody <Customers>();
     if (this.customer.CustomerGuid == null)
     {
         // we need to figure out if there's a pre-existing customer by this name
         Customers theirCustomer = FLJsonAdapter.getInstance().GetCustomerByName(this.customer.Name());
         if (theirCustomer != null)
         {
             // they've got one.
             this.customer.CustomerGuid = theirCustomer.CustomerGuid;
             // Update customer data using PUT
             FLJsonAdapter.getInstance().UpdateCustomer(this.customer);
         }
         else
         {
             // if not, create a guid for this one.
             this.customer.CustomerGuid = Guid.NewGuid().ToString();
             // Create customer data using POST
             FLJsonAdapter.getInstance().CreateCustomer(this.customer);
         }
         // We need to let our DB know what the right GUID is.
         CustomerServiceWorker csw = new CustomerServiceWorker();
         csw.CustomerUpdateOrAddLocal(this.customer);
     }
     //
     msg.Complete();
 }
Beispiel #3
0
 public override void HandleMessage(BrokeredMessage msg)
 {
     this.customer = msg.GetBody <Customers>();
     if (this.customer.CustomerGuid != null)
     {
         // Update customer data using PUT
         FLJsonAdapter.getInstance().UpdateCustomer(this.customer);
     }
     //
     msg.Complete();
 }