DataTables / Editor-NET

.NET Framework and .NET Core server-side libraries for Editor
Other
15 stars 12 forks source link

upload and mjoin with non-dbo tables (child table) #4

Closed fbognini closed 3 years ago

fbognini commented 3 years ago

UPLOAD

In DbClean it's assumed that the table specified in the field is a dbo-table, but it's not always true.

Here an example:

new Editor(dtDatabase, "intranet.Links", "Id")
      .Field(new Field("Links.LinkIconId", "linkIconId")
          .SetFormatter(Format.IfEmpty(null))
          .Upload(
              new Upload(Path.Combine(environment.WebRootPath, "uploads", "links", "__ID____EXTN__"))
              .Validator(
                  Validation.FileExtensions(
                      new[] { "png", "jpg", "jpeg", "svg", "gif" },
                      "Carica un'immagine (png, jpg, gif o svg)"
                  )
              )
              .Db("intranet.LinkIcons", "Id", new Dictionary<string, object>
              {
                  {"FileName", Upload.DbType.FileName},
                  {"Extension", Upload.DbType.Extn},
                  {"FileSize", Upload.DbType.FileSize},
                  {"MimeType", Upload.DbType.MimeType},
                  {"WebPath", Path.Combine("uploads", "links", "__ID____EXTN__")},
                  {"SystemPath", Upload.DbType.SystemPath}
              })
              .DbClean(data =>
              {
                  foreach (var row in data)
                  {
                      System.IO.File.Delete(row["SystemPath"].ToString());
                  }
                  return true;
              })
          )
      )

MJOIN

Same example:

new Editor(dtDatabase, "intranet.Links", "Id")
        .MJoin(
            new MJoin("auth.Roles")
                .Link("intranet.Links.id", "intranet.LinkRoles.LinkId")
                .Link("auth.Roles.id", "intranet.LinkRoles.RoleId")
                .Order("auth.Roles.Name")
                .Field(new Field("Id", "id")
                    .Options("auth.Roles", "Id", "Name")
                )
                .Field(new Field("Roles.Name", "name"))
        )

Table name should be only Roles not auth.Roles. Otherwise it will be considered a normal joined table (in the request) and "Roles-many-count" key won't be calculated.

DataTables commented 3 years ago

Looks good - thanks for this :-). Are you happen to contribute this under the MIT license?

fbognini commented 3 years ago

👍