Please leave reading the codings part. I mentioned my issue in last. Why i include my DB and Codings means suppose if you didn't understand my issue you can refer this (i.e) what i did from the Starting Itself.
In my project i have Customer Master. It contain 16 fields like
1) Customer ID2) Customer Name 3) Alias 4) Customer Type 5) Street 6) Location 7) Area 8) City 9) Stat 10) Country 11 Tin No 12 Cst No 13 Service Tax No 14 Excise Reg No 15 Pan No 16) Cin No
Customer
CustomerID Primary key Uniqueidentifier not null,
Display Name Varchar(100) null,
Print Name Varchar(100) null,
CustomerType ID Uniqueidentifier null.
Customer Address
CustomerAddressID Primary key Uniqueidentifier not null,
CustomerID Uniqueidentifier null,
AddressID Uniqueidentifier null.
Address
AddressID Primary key Uniqueidentifier not null,AddressTypeID Uniqueidentifier null,
DisplayName Varchar(100) null,
SalutationID Uniqueidentifier null,
PrintName Varchar(100) null,
SimpleMode bit null,
DetailMode bit null,
Street Varchar(100) null,
Location Varchar(100) null,
Place Varchar(100) null,
AreadID Uniqueidentifier null,
Pincode Varchar(100) null.
DisplayName Varchar(100) null,
PrintName Varchar(100) null,
CityID Uniqueidentifier null.
SalutationID Primary key Uniqueidentifier not null,
DisplayName Varchar(100) null,
PrintName Varchar(100) null
City
CityID Primary key Uniqueidentifier not null,
DisplayName Varchar(100) null,
PrintName Varchar(100) null ,
StateID Uniqueidentifier null.
StateId Primary key Uniqueidentifier not null,
DisplayName Varchar(100) null ,
PrintName Varchar(100) null ,
CountryID Uniqueidentifier null.
Country
CountryID Primary key Uniqueidentifier not null,
DisplayName Varchar(100) null ,
PrintName Varchar(100) null.
CustomerTaxInfo
CustomerTaxInfoID Primary key Uniqueidentifier not null,
CustomerID Uniqueidentifier null,
TaxInfoReference Varchar(100) null ,
TaxInfoID Uniqueidentifier null,
Taxfield TaxFieldID PrimaryKey Uniqueidentifier not null,
DisplayName Varchar(100) null ,
PrintName Varchar(100) null.
TaxInfo
TaxInfoID PrimaryKey Uniqueidentifier not null,
DisplayName Varchar(100) null ,
PrintName Varchar(100) null.
TaxInfoTaxField
TaxInfoTaxFieldID PrimaryKey Uniqueidentifier not null,
TaxInfoID Uniqueidentifier null,,
TaxFieldID Uniqueidentifier null,
FieldValue big int,
And My Controller
using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sample_Customer.Models;
namespace Sample_Customer.Controllers
{
public class CustomerController : Controller
{
VisitorsEntities1 db = new VisitorsEntities1();
//
// GET: /Customer/
public ActionResult Index()
{
return View();
}
public ActionResult Create()
{
VisitorsEntities1 db = new VisitorsEntities1();
ViewBag.Country = new SelectList(db.Country, "CountryID", "DisplayName","PrintName");
ViewBag.State = new SelectList(db.State, "StateID", "DisplayName", "PrintName");
ViewBag.City = new SelectList(db.City, "CityID", "DisplayName", "PrintName");
ViewBag.Area = new SelectList(db.Area, "AreaID", "DisplayName", "PrintName");
return View();
[HttpPost
public ActionResult Create(CustomerViewModel viewmodel) {
ViewBag.Country = new SelectList(db.Country, "CountryID", "DisplayName","PrintName");
ViewBag.State = new SelectList(db.State, "StateID", "DisplayName", "PrintName");
ViewBag.City = new SelectList(db.City, "CityID", "DisplayName", "PrintName");
ViewBag.Area = new SelectList(db.Area, "AreaID", "DisplayName", "PrintName");
var Customerobj = new Customer()
{
CustomerID= Guid .NewGuid (),
DisplayName = viewmodel.CustomerName,
PrintName = viewmodel .CustomerName,
CustomerType =viewmodel.CustomerTypeID,
};
var CustomerTypeobj = new CustomerType()
{
CustomerTypeID= Guid.NewGuid(),
DisplayName = viewmodel.CustomerType,
PrintName= viewmodel.CustomerType
};
var CustomerAddressobj = new CustomerAddress()
{
CustomerAddressID= Guid.NewGuid(),
CustomerID= viewmodel.CustomerID,
AddressID= viewmodel.AddressID
};
var Addressobj = new Address()
{
AddressID = Guid.NewGuid(),
AddressTypeID = viewmodel.AddressTypeID,
DisplayName= viewmodel.CustomerName,
Salutation= viewmodel.Alias,
PrintName= viewmodel.CustomerName,
Street=viewmodel.Street,
Location= viewmodel.Location,
Place= viewmodel.Place,
Area = viewmodel.AreaID,
PinCode= viewmodel.PinCode
};
while Saving the data in Database using Code First approach is working fine upto Address.That is It saving the data up to Address details in DB is working Fine. But I got a problem while Saving the Tax details.In my view I have Six Fields like TinNo , CstNo, PanNo, ExciseRegNo, ServiceTxNo, CinNo.Each one have Default value which is saved in TaxField Table.
Eg TinNo = FD713788-B5AE-49FF-8B2C-F311B9CB0CC4
CstNo = 64B512E7-46AE-4989-A049-A446118099C4
CinNo =59A2449A-C5C6-45B5-AA00-F535D83AD48B
Same as like that other field PanNo, ExciseRegNo, ServiceTxNo contain Default Value .
Suppose now I am going to save one customer Details in CustomerMaster view and enter the TinNo ,CstNo, PanNo, ExciseRegNo, ServiceTxNo, CinNo, means it have to save the values(Which is entered in the Field of TinNo in the View) in FieldValue and their ID ( eg TinNo = FD713788-B5AE-49FF-8B2C-F311B9CB0CC4) in TaxFieldID of TaxInfoTaxField Table.That is I need to save those six Field in same column not in same row and same cell. Suppose if I enter the TinNo means it have to save the value in FieldValue and ID in TaxFieldID. Then I enter the CstNo it will automatically go and create the new row and have to save the Value and ID in the FieldValue and TaxFieldID. So for each Customer it will create 6 rows automatically while Saving TaxDetails. How to do this MVC4 ?
Saineshwar BageriPosted Dec 3, 2015, 1:20 AM
Saineshwar BageriPosted Dec 4, 2015, 4:11 AM
{
Type type = typeof(City); // City class name
PropertyInfo[] properties = type.GetProperties();
foreach (PropertyInfo property in properties)
{
City tv = new City(); //create object of class which you want to save
tv.CityID = (int)property.GetValue(TM.City.CityID, null); // Assiging value
tv.CityName = (string)property.GetValue(TM.City.CityName, null); // Assiging value
tv.City.Add(City);
tv.SaveChanges();
}
return View();
}
Sneha KPosted Dec 3, 2015, 11:56 PM
TaxField table
TinNo :
Need to Save Format in TaxInfoTaxFieldTable
TinNo = FD713788-B5AE-49FF-8B2C-F311B9CB0CC4
CstNo = 64B512E7-46AE-4989-A049-A446118099C4
CinNo =59A2449A-C5C6-45B5-AA00-F535D83AD48B
TaxInfoTaxFieldID
TaxFieldID
FieldValue
NewGuid()
TinNoID Eg(FD713788-B5AE-49FF-8B2C-F311B9CB0CC4)
TinNo
NewGuid()
CstNoID Eg(64B512E7-46AE-4989-A049-A446118099C4 )
CstNo
NewGuid()
CinNoEg(59A2449A-C5C6-45B5-AA00-F535D83AD48B)
CinNo
NewGuid()
ServiceTaxNo Eg(2F405521-06A0-427C-B9A3-56B8931CFC57)
ServiceTaxNo
public partial class TaxInfoTaxFiled
{
public System.Guid TaxInfoTaxFieldID { get; set; }
public NullableGuid> TaxInfoID { get; set; }
public NullableGuid> TaxFieldID { get; set; }
public NullableGuid> FieldTypeID { get; set; }
public string FieldValue { get; set; }
}
public partial class TaxField
{
public System.Guid TaxFieldID { get; set; }
public string DisplayName { get; set; }
public string PrintName { get; set; }
}
My ViewModel
public class TaxViewModel1
{
public System.Guid TaxInfoTaxFieldID { get; set; }
public System.Guid TaxInfoID { get; set; }
public NullableGuid> TaxFiledID { get; set; }
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 class VisitorsEntities1 : DbContext
{
public DbSet TaxField { get; set; }
public DbSet TaxInfo { get; set; }
public DbSet TaxInfoTaxFiled { get; set; }
}
My Controller
[HttpPost]
public ActionResult Index(TaxViewModel1 TVM)
{
Type type = typeof(TaxField);
PropertyInfo[] Info = new TaxInfoTaxField().GetType().GetProperties();
foreach (TaxInfoTaxField property in properties)
{
var Value = property.GetValue(TVM.TinNo, null);
var Value1 = property.GetValue(TVM.CstNo, null);
}
return View(Tax);
}
Type type = typeof(TaxField);
PropertyInfo[] Info = new TaxInfoTaxField().GetType().GetProperties();
And here we assigning the Value to the Variable. But how to assign the value to the Column .
And How to do save the Value in FieldValue and ID in TaxFieldID of TaxInfoTaxField Table in the above format which I mentioned. Please Correct my Controller Code . I am very very new to MVC . so only I struggling for this Small Concepts. Please correct my Controller Code and help me to save the Values in the TaxInfoTaxField table. And if you have a times means please explain me the Logic you used in Controller.
Sneha KPosted Dec 3, 2015, 6:05 AM
Saineshwar BageriPosted Dec 3, 2015, 5:33 AM
{
public int CountryID { get; set; }
public string CountryName { get; set; }
public City City { get; set; }
}
public class City
{
public int CityID { get; set; }
public string CityName { get; set; }
}
@Html.LabelFor(model => model.CountryName)
@Html.EditorFor(model => model.CountryName)
@Html.ValidationMessageFor(model => model.CountryName)
@Html.LabelFor(model => model.City.CityName)
@Html.EditorFor(model => model.City.CityName)
@Html.ValidationMessageFor(model => model.City.CityName)
public ActionResult Index(totalviewmodel TM)
{
Type type = typeof(City); // City class name
PropertyInfo[] properties = type.GetProperties();
foreach (PropertyInfo property in properties)
{
var value = property.GetValue(TM.City, null); // TM viewmodel Name
}
return View();
}
Sneha KPosted Dec 3, 2015, 2:11 AM
Eg TinNo = FD713788-B5AE-49FF-8B2C-F311B9CB0CC4
FD713788-B5AE-49FF-8B2C-F311B9CB0CC4 for Label TinNo
Sneha KPosted Dec 3, 2015, 1:52 AM