Sneha K

Sneha K

  • 1.2k
  • 527
  • 195.3k

Array in MVC4

Dec 10 2015 1:58 AM
Hi i am going to use Array Collection in my project
 TaxField Table
 TaxFieldID Display Name  Print Name
 FD713788-B5AE-49FF-8B2C-F311B9CB0CC4 TinNo TinNo
 64B512E7-46AE-4989-A049-A446118099C4 CstNo CstNo
59A2449A-C5C6-45B5-AA00-F535D83AD48B CinNo CinNo
 2F405521-06A0-427C-B9A3-56B8931CFC57 ServiceTaxNo ServiceTaxNo
TaxInfoTaxField Table 
 TaxInfoTaxFieldID TaxFieldIDField Value 
 NewGuid() TinNo Eg(FD713788-B5AE-49FF-8B2C-F311B9CB0CC4)
 TinNo
 NewGuid()
CstNoEg(64B512E7-46AE-4989-A049-A446118099C4)

 CstNo
 NewGuid()                                   CinNoEg(59A2449A-C5C6-45B5-AA00-F535D83AD48B) CinNo
 NewGuid()                                   ServiceTaxNo Eg(2F405521-06A0-427C-B9A3-56B8931CFC57) ServiceTaxNo
 
 
 My  View Contain 6 fields  TinNo, CstNo, PanNo, ServiceTaxNo, CinNo, ExciseRegNo. I need to save these six fields in TaxInfoTaxField Table in the above format.  Each  fiels have Default value which is mentioned in the TaxField Table.
 
Now i am going to use Array not Array list collection to save these values in tables . I want to set Array Size as 6 before i used for each loop  to save these values in table but it is not working.
 
 That is  
 
My Model
 
 
public partial class TaxFieldModel
{
public System.Guid TaxFieldID { get; set; }
public string DisplayName { get; set; }
public string PrintName { get; set; }
 
}
public partial class TaxInfoTaxFiledModel
{
public System.Guid TaxInfoTaxFieldID { get; set; }
public Nullable<System.Guid> TaxInfoID { get; set; }
public Nullable<System.Guid> TaxFieldID { get; set; }
public string FieldValue { get; set; }
}
 
My ViewModel
 
public class CustomerViewModel
{
public string TinNo { get; set; }
public string CstNo { get; set; }
public string ExciseRegNo { get; set; }
public string PanNo { get; set; }
public string ServiceTaxNo { get; set; }
public string CinNo { get; set; }
 
public List<TaxFiled> TaxFields { get; set; }
public List<TaxInfoTaxFiled> Tfs { get; set; } 
}
public class VisitorsEntities1 : DbContext
{
public DbSet<Sample_Customer.Models.CustomerModel.TaxFieldModel> TaxField { get; set; }
public DbSet<Sample_Customer.Models.CustomerModel.TaxInfoTaxFiledModel> TaxInfoTaxFiled { get; set; }
}
 
My Controller
 
 ArrayList Alist = new ArrayList();
{
Alist.Add("FD713788-B5AE-49FF-8B2C-F311B9CB0CC4");
Alist.Add("64B512E7-46AE-4989-A049-A446118099C4");
Alist.Add("376D45C8-659D-4ACE-B249-CFBF4F231915");
Alist.Add("59A2449A-C5C6-45B5-AA00-F535D83AD48B");
Alist.Add("03ADA903-D09A-4F53-8B67-7347A08EDAB1");
Alist.Add("2F405521-06A0-427C-B9A3-56B8931CFC57");
}
 
ArrayList objValue=new ArrayList();
{
objValue.Add(viewmodel.TinNo);
objValue.Add(viewmodel.CstNo);
objValue.Add(viewmodel.PanNo);
objValue.Add(viewmodel.CinNo);
objValue.Add(viewmodel.ExciseRegNo);
objValue.Add(viewmodel.ServiceTaxNo);
}
foreach(var tax in Alist)
foreach (var tax in viewmodel.Tfs )
{
foreach (var i in Alist)
{
tax.FieldTypeID = Guid.Parse(i.ToString());
}
foreach (var j in objValue)
{
tax.FieldValue = j.ToString();
}
db.TaxInfoTaxFiled.Add(tax);
}
 
 But the above method is not working  to save this six field in TaxInfoTaxField table in the above format. So now i am going to use Array and FOR loop to save these details in TaxinfoTaxfield Table.
 
1) First Have to declare the Size of Array is 6 ( because it contain Six fields) before that i need to save those Default Guid Id's in Array
 
eg
Guid[] Alist = new Guid[6];
new Guid("FD713788-B5AE-49FF-8B2C-F311B9CB0CC4");
new Guid ("64B512E7-46AE-4989-A049-A446118099C4");
new Guid("376D45C8-659D-4ACE-B249-CFBF4F231915");
new Guid("59A2449A-C5C6-45B5-AA00-F535D83AD48B");
new Guid("03ADA903-D09A-4F53-8B67-7347A08EDAB1");
new Guid("2F405521-06A0-427C-B9A3-56B8931CFC57");
I donno this is correct or not  and next i have to save that six fields in view model in Array . How to do that
 
 
 
ArrayList objValue=new ArrayList();
{
objValue.Add(viewmodel.TinNo);
objValue.Add(viewmodel.CstNo);
objValue.Add(viewmodel.PanNo);
objValue.Add(viewmodel.CinNo);
objValue.Add(viewmodel.ExciseRegNo);
objValue.Add(viewmodel.ServiceTaxNo);
}
 Here i saved this in ArrayList .But how to do this Array . Now it want to calculate in this format eg. Guid[0] objvalue[0]  Guid[1] objvalue[1]. then only it save the value of particular field in FieldValue Column and their Id in TaxFieldID of TaxInfoTaxField Table. I find the logic but i donno how to do this . So please any one tell me how to store the Default GUID's and fields in View model  in array and  tell me the For loop  method to calculate   (Guid[0] objvalue[0] Guid[1] objvalue[1].) in this format
 
 
Thanks.. 
 
 
 
 
 
 

Answers (2)