public JsonResult RemoveRole(int[] RemoeRoles)
        {
            RoleListModel _model = new RoleListModel();
            List<Role> _deleted = new List<Role>();

            foreach (int RoleID in RemoeRoles)
            {
                Role role = Web.Admin.Logic.Collections.Roles.GetBy(RoleID);
                List<ProfileField> _profileFields = ProfileFields.GetByRole(RoleID);

                if (Web.Admin.Logic.Collections.Roles.GetMemberCount(role.RoleID) > 0)
                {
                    role.WasDeleted = false;
                    role.UIMessage = "The role contains members.";
                    role.UIMessageType = UIMessageType.Warning;
                    AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleContainsMembers, role.Name));
                }
                else if (_profileFields.Count > 0)
                {
                    role.WasDeleted = false;
                    role.UIMessage = "The role has not been deleted. Attached fields: ";
                    foreach (ProfileField profileField in _profileFields)
                    {
                        role.UIMessage += "<u>" + profileField.FieldName + "</u>&nbsp;";
                    }
                    role.UIMessageType = UIMessageType.Warning;
                    AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleContainsMembers, role.Name));
                }
                else
                {
                    if (role.IsBuiltIn)
                    {
                        role.WasDeleted = true;
                        role.UIMessage = "The role is built in and can't be deleted.";
                        role.UIMessageType = UIMessageType.Warning;
                        AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleIsBuiltIn, role.Name));
                    }
                    else if (role.Delete())
                    {
                        role.WasDeleted = true;
                        role.UIMessage = "The role has been deleted.";
                        role.UIMessageType = UIMessageType.Success;
                        AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleDeleted, role.Name));
                    }
                }

                _deleted.Add(role);
            }

            _model.Roles = _deleted;

            return Json(new
            {
               NotifyType = NotifyType.Dialog,
               Html = this.RenderPartialView(@"_RemoveRolesResult", _model)

            }, JsonRequestBehavior.AllowGet);
        }
        public JsonResult GetRemoveRoleDialog(int[] RmoveRoles)
        {
            RoleListModel _model = new RoleListModel();
            foreach (int RoleID in RmoveRoles)
            {
                Role role = Web.Admin.Logic.Collections.Roles.GetBy(RoleID);
                _model.Roles.Add(role);
            }

            return Json(new
            {
                Html = this.RenderPartialView(@"_RemoveRoles", _model),

            }, JsonRequestBehavior.AllowGet);
        }
        public ActionResult ImportRoles()
        {
            System.Threading.Thread.Sleep(200);
            CultureInfo provider = CultureInfo.InvariantCulture;

            List<Role> RoleResult = new List<Role>();
            try
            {
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    System.Threading.Thread.Sleep(1);

                    String FileContent = "";
                    HttpPostedFileBase PostedFile = Request.Files[i];

                    using (System.IO.Stream input = PostedFile.InputStream)
                    {
                        byte[] buffer = new byte[PostedFile.InputStream.Length];
                        input.Read(buffer, 0, buffer.Length);
                        FileContent = System.Text.ASCIIEncoding.UTF8.GetString(buffer);
                    }

                    if (FileContent.Length > 0)
                    {
                        string[] Lines = FileContent.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                        AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleUploadHasStarted, Lines.Length));

                        int LineNumber = 1;
                        foreach (String Line in Lines)
                        {
                            if (LineNumber == 1 || Line == null || Line.Trim().Length == 0)
                            {
                                LineNumber++;
                                continue;
                            }

                            List<string> Values = new List<string>();
                            CsvParser parser = new CsvParser(Line);

                            foreach (string s in parser)
                                Values.Add(s.Trim());

                            if (Values.Count >= 4)
                            {
                                Role Role = Web.Admin.Logic.Collections.Roles.GetBy(Values[0]);
                                if (Role.RoleID > 0)
                                {
                                    Role.UIMessage = "Role already exists.";
                                    Role.UILineNumber = LineNumber;
                                    Role.UIMessageType = Logic.UIMessageType.Warning;
                                    AuditEvent.AppEventWarning(Profile.Member.Email, String.Format(AuditEvent.RoleUploadMemberExists, Role.Name));
                                }
                                else
                                {
                                    Role.Name = Values[0];
                                    Role.Settings = Values[1];

                                    if (Values[3].Trim().Length == 0)
                                        Role.BackColor = "aaaaaa";
                                    else
                                        Role.BackColor = Values[2];

                                    if (Values[3].Trim().Length == 0)
                                        Role.ForeColor = "000000";
                                    else
                                        Role.ForeColor = Values[3];

                                    if (BuiltInRoleMember.ContainsRole(Role.Name))
                                        Role.IsBuiltIn = true;
                                    else
                                        Role.IsBuiltIn = false;

                                    try
                                    {
                                        Role.Created = DateTime.ParseExact(Values[4], "dd.MM.yyyy HH:mm:ss", provider);
                                    }
                                    catch { }

                                    try
                                    {
                                        Role.Modified = DateTime.ParseExact(Values[5], "dd.MM.yyyy HH:mm:ss", provider);
                                    }
                                    catch {
                                    }

                                    Role.Save();

                                    Role.UIMessage = "Role has been added.";
                                    Role.UIMessageType = Logic.UIMessageType.Success;
                                    Role.UILineNumber = LineNumber;
                                    AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleUploadedItemAdded, Role.Name));

                                }

                                RoleResult.Add(Role);
                            }
                            else if (Values.Count > 0)
                            {
                                Role Role = new Role();

                                Role.UIMessage = "Wrong line format. Number of columns: " + Values.Count.ToString();
                                Role.UIMessageType = Logic.UIMessageType.ErrorOrDanger;
                                Role.UILineNumber = LineNumber;
                                AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleUploadWrongLineFormat, LineNumber, Values.Count));

                                RoleResult.Add(Role);
                            }

                            LineNumber++;
                        }

                    }
                }

                System.Threading.Thread.Sleep(1000);
                RoleListModel Model = new RoleListModel();
                Model.Roles = RoleResult;

                return Json(new
                {
                    NotifyType = NotifyType.Dialog,
                    Html = this.RenderPartialView(@"_ImportRolesResult", Model)

                }, "text/html", JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {

              RequestResultModel _model = new RequestResultModel();

              _model.Title = "Warning";
              _model.Message = String.Format("Something went wrong: {0}",HttpUtility.HtmlEncode(ex.Message));
              _model.InfoType = RequestResultInfoType.ErrorOrDanger;
              _model.HideInSeconds = 0;
              _model.Height = 250;

              AuditEvent.AppEventError(Profile.Member.Email, _model.Message, AuditEvent.GetSessionDetails(ex.StackTrace));

              return Json(new
              {
                  NotifyType = NotifyType.DialogInline,
                  Html = this.RenderPartialView(@"_RequestResultDialog", _model)

              }, "text/html", JsonRequestBehavior.AllowGet);

            }
        }
        public JsonResult GetEditRoleDialog(int RoleID)
        {
            Role role = Web.Admin.Logic.Collections.Roles.GetBy(RoleID);
            RoleListModel _model = new RoleListModel();
            _model.Roles.Add(role);

            return Json(new
            {
                Html = this.RenderPartialView(@"_EditRole", _model),

            }, JsonRequestBehavior.AllowGet);
        }