public JsonResult SaveRole(RoleInfo Info)
        {
            RequestResultModel _model = new RequestResultModel();

            if (Info.Name == null || Info.Name.Trim().Length == 0)
            {
                _model = new RequestResultModel();
                _model.Title = "Warning";
                _model.Message = "Name is empty. Please, enter role name.";
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

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

                }, JsonRequestBehavior.AllowGet);
            }

            if (!AppSession.IsColor(Info.Color))
            {
                _model = new RequestResultModel();
                _model.Title = "Warning";
                _model.Message = "Wrong color value or format, please check.";
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

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

                }, JsonRequestBehavior.AllowGet);
            }

            if (Info.RoleID > 0)
            {
                Role role = Web.Admin.Logic.Collections.Roles.GetBy(Info.RoleID);
                Role roleExists = Web.Admin.Logic.Collections.Roles.GetBy(Info.Name);

                // The role has been deleted.
                if (role.RoleID <= 0)
                {
                    _model.Title = "Warning";
                    _model.Message = String.Format("Role '{0}' doesn't exist. Please, refresh role list and try again.", roleExists.Name);
                    AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

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

                    }, JsonRequestBehavior.AllowGet);
                }

                // The role already esists.
                if (roleExists.RoleID > 0 && Info.RoleID != roleExists.RoleID)
                {
                    _model.Title = "Warning";
                    _model.Message = String.Format("Role '{0}' already exists. Please, change role name and try again.", roleExists.Name);
                    AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

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

                    }, JsonRequestBehavior.AllowGet);
                }

                if (!role.IsBuiltIn)
                {
                    role.Name = Info.Name;
                    role.IsBuiltIn = false;
                }
                else
                {
                    role.IsBuiltIn = true;
                }

                role.Settings = Info.Settings;
                role.BackColor = Info.Color != null ? Info.Color.Replace("#", "") : "FFFFFF";
                role.ForeColor = Role.ContrastColor(role.BackColor.Replace("#", ""));
                role.Save();

                _model = new RequestResultModel();
                _model.Message = String.Format("Role \"{0}\"has been updated.",role.Name);
                _model.HideInSeconds = 4000;
                AuditEvent.AppEventSuccess(Profile.Member.Email, _model.Message);

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

                }, JsonRequestBehavior.AllowGet);

            }
            else
            {
                Role roleExists = Web.Admin.Logic.Collections.Roles.GetBy(Info.Name);

                // The role already esists.
                if (roleExists.RoleID > 0)
                {
                    _model.Title = "Warning";
                    _model.Message = String.Format("Role '{0}' already exists. Please, change role name and try again.", roleExists.Name);

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

                    }, JsonRequestBehavior.AllowGet);
                }

                Role Role = new Role();
                Role.Name = Info.Name;
                Role.Settings = Info.Settings;
                Role.BackColor = Info.Color != null ? Info.Color.Replace("#", "") : "FFFFFF";
                Role.ForeColor = Role.ContrastColor(Role.BackColor.Replace("#", ""));
                Role.IsBuiltIn = false;
                Role.Save();

                _model.Message = String.Format("New role \"{0}\" has been created.",Role.Name);

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

                }, JsonRequestBehavior.AllowGet);
            }
        }
Beispiel #2
0
        public JsonResult SaveRole(RoleInfo Info)
        {
            RequestResultModel _model = new RequestResultModel();

            if (Info.Name == null || Info.Name.Trim().Length == 0)
            {
                _model          = new RequestResultModel();
                _model.Title    = "Warning";
                _model.Message  = "Name is empty. Please, enter role name.";
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                return(Json(new
                {
                    NotifyType = NotifyType.DialogInline,
                    Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                }, JsonRequestBehavior.AllowGet));
            }

            if (!AppSession.IsColor(Info.Color))
            {
                _model          = new RequestResultModel();
                _model.Title    = "Warning";
                _model.Message  = "Wrong color value or format, please check.";
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                return(Json(new
                {
                    NotifyType = NotifyType.DialogInline,
                    Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                }, JsonRequestBehavior.AllowGet));
            }

            if (Info.RoleID > 0)
            {
                Role role       = Web.Admin.Logic.Collections.Roles.GetBy(Info.RoleID);
                Role roleExists = Web.Admin.Logic.Collections.Roles.GetBy(Info.Name);

                // The role has been deleted.
                if (role.RoleID <= 0)
                {
                    _model.Title   = "Warning";
                    _model.Message = String.Format("Role '{0}' doesn't exist. Please, refresh role list and try again.", roleExists.Name);
                    AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                    return(Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                    }, JsonRequestBehavior.AllowGet));
                }

                // The role already esists.
                if (roleExists.RoleID > 0 && Info.RoleID != roleExists.RoleID)
                {
                    _model.Title   = "Warning";
                    _model.Message = String.Format("Role '{0}' already exists. Please, change role name and try again.", roleExists.Name);
                    AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                    return(Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                    }, JsonRequestBehavior.AllowGet));
                }

                if (!role.IsBuiltIn)
                {
                    role.Name      = Info.Name;
                    role.IsBuiltIn = false;
                }
                else
                {
                    role.IsBuiltIn = true;
                }

                role.Settings  = Info.Settings;
                role.BackColor = Info.Color != null?Info.Color.Replace("#", "") : "FFFFFF";

                role.ForeColor = Role.ContrastColor(role.BackColor.Replace("#", ""));
                role.Save();

                _model               = new RequestResultModel();
                _model.Message       = String.Format("Role \"{0}\"has been updated.", role.Name);
                _model.HideInSeconds = 4000;
                AuditEvent.AppEventSuccess(Profile.Member.Email, _model.Message);

                return(Json(new
                {
                    NotifyType = NotifyType.PageInline,
                    Html = this.RenderPartialView(@"_RequestResultPageInLine", _model)
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                Role roleExists = Web.Admin.Logic.Collections.Roles.GetBy(Info.Name);

                // The role already esists.
                if (roleExists.RoleID > 0)
                {
                    _model.Title   = "Warning";
                    _model.Message = String.Format("Role '{0}' already exists. Please, change role name and try again.", roleExists.Name);

                    return(Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                    }, JsonRequestBehavior.AllowGet));
                }

                Role Role = new Role();
                Role.Name      = Info.Name;
                Role.Settings  = Info.Settings;
                Role.BackColor = Info.Color != null?Info.Color.Replace("#", "") : "FFFFFF";

                Role.ForeColor = Role.ContrastColor(Role.BackColor.Replace("#", ""));
                Role.IsBuiltIn = false;
                Role.Save();

                _model.Message = String.Format("New role \"{0}\" has been created.", Role.Name);

                return(Json(new
                {
                    NotifyType = NotifyType.PageInline,
                    Html = this.RenderPartialView(@"_RequestResultPageInLine", _model)
                }, JsonRequestBehavior.AllowGet));
            }
        }