Exemplo n.º 1
0
        public static string Update(Context context, SiteSettings ss, int tenantId)
        {
            var tenantModel = new TenantModel(
                context: context, ss: ss, tenantId: tenantId, setByForm: true);
            var invalid = TenantValidators.OnUpdating(
                context: context,
                ss: ss,
                tenantModel: tenantModel);

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

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

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

            case Error.Types.UpdateConflicts:
                return(Messages.ResponseUpdateConflicts(
                           context: context,
                           data: tenantModel.Updator.Name)
                       .ToJson());

            default:
                return(error.MessageJson(context: context));
            }
        }
Exemplo n.º 2
0
        public static string Editor(
            Context context, SiteSettings ss, TenantModel tenantModel)
        {
            var invalid = TenantValidators.OnEditing(
                context: context,
                ss: ss,
                tenantModel: tenantModel);

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

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

            ss.SetColumnAccessControls(
                context: context,
                mine: tenantModel.Mine(context: context));
            return(hb.Template(
                       context: context,
                       ss: ss,
                       view: null,
                       verType: tenantModel.VerType,
                       methodType: tenantModel.MethodType,
                       referenceType: "Tenants",
                       title: tenantModel.MethodType == BaseModel.MethodTypes.New
                    ? Displays.Tenants(context: context) + " - " + Displays.New(context: context)
                    : tenantModel.Title.Value,
                       action: () =>
            {
                hb
                .Editor(
                    context: context,
                    ss: ss,
                    tenantModel: tenantModel)
                .Hidden(controlId: "TableName", value: "Tenants")
                .Hidden(controlId: "Controller", value: context.Controller)
                .Hidden(controlId: "Id", value: tenantModel.TenantId.ToString());
            }).ToString());
        }
Exemplo n.º 3
0
        public static string Create(Context context, SiteSettings ss)
        {
            var tenantModel = new TenantModel(context, ss, 0, setByForm: true);
            var invalid     = TenantValidators.OnCreating(
                context: context,
                ss: ss,
                tenantModel: tenantModel);

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

            default: return(invalid.MessageJson(context: context));
            }
            var error = tenantModel.Create(context: context, ss: ss);

            switch (error)
            {
            case Error.Types.None:
                SessionUtilities.Set(
                    context: context,
                    message: Messages.Created(
                        context: context,
                        data: tenantModel.Title.Value));
                return(new ResponseCollection()
                       .Response("id", tenantModel.TenantId.ToString())
                       .SetMemory("formChanged", false)
                       .Href(Locations.Edit(
                                 context: context,
                                 controller: context.Controller,
                                 id: ss.Columns.Any(o => o.Linking)
                                ? context.Forms.Long("LinkId")
                                : tenantModel.TenantId))
                       .ToJson());

            default:
                return(error.MessageJson(context: context));
            }
        }
Exemplo n.º 4
0
        public static string Delete(Context context, SiteSettings ss, int tenantId)
        {
            var tenantModel = new TenantModel(context, ss, tenantId);
            var invalid     = TenantValidators.OnDeleting(
                context: context,
                ss: ss,
                tenantModel: tenantModel);

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

            default: return(invalid.MessageJson(context: context));
            }
            var error = tenantModel.Delete(context: context, ss: ss);

            switch (error)
            {
            case Error.Types.None:
                SessionUtilities.Set(
                    context: context,
                    message: Messages.Deleted(
                        context: context,
                        data: tenantModel.Title.Value));
                var res = new TenantsResponseCollection(tenantModel);
                res
                .SetMemory("formChanged", false)
                .Href(Locations.Index(
                          context: context,
                          controller: "Tenants"));
                return(res.ToJson());

            default:
                return(error.MessageJson(context: context));
            }
        }