How to work with PXImageUploader in Acumatica - erp

I want to add image uploader to my web form in Acumatica. But I hardly imagine what fields should be presented in DAC and in DB. Another question which I have is how to manage storage for images.
Is it possible to store them in db, cloud, file system?

ImageUploader uses the files attached to an entity plus (optionally) a string field that can store the selected file name (screen title + (entity key values) + \ file name, to be precise). Since these are just regular attached files the usual storage options apply (i.e. DB or whatever storage provider you use). The files that are displayed have extensions marked as "Image" in file upload preferences.
There's nothing special about the filename field really. You need add a string to your DAC:
public partial class YourEntity : PX.Data.IBqlTable {
...
public abstract class filename : PX.Data.IBqlField{}
[PXDBString(255, IsUnicode = true)]
public virtual string Filename { get; set; }
...
}
add a corresponding field to your database:
create table "YourEntity" (
...
"Filename" nvarchar(255) null,
...
)
and specify that field name in aspx page when adding a control:
<px:PXImageUploader ID="controlField" runat="server" DataField="Filename" ...
The user will be able to pick the selected image by on-screen arrows (or Ctrl - arrow keyboard combo) from all the attached images.
It's possible not to use the filename field at all. In that case the control will show the first attached image, and the user will be able to scroll through all the attached images.

Related

Saving multiple images with size limitation and bootstrap

I have built a simple ASP.NET MVC5 project that acts as a classifieds application for my college's students. I got everything figured out and implemented except for the images. I am struggling to find the best approach to store the images.
I came up with the following structure:
Ad represents the advertisement model
adImage represents an image(s) for an ad. AdImage has a foreign Key public int AdId { get; set; } and then public virtual Ad TheAdvertisement { get; set; }
Considerations:
I am using bootstrap
I will not consider support older IE browsers
I have to resize the images prior to save
I will be saving the images on the file system and then store their urls back into my database.
I think I know how to upload then store multiple images. I am struggling with how to implement size-limitation validation to my controller and whether it is something I should consider to implement in my project. What is the best approach when dealing with images in classified website?
To Limit the size of image files, take a look at file size upload limitation in ASP.NET MVC that employs web.config file to meet your purpose.
Another way to Limit file size is writing code something like this:
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
//you can put your existing save code here
if (file != null && file.ContentLength > 10000)
{
//do whatever you want with the file
}
}
And the page File Upload ASP.NET MVC 3.0 contains good samples for you if you don't know how to write a controller to save files on file system.

User profile image asp.net mvc identity

I'm creating a web application using MVC 5 and Identity. I have so far created a registration system, but I would like to allow users to upload a profile when they register.
I was wondering if it is possible to implement profile pictures with asp.net identity?
Yes. Assuming you're using the default Entity Framework implementation, you can extend the ApplicationUser in a file called Models/IdentityModels.cs.
You can store the image in the database or elsewhere on the file system.
One way to store it in the database is using a byte array in the model (which I believe maps to varbinary(max))...
public class ApplicationUser : IdentityUser
{
public byte[] Image { get; set; }
}
Details on how to save upload an image and save in the database via EF can be found here...
Entity Framework 5 Code first adding an image
Or you can simply save the uploaded file to the file system or to blob storage, then store the path or URL to the image...
public class ApplicationUser : IdentityUser
{
public string ImagePath { get; set; }
}
Best thing todo is to create a second table (or add a column to the current table), add a file upload feature to the registration form. When registration is successful add the picture to the db with EntityFramework. Create a page to return the picture by the userid so you can include it in a page somewhere.
Something like this http://blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates.aspx but with a profile picture

Override partial class field in ASP MVC model

In my ASP MVC project, whenever I add a new table to my project two models are created. One under the Text Templating Transformation Toolkit (file w/.tt extension), and another outside this in the general Models folder (this one seems to want to default with a "1" at the end of the file).
Whenever a change is made to the database, it seems all the models under the .tt file are refreshed according to the fields currently existing in the database on that table. The files outside this is the general Models folder, however are left as they were. Because of this, we have put all of our model validation methods in these .cs files (with the "1" at the end of the file name).
However, in one instance I needed to remove a field from the model under the .tt file in order to perform a validation in the other .cs file. This is the validation I perform:
private string agentId;
//here, AgentId overrrides the field in the BankListAgentId.cs file,
//which MUST be commented out.
[DisplayName("Agent ID")]
public string AgentId
{
get { return agentId; }
set { agentId = this.scrubAgentId(value); }
}
Is there a way to specify in this .cs file that the AgentId field here (the file with the "1" at the end of the name) overrides the AgentId field in the.csfile found under the.tt` file?
As far as I know it can't be done. But there are few tricks that can you do.
Change name of your property to eg. InternalAgentId and also change in EDMX that field to be protected or even private. Then in your code reference to InternalAgentId:
public string AgentId
{
get { return this.InternalAgentId; }
set { this.InternalAgentId = this.ScrubAgentId(value); }
}
If you need that property in linq you can look at Microsoft Linq Translation
Another way is to change your T4 to generate partial methods and invoking it inside generated properties. I think that one of Entity Framework template already do that.

Creating a list in asp.net mvc without javascript

I want to create a form where the user creates a list and then saves it. The list can have an arbitrary number of rows. The user cannot save the list until it is complete (all rows/items are added) and I cannot use javascript to do it all on the clientside before posting.
The form will create a contact, like in an address book or something. The entity looks like this:
public class Contact
{
public string Name { get; set; }
public string Company { get; set; }
public List<ContactRow> ContactRows { get; set; }
}
The ContactRow looks like this:
public class ContactRow
{
public string Type { get; set; }
public string Value { get; set; }
}
So, basically it is a contact with a name and a company. The contact has a list of contact rows, where each row has a type (phone, email, etc) and a value (555 - 12334, test#email.com, etc).
My form will contain two ordinary textboxes for Name och Company respectively. But I'm not sure how to handle the list with contact rows. What I want the user to be able to do is adding new rows, editing rows and deleting rows. All this must be done before the save button i clicked, i.e. the list must be all done when saving.
This is not very hard to to with javascript and I've already done that. But now I want to implement this functionality without javascript. It is ok to post to the server while building up the list, but the list cannot be saved until it is done.
Ideas?
If you do not wish to use javascript a postback whilst building up the list is all you can do.
This user experience is often deemed poor as work is ongoing, but is the best starting point when using progressive-enhancement to make your application more user friendly.
The OP stated Javascript was not an option. I feel your pain as one of our applications had a similar requirement. We have a construct called an updateable list with the same functionality as you outlined.
We perform data handling on the server. Each list is displayed in a table. Each row contains the item data and has an action icon associated with it. The default is to display and we support new, updated and deleted actions.
After the user enters data for an item they press a button to add or remove the item from the list. Selecting existing items allows for an update operation. The list, and status, is determined on the server and the client does not run Javascript.
As #rich.kelly pointed out you will need to go to the server for each operation. It takes longer to do anything and your session gets a workout but it meets the client requirements.

How to create a MVC 2 DisplayTemplate for a field whose display format is dependent on another field?

If I have a property whose display format is dependent on the value of another property in the view model how do I create a display template for it?
The combination of field1's display being dependent on field2's value will be used throughout the app and I would like to encapsulate this in a MVC 2 display template.
To be more specific, I've already create a display template (Social.ascx) for custom data type Social that masks a social security number for display. For instance, XXX-XX-1234.
[DataType("Social")]
public string SocialSecurityNumber { get; set; }
All employees also have an employeeID. Certain companies use the employee's social security number as either the whole employee id or as part of it. I need to also mask the employeeID if it contains the social. I'd like to create another display template (EmpID.ascx) to perform this task.
[DataType("EmpID")]
public string EmployeeID { get; set; }
The problem is that I don't know how to get both properties in the "EmpID" template to be able to perform the comparison.
Thanks for the help.
This might not directly answer your question but I'm wondering why the Employee ID is only sometimes marked out. I know there are legal requirements to doing so for the social but the employee ID is (or should be) somewhat sensitive as well. I would think it would be better to default to marking out both unless the logged in user had whatever privileges made them fully readable.
If you can do this that would probably simplify your logic/design somewhat.
Cant you create a custom ViewModel class containg both SocialSecurityNumber and EmployeeID and create a custom editor template for that class?

Resources