public void SaveList(IEnumerable <T> list, Request request = null)
        {
            if (request != null)
            {
                if (request.LockBy != null)
                {
                    Request editRequest = CreateEditRequest(request);

                    EditModel <IEnumerable <T> > editObject;
                    //Special for just editmodel with list parameter
                    var key = GetKey(editRequest);
                    editObject = _client.Get <EditModel <IEnumerable <T> > >(key);

                    if (request.LockForEdit)
                    {
                        if (editObject == null)
                        {
                            //Create a custom user for locked by to avoid having to much data in memcache. Only need id and name. Use dunamic is an option.
                            var lockUser = new EditUser {
                                Id = request.LockBy.Id, Name = request.LockBy.Name
                            };

                            editObject = new EditModel <IEnumerable <T> > {
                                EditObject = list, EditUser = lockUser
                            };
                        }
                        else
                        {
                            editObject.EditObject = list;
                        }
                        var storeResult = _client.Store(StoreMode.Set, key, editObject, GetTTL());
                    }
                    else
                    {
                        if (editObject != null)
                        {
                            if (editObject.EditUser.Id == request.LockBy.Id)
                            {
                                Delete(request);
                            }
                            else
                            {
                                ThrowLockedBy(editObject.EditUser);
                            }
                        }
                    }
                }
            }
        }
 private void ThrowLockedBy(EditUser user)
 {
     throw new ObjectLockedException(string.Format("{0} locked by {1}", typeof(T).Name, user.Name), user.Name);
 }
        public void Save(T obj, Request request)
        {
            if (request != null)
            {
                if (request.LockBy != null)
                {
                    EditModel <T> editObject;

                    Request      editRequest = CreateEditRequest(request);
                    PropertyList propertyList;

                    /*
                     * //For new unsaved objects and more than one user has unsaved objects in memory
                     * propertyList =  PropertyInfoHelper.GetProperties<T>();
                     * int id = propertyList.KeyProperty.GetValue(obj, null);
                     * if (id < 0)
                     * {
                     *  id = request.LockBy.Id * -1;
                     * }*/


                    if (editRequest.Parameters == null)
                    {
                        //Create parameters based on Key attribute on Object
                        propertyList = PropertyInfoHelper.GetProperties <T>();

                        editRequest.Parameters = new { Id = propertyList.KeyProperty.GetValue(obj, null) };
                    }


                    editObject = base.Get(editRequest);

                    if (request.LockForEdit)
                    {
                        if (editObject == null)
                        {
                            //Create a custom user for locked by to avoid having to much data in memcache. Only need id and name. Use dunamic is an option.
                            var lockUser = new EditUser {
                                Id = request.LockBy.Id, Name = request.LockBy.Name
                            };

                            editObject = new EditModel <T> {
                                EditObject = obj, EditUser = lockUser
                            };
                        }
                        else
                        {
                            editObject.EditObject = obj;
                        }

                        if (editObject != null)
                        {
                            base.Save(editObject, editRequest);
                        }
                    }
                    else
                    {
                        if (editObject != null)
                        {
                            if (editObject.EditUser.Id == request.LockBy.Id)
                            {
                                Delete(editRequest);
                            }
                            else
                            {
                                ThrowLockedBy(editObject.EditUser);
                            }
                        }
                        else
                        {
                            //We guess that we created a new item and that item has a negative id of user.id *-1
                            //checked if this item exists
                            editRequest.Key        = null;
                            editRequest.Parameters = new { Id = request.LockBy.Id * -1 };
                            editObject             = base.Get(editRequest);
                            if (editObject != null)
                            {
                                if (editObject.EditUser.Id == request.LockBy.Id)
                                {
                                    Delete(editRequest);
                                }
                                else
                                {
                                    ThrowLockedBy(editObject.EditUser);
                                }
                            }
                        }
                    }
                }
            }
        }