Sneha K

Sneha K

  • 1.1k
  • 527
  • 190.1k

How to create View based on Controller Code in mvc4?

Mar 22 2016 9:15 AM
Hi i want to create one view based on Controller code . i want one idea or solution for my problem.  I will explain my issue with example.
 
 Controller code  
 
public ActionResult customerid()
{
List<Customer> n = (from c in db.Customers where c.IsDeleted == false select c).ToList();
var customertype = string.Empty;
for (var i = 0; i < n.Count; i++)
{
var objCustomerName = n[i].DisplayName;
var objCustomerID = n[i].CustomerID;
var objCusCreatedDate=n[i].CreatedDate;
 
var objNextDate = objCusCreatedDate.GetValueOrDefault().AddDays(120);
var salescount = (from sc in db.SalesOrders where sc.CustomerID==objCustomerID && sc.CreatedDate >= objCusCreatedDate && sc.CreatedDate<= objNextDate select sc.SalesOrderID).Count();
if (salescount <= 3&& salescount> 0)
{
customertype = "Exisiting Customer";
}
else if (salescount >= 3)
{
customertype = "Potential Customer";
}
else
{
customertype = "New Customer";
}
//var details = (from c in db.Customers where c.IsDeleted == false select c);
}
return View();
}
 
Wanted Output 
 
                     
 
I want to create  a view same as like which is mentioned in the above image. First i want to list all the Customer Name (which is from Customer table)
 
Customer Table
 
CustomerID uniqueidentifier primarykey not null,
DisplayName varchar(100) null
 
then i want to create one column manually in view Customer Type. The value for Customer Type have to get it from  Controller(customertype = "Potential Customer";)
 
 Eg 
 
 Customer Name Customer Type
 TBS Sizing Mill Existing Customer
 Kallam Spinning Mill Potential Customer
 Suryaprabha Sizing New Customer
 Skyweaves Existing Customer
 
 
 
 How i do this this is my task. please i did the controller part . please any one help me to do this task..
My Model 
 
public class CustomerTypeViewModel
{
public System.Guid CustomerID { get; set; }
public string CustomerName { get; set; }
public DateTime CreatedDate { get; set; }
public string SalesCount { get; set; }
public string CustomerType { get; set; }
}
 

Answers (1)