예제 #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();
        }
        // PUT api/values/5
        public Dictionary <String, Boolean> Put(Dictionary <String, dynamic> dict)
        {
            Dictionary <String, Boolean> result = this.GetSimpleSuccessResponse();

            try
            {
                UpdateUsersForStoreMessage msg = new UpdateUsersForStoreMessage();
                msg.storeid = dict["storeid"];
                msg.EnqueueSelfAsMessage(BaseApiController.protectedQueue);
            }
            catch (Exception e)
            {
                result["success"] = false;
                throw e;
            }
            return(result);
        }