mike idowu

mike idowu

  • 1.2k
  • 434
  • 61.9k

ASP.NET MVC - How to update and upload complex Excel file

Dec 4 2017 2:52 AM
I have this Excel File which I tried to upload. It has Parent Category
 
 
 
Model
 public partial class CategoryLevel 
{ 
public long CategoryID { get; set; } 
public string CategoryName { get; set; } 
public string OPTION_VALUE { get; set; } 
public Nullable<int> ParentID { get; set; } 
public Nullable<int> ParentID1 { get; set; } 
public Nullable<int> ParentID2 { get; set; }
 
Data sample
 
 
Controller
The code ihave written so far is in the controller.
 

Without clicking twice to upload, it will retrieve the data it has saved to perform the following manipluations.

  1. From the Excel, Where Category Code is equal to Parent Category, it means its a child of the corresponding parent. So, it will save the CategoryID of its parent as its ParentID
  2. From the Excel, where Category Name is Null, it means its a root and has no parent
  3. ParentID1 is the Level - It can get to level N
  4. ParentID of the Root Category(Level 1) will be set to 0
  5. ParentID of the Child Category will be the CategoryID of the direct parent
  6. Note that CategoryID is System Generated (auto-increment)

Please how do I achieve this using the same controller, and also with the same instance of upload.

 
 

Attachment: controller.zip

Answers (3)