1
votes

I'm working on an MVC5 project, where users can create orders. There are 2 roles for each order. One is customer, and one is processor. The customer can create orders and attach files, which the processor needs to execute the order. The customers files have to be visible for the processor, but the processors files must only be visible to him and other processors. However, he can decide on a file-to-file basis if the customer is able to see the file in the uploads section.

Now when I started working on the file upload I was told that it should be just that: Customers and Processors can upload files, which everybody can see. So I decided to aim for a rather simple approach, which I extended more and more based on the extending requirements/demands. Problem is: Now the whole thing got so complex that my simple approach seems terribly confusing and is a PITA to modify.

My approach is basically this:

  • Customer creates a new order and uploads a file: On upload, the file is stored on the server in /~/uploads/cust/temp/{tempfolderid}. The order does not have an id before its sent, so I had to create a temporary id, which I store in the viewmodel. This temporary id is basically based on customername+date with timestamp of creating the order, to ensure it is unique. When the order is sent, the file is moved to /~/uploads/cust/{orderid}. If the customer just closes his browser without sending the order, my temp basically is cluttered with temporary files. To counter this: Every day all files in the temp folder that are older than 14 days are deleted.

  • Customer opens an existing order and uploads a file: The file is stored in /~/uploads/cust/{orderid}. The customer can't make any changes to existing orders except uploading files, which means there's no save button. Hence I am not working with a temp folder here, but instead just process his changes directly.

  • Customer opens an existing order and checks the uploaded files: Every file in the folder "/~/uploads/cust/{orderid} is shown to him.

  • Processor creates a new order and uploads a file: (Processors can create their own orders and attach a customer to it themself -> the process isn't just started by the customer) When he uploads the file it is stored in /~/uploads/proc/temp/{temporderid}. The order again has no id until its sent, but since the customer is not allowed to see the files the processor uploaded they're stored in a different folder. When he clicks send, the file is moved to "~/uploads/proc/{orderid}".

  • Processor opens an existing order and uploads a file: The file is stored in the folder "/~/uploads/proc/{orderid}/temp". When he uploads a file that exists in the "/~/uploads/proc/{orderid}" folder already, only the version in the temp folder is shown to him (the orders update with partialviews immediately upon upload, without reloading the page) and once he saves, the original file is deleted and the new one is moved from the temp folder to the orderid folder.

  • Processor opens an existing order and deletes a file: Each file has a little x-button next to it. When the processor clicks on it, the file is moved to "/~/uploads/proc/{orderid}/deleteTemp". When he uploads a new file and (before saving) presses the x-button, the file is deleted from the "/~/uploads/proc/{orderid}/temp" folder again. When he uploads a file that exists already in the "/~/uploads/proc/{orderid}" folder and presses the x-button, then the original version is moved to the deleteTemp folder, and the new version is simply deleted from the temp folder. Once he saves his changes, every file in the deleteTemp folder is deleted. If he doesn't save his changes, the next time the order is opened the content of the deleteTemp folder is moved back to the {orderid}-folder and the content of the temp-folder is deleted.

  • Processor shares a file: Each file that has been uploaded by a processor has another little button next to it "share file". On click it creates a copy of the file in the "/~/uploads/proc/{orderid}/sharedFiles" folder. This folder has its own /temp/ and /tempDelete/ folders aswell, which function similarly to the ones in the two processes above. This is needed to make sure changes are only processed when they order is actually saved.

  • Customer opens an existing order and checks for the uploaded files (now with shared files among them): Every file in the folder "/~/uploads/cust/{orderid}" and in the folder "/~/uploads/cust/{orderid}/sharedFiles" is shown to him.

Now while this is already pretty complex, it gets even worse: Once an order is finished or cancelled, not even the processor can change any information on the order. However he still must be able to upload files and change shared file clearances. This works similarly to the "customer opens an existing order and uploads a file" but again uses different methods.

There are also files that the application itself creates. They're stored in another different folder and must be visible (and shareable) by the processor.

Now my question is: Is there another, easier way to manage file uploads? Without thousand different paths and without having multiple instances of the same file and without so many temp-folders? Maybe by linking the files to the actual orders instead of just showing the contents of a folder that has the same ID as the order every time?

I didn't create this project and I'm not sure why they didn't include the file upload initially. I just took the project and was told to implement more features.

Edit: Added an idea as an answer.

1

1 Answers

0
votes

I've had an idea:

I create a new Model called uploadedFiles with the following values:

AuftragsID | FileID | File | isShared | UploadedByRole

I add this to the ViewModel:

 public IEnumerable<uploadedFiles> myUploadedFiles { get; set; }

On deleting, overwriting and sharing I simply update the ViewModel and when a user clicks on save I write the change to the database.

For this to work I have to be able to save a file to my database. Is that possible?