简体   繁体   中英

Best practice to set up multiple companies with different accounts and views in an ASP.NET MVC project

I'm writing a program using ASP.NET MVC. It's a simple program that will allow dispatchers to track calls and field units' statuses.

Here's where it gets confusing and I'm hoping for some advice on best practice.

The view structure will be the exact same for each company. The page is basically set up this way for every company every time:

------------------------------------------------------------
(Header) Company logo - (buttons to filter this company's data you see in the three tables below)
------------------------------------------------------------
New things to be dispatched table
------------------------------------------------------------
New things that have been dispatched
------------------------------------------------------------
Units you've filtered and are checking statuses for in a table.

Pretty simple. However, while each company will have the same view structure, the data will be different for each user. For example, in the header, the logo and buttons to filter the three tables will be different for every company.

The tables below the header will have different data for each company.

Also, I want users to be able to access the back end for their company only (add / delete users for just their company, etc.)

It will be set up so I can use the same database and tables for everyone, though.

Here's my question. Would you set up a new view for each company to customize things? For example, you are an employee assigned to company X. If you log in and have that assignment in your table, then you'll load your company's view with customized data and logo. My concern with this is redundancy. The basic code will be the same so if I have to update some global setting, I'll have to do it hundreds of times.

Or do you set up one view with a bunch of if/then statements... like if the employee belongs to company X, set this logo and allow access to this data. if employee belongs to company y, set this other logo and data, etc. The problem with this is hundreds of if then stuff and a very long view.

Any thoughts on best practice for this?

Thank you for all your help!

I'm not quite sure what I would do in your case and it also depends a bit on the situation, here's why:

If those different companies are different customers of yours which might have different demands regarding the UI, then a separate UI would make sense.

If you are expecting them to demand different logics on the other hand, then maybe a different action might come in handy, too.

If the UI and the logic are expected to stay the same for all of them (which normally on the long run is not the case) then I would store images like the logo and all those things in a company specific folder in your wwroot folder, store the company info of a user in a session variable and then load the logo etc. like so: src="/@Session[companyId]/logo.png" .

You can load like this also customized javascript (eg to render the buttons) and even pass the companyId to you ajax functions that load the content of tables etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM