Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
I have a one to many file upload setup following your example using a link table. My image model looks like the following
public class ImagesModel : EditorModel
{
public System.Guid ImageID { get; set; }
public byte[] Content { get; set; }
public string ContentType { get; set; }
public string Extension { get; set; }
public string FileName { get; set; }
public int FileSize { get; set; }
public string MimeType { get; set; }
public DateTime CreatedDate { get; set; }
public bool IsDefault { get; set; }
}
Basically, I have "Products" that can have many images. This is all setup and working fine with all images currently being uploaded as "IsDefault" false. However, I need a way to mark the "IsDefault". I want to have a checkbox next to the image and then a validator in my controller to only allow 1 image to be checked but I'm struggling on how to accomplish this. Any suggestions? Here's my editor
using (var db = new Database(dbType, dbConnection))
{
var response = new Editor(db, "Product.Product", "ProductID")
//.Model<ProductModel>()
.Field(new Field("ProductID"))
.Field(new Field("Product.ProductID").Set(false))
.Field(new Field("Product.Identifier").Set(false))
.Field(new Field("Product.Title").Set(false))
.MJoin(new MJoin("Product.Images")
.Link("Product.Product.ProductID", "Product.ImageRef.ProductID")
.Link("Product.Images.ImageID", "Product.ImageRef.ImageID")
.Model<ImagesModel>()
.Field(new Field("ImageID")
.Upload(new Upload()
.Db("Product.Images", "ImageID", new Dictionary<string, object>
{
//{"web_path", Path.DirectorySeparatorChar+Path.Combine("uploads", "__ID____EXTN__")},
{"ImageID", Upload.DbType.ReadOnly},
{"Content", Upload.DbType.ContentBinary},
{"ContentType", Upload.DbType.ContentType},
{"Extension", Upload.DbType.Extn},
{"FileName", Upload.DbType.FileName},
{"FileSize", Upload.DbType.FileSize},
{"MimeType", Upload.DbType.MimeType},
{"CreatedDate", Upload.DbType.ReadOnly},
{"IsDefault", Upload.DbType.ReadOnly}
})
.Validator(Validation.FileSize(500000, "Max file size is 500K."))
.Validator(Validation.FileExtensions(new[] { "jpg", "png", "jpeg" }, "Please upload an image."))
)
)
)
//.Debug(true).TryCatch(false)
.Process(Request)
.Data();
return Json(response);
}
Note: I have IsDefault setup as a bit in my database and defaults to 0.
Thanks for any help you can provide.