public JsonResult AddManagersForEmployee(Manager[] managers)
        {
            //check the all the details are correct and if not send message to client
            var errors = CheckManagers(managers);
            if (errors.Length > 0)
            {
                GetLogger().Info(string.Format("Administration:AddManagersForEmployee: Problem with manager details {0}", errors));
                return JsonError(new AccountsManagersAdminViewModel { ErrorMessage = errors }, errors);
            }


            using (var orgSession = OrgStore.OpenSession())
            {
                var errorBuilder = new StringBuilder();
                foreach (var newManager in managers)
                {
                    var employee = orgSession.Load<User>(newManager.EmployeeId);
                    if (employee == null)
                        errorBuilder.Append("Cannot find user");
                    else
                    {
                        if (employee.Relationships.All(manager => manager.UserId != newManager.ManagerEmployeeId && manager.RelationshipName == "LineManager"))
                        {
                            var newManagerUser = orgSession.Load<User>(newManager.ManagerEmployeeId);
                            try
                            {
                                employee.AddManager(newManagerUser);
                            }
                            catch 
                            {
                                errorBuilder.Append(string.Format("Cannot add {0} as a manager because they are not in the Manager role",newManagerUser.Name));
                            }
                        }
                    }
                }
                if (errorBuilder.Length > 0)
                {
                    GetLogger().Info(string.Format("AdministrationController:AddManagersForEmployee - {0}", errors));
                    return JsonError(new AccountsManagersAdminViewModel { ErrorMessage = errorBuilder.ToString() }, errors);
                }

                var vm = new AccountsManagersAdminViewModel();

                //save the changes to Raven and send a success message to the client
                try
                {
                    orgSession.SaveChanges();

                    vm.SuccessMessage = string.Format("Succesfully added {0} managers to employee account",
                                                      managers.Length);
                    return JsonSuccess(vm, vm.SuccessMessage);
                }
                catch (Exception ex)
                {
                    GetLogger().Error("Admin: Add managers for employee: Cannot save to Raven", ex);
                    vm.ErrorMessage = "Cannot save changes";
                    return JsonError(vm, vm.ErrorMessage);
                }
            }
        }
        public JsonResult RemoveManagersForEmployee(Manager[] managers)
        {
            using (var orgSession = OrgStore.OpenSession())
            {
                foreach (var manager in managers)
                {
                    var employee = orgSession.Load<User>(manager.EmployeeId);
                    employee.Relationships.RemoveAll(m => m.UserId == manager.ManagerEmployeeId && m.RelationshipName == "LineManager");
                }
                var vm = new AccountsManagersAdminViewModel();

                //save the changes to Raven and send a success message to the client
                try
                {
                    orgSession.SaveChanges();
                    vm.SuccessMessage = string.Format("Succesfully removed  managers");
                    return JsonSuccess(vm, vm.SuccessMessage);
                }
                catch (Exception ex)
                {
                    GetLogger().Error(string.Format("Administration-RemoveManagersForEmployee: Problem"), ex);
                    return JsonError("Cannot remove managers");
                }
            }
        }