Exemple #1
0
        public static string Delete(SiteSettings ss, int deptId)
        {
            var deptModel = new DeptModel(ss, deptId);
            var invalid   = DeptValidators.OnDeleting(ss, deptModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            var error = deptModel.Delete(ss);

            if (error.Has())
            {
                return(error.MessageJson());
            }
            else
            {
                Sessions.Set("Message", Messages.Deleted(deptModel.Title.Value).Html);
                var res = new DeptsResponseCollection(deptModel);
                res
                .SetMemory("formChanged", false)
                .Href(Locations.Index("Depts"));
                return(res.ToJson());
            }
        }
Exemple #2
0
        public static string Create(SiteSettings ss)
        {
            var deptModel = new DeptModel(ss, 0, setByForm: true);
            var invalid   = DeptValidators.OnCreating(ss, deptModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            var error = deptModel.Create(ss);

            if (error.Has())
            {
                return(error.MessageJson());
            }
            else
            {
                return(EditorResponse(
                           ss,
                           deptModel,
                           Messages.Created(deptModel.Title.Value),
                           GetSwitchTargets(ss, deptModel.DeptId).Join()).ToJson());
            }
        }
Exemple #3
0
        public static string Update(SiteSettings ss, int deptId)
        {
            var deptModel = new DeptModel(ss, deptId, setByForm: true);
            var invalid   = DeptValidators.OnUpdating(ss, deptModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            if (deptModel.AccessStatus != Databases.AccessStatuses.Selected)
            {
                return(Messages.ResponseDeleteConflicts().ToJson());
            }
            var error = deptModel.Update(ss);

            if (error.Has())
            {
                return(error == Error.Types.UpdateConflicts
                    ? Messages.ResponseUpdateConflicts(deptModel.Updator.Name).ToJson()
                    : new ResponseCollection().Message(error.Message()).ToJson());
            }
            else
            {
                var res = new DeptsResponseCollection(deptModel);
                return(ResponseByUpdate(res, ss, deptModel)
                       .PrependComment(ss, deptModel.Comments, deptModel.VerType)
                       .ToJson());
            }
        }
Exemple #4
0
        public static string Editor(SiteSettings ss, DeptModel deptModel)
        {
            var invalid = DeptValidators.OnEditing(ss, deptModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(HtmlTemplates.Error(invalid));
            }
            var hb = new HtmlBuilder();

            ss.SetColumnAccessControls(deptModel.Mine());
            return(hb.Template(
                       ss: ss,
                       verType: deptModel.VerType,
                       methodType: deptModel.MethodType,
                       referenceType: "Depts",
                       title: deptModel.MethodType == BaseModel.MethodTypes.New
                    ? Displays.Depts() + " - " + Displays.New()
                    : deptModel.Title.Value,
                       action: () =>
            {
                hb
                .Editor(
                    ss: ss,
                    deptModel: deptModel)
                .Hidden(controlId: "TableName", value: "Depts")
                .Hidden(controlId: "Id", value: deptModel.DeptId.ToString());
            }).ToString());
        }
Exemple #5
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string Index(SiteSettings ss)
        {
            var invalid = DeptValidators.OnEntry(ss);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(HtmlTemplates.Error(invalid));
            }
            var hb       = new HtmlBuilder();
            var view     = Views.GetBySession(ss);
            var gridData = GetGridData(ss, view);
            var viewMode = ViewModes.GetBySession(ss.SiteId);

            return(hb.Template(
                       ss: ss,
                       verType: Versions.VerTypes.Latest,
                       methodType: BaseModel.MethodTypes.Index,
                       referenceType: "Depts",
                       script: Libraries.Scripts.JavaScripts.ViewMode(viewMode),
                       title: Displays.Depts() + " - " + Displays.List(),
                       action: () =>
            {
                hb
                .Form(
                    attributes: new HtmlAttributes()
                    .Id("DeptForm")
                    .Class("main-form")
                    .Action(Locations.Action("Depts")),
                    action: () => hb
                    .ViewFilters(ss: ss, view: view)
                    .Aggregations(
                        ss: ss,
                        aggregations: gridData.Aggregations)
                    .Div(id: "ViewModeContainer", action: () => hb
                         .Grid(
                             ss: ss,
                             gridData: gridData,
                             view: view))
                    .MainCommands(
                        ss: ss,
                        siteId: ss.SiteId,
                        verType: Versions.VerTypes.Latest)
                    .Div(css: "margin-bottom")
                    .Hidden(controlId: "TableName", value: "Depts")
                    .Hidden(controlId: "BaseUrl", value: Locations.BaseUrl())
                    .Hidden(
                        controlId: "GridOffset",
                        value: Parameters.General.GridPageSize.ToString()))
                .Div(attributes: new HtmlAttributes()
                     .Id("ImportSettingsDialog")
                     .Class("dialog")
                     .Title(Displays.Import()))
                .Div(attributes: new HtmlAttributes()
                     .Id("ExportSettingsDialog")
                     .Class("dialog")
                     .Title(Displays.ExportSettings()));
            }).ToString());
        }
        public static string Create(SiteSettings ss)
        {
            var deptModel = new DeptModel(ss, 0, setByForm: true);
            var invalid   = DeptValidators.OnCreating(ss, deptModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            var error = deptModel.Create(ss);

            switch (error)
            {
            case Error.Types.None:
                Sessions.Set("Message", Messages.Created(deptModel.Title.Value));
                return(new ResponseCollection()
                       .SetMemory("formChanged", false)
                       .Href(Locations.Edit(
                                 controller: Routes.Controller(),
                                 id: ss.Columns.Any(o => o.Linking)
                                ? Forms.Long("LinkId")
                                : deptModel.DeptId))
                       .ToJson());

            default:
                return(error.MessageJson());
            }
        }
Exemple #7
0
        private static string ViewModeTemplate(
            this HtmlBuilder hb,
            SiteSettings ss,
            DeptCollection deptCollection,
            View view,
            string viewMode,
            Action viewModeBody)
        {
            var invalid = DeptValidators.OnEntry(ss);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(HtmlTemplates.Error(invalid));
            }
            ss.SetColumnAccessControls();
            return(hb.Template(
                       ss: ss,
                       verType: Versions.VerTypes.Latest,
                       methodType: BaseModel.MethodTypes.Index,
                       siteId: ss.SiteId,
                       parentId: ss.ParentId,
                       referenceType: "Depts",
                       script: Libraries.Scripts.JavaScripts.ViewMode(viewMode),
                       userScript: ss.GridScript,
                       userStyle: ss.GridStyle,
                       action: () => hb
                       .Form(
                           attributes: new HtmlAttributes()
                           .Id("DeptsForm")
                           .Class("main-form")
                           .Action(Locations.ItemAction(ss.SiteId)),
                           action: () => hb
                           .ViewSelector(ss: ss, view: view)
                           .ViewFilters(ss: ss, view: view)
                           .Aggregations(
                               ss: ss,
                               aggregations: deptCollection.Aggregations)
                           .Div(id: "ViewModeContainer", action: () => viewModeBody())
                           .MainCommands(
                               ss: ss,
                               siteId: ss.SiteId,
                               verType: Versions.VerTypes.Latest,
                               bulkMoveButton: true,
                               bulkDeleteButton: true,
                               importButton: true,
                               exportButton: true)
                           .Div(css: "margin-bottom")
                           .Hidden(controlId: "TableName", value: "Depts")
                           .Hidden(controlId: "BaseUrl", value: Locations.BaseUrl()))
                       .MoveDialog(bulk: true)
                       .Div(attributes: new HtmlAttributes()
                            .Id("ExportSettingsDialog")
                            .Class("dialog")
                            .Title(Displays.ExportSettings())))
                   .ToString());
        }
Exemple #8
0
        public static string Update(Context context, SiteSettings ss, int deptId)
        {
            var deptModel = new DeptModel(
                context: context, ss: ss, deptId: deptId, setByForm: true);
            var invalid = DeptValidators.OnUpdating(
                context: context, ss: ss, deptModel: deptModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            if (deptModel.AccessStatus != Databases.AccessStatuses.Selected)
            {
                return(Messages.ResponseDeleteConflicts().ToJson());
            }
            var error = deptModel.Update(context: context, ss: ss);

            switch (error)
            {
            case Error.Types.None:
                var res = new DeptsResponseCollection(deptModel);
                return(ResponseByUpdate(res, context, ss, deptModel)
                       .PrependComment(
                           context: context,
                           ss: ss,
                           column: ss.GetColumn(context: context, columnName: "Comments"),
                           comments: deptModel.Comments,
                           verType: deptModel.VerType)
                       .ToJson());

            case Error.Types.UpdateConflicts:
                return(Messages.ResponseUpdateConflicts(
                           deptModel.Updator.Name)
                       .ToJson());

            default:
                return(error.MessageJson());
            }
        }
Exemple #9
0
        public static string Restore(SiteSettings ss, int deptId)
        {
            var deptModel = new DeptModel();
            var invalid   = DeptValidators.OnRestoring();

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            var error = deptModel.Restore(ss, deptId);

            if (error.Has())
            {
                return(error.MessageJson());
            }
            else
            {
                var res = new DeptsResponseCollection(deptModel);
                return(res.ToJson());
            }
        }