They could help me with the following:
I have two related models, one Customers and another Orders, I try to generate a report with crystal reports of the orders generated, they would be something like when a customer buys something in a store, a purchase order is generated but this order contains inside of your model the data of the client that generated the order, ok, I intend that when generating the report of this order, the customer's data will appear as identification, email, address, etc., the problem is that I am sooooooooo new in the MVC theme and even more in crystal report, and the report only shows me the id of the client How to do to nest the data of the client in the report? I leave some additional data.
my models:
public class Order
{
[Key]
public int OrderId { get; set; }
[Display(Name = "Consecutivo")]
public string Consecutive{ get; set; }
public int CustomerId { get; set; }
public virtual Customer Customer { get; set; }
[Required(ErrorMessage = "Este campo obligatorio")]
[Display(Name = "Fecha")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime EntryDate { get; set; }
public int PaymentTypeId { get; set; }
public virtual PaymentType PaymentType { get; set; }
}
public class Customer
{
[Key]
public int CustomerId { get; set; }
public int TypeDocumentId { get; set; }
public virtual TypeDocument TypeDocuments { get; set; }
[Required(ErrorMessage = "Este campo es obligatorio")]
[MaxLength(50, ErrorMessage = "Max 50 caracteres")]
[RegularExpression("^[0-9]*$", ErrorMessage = "Sólo caracteres numéricos")]
[DataType(DataType.Text)]
[Display(Name = "Nº Documento")]
[Index("Index_Document_Customer", IsUnique =true)]
public string Document { get; set; }
[Required(ErrorMessage = "Este campo es obligatorio")]
[MaxLength(250, ErrorMessage = "Max 250 caracteres")]
[DataType(DataType.Text)]
[Display(Name = "Nombre")]
public string FirstName { get; set; }
[Required(ErrorMessage = "Este campo es obligatorio")]
[MaxLength(50, ErrorMessage = "Max 50 caracteres")]
[DataType(DataType.Text)]
[Display(Name = "Apellido")]
public string LastName { get; set; }
[MaxLength(250, ErrorMessage = "Max 250 caracteres")]
[DataType(DataType.EmailAddress)]
[Display(Name = "e-mail")]
public string Email { get; set; }
[MaxLength(250, ErrorMessage = "Max 250 caracteres")]
[DataType(DataType.Text)]
[Display(Name = "Dirección")]
public string Address { get; set; }
[MaxLength(25, ErrorMessage = "Max 25 caracteres")]
[RegularExpression("^[0-9]*$", ErrorMessage = "Sólo caracteres numéricos")]
[DataType(DataType.PhoneNumber)]
[Display(Name = "Teléfono")]
public string Phone { get; set; }
[Display(Name ="Nombre")]
public virtual string FullName { get{ return string.Format("{0} {1}", FirstName, LastName); } }
public virtual ICollection<Order> Orders { get; set; }
public virtual ICollection<OrderDetail> OrderDetails { get; set; }
}
here the controller code:
db.SaveChanges();
transaction.Commit();
ReportDocument rd = new ReportDocument();
rd.Load(Path.Combine(Server.MapPath("~/Reports"), "Orders.rpt"));
rd.SetDataSource(db.Orders.Where(o=>o.OrderId == orderAux.OrderId).ToList());
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, SeekOrigin.Begin);
return File(stream,"aplicattion/pdf",string.Format("{0}.pdf",orderAux.OrderId));'