Мне не удалось найти что-либо на этом сайте. У меня есть ReservationDate
модель,
namespace Mijem_test_app.Models
{
[HandleError]
/*
This model includes the location,
the person who reserved it and
FOR when they reserved it (not
when they reserved it)
*/
public class ReservationDate
{
//key
public int Id { get; set; }
//location name
[Required]
public Reservation Reservation { get; set; }
//contact
[Required]
public Contact Contact { get; set; }
//date reserved for
[Required]
public DateTime ReservedDate { get; set; }
//information from textbox
[Required]
public string InfoFromTextBox { get; set; }
public bool Deleted { get; set; }
public ImagesUploaded ImageURL { get; set; }
}
}
И в моем контроллере я пытаюсь CREATE
записать,
[HttpPost]
public ActionResult Save(ReservationDate reservation)
{
var _contactID = (int) TempData["ContactID"];
var _contact = _context.Contacts
.Single(r => r.Id == _contactID);
var _location = _context.Reservations
.Single(r => r.Name == reservation.Reservation.Name);
var _ReservedDate = (DateTime)TempData["BookDate"];
var _InfoFromTextBox = (string)TempData["InfoFromTextBox"];
var __reservation = new ReservationDate
{
ReservedDate = _ReservedDate,
Contact = _contact.Id,
Reservation = _location.Id,
InfoFromTextBox = _InfoFromTextBox,
Deleted = false
};
_context.ReservationDates.Add(__reservation);
_context.SaveChanges();
return View("Index");
}
Код прерывается на
Contact = _contact.Id,
Reservation = _location.Id,
и отладчик сообщает мне Cannot implicitly convert type 'int' to 'app.Models.Contact
и Cannot implicitly convert type 'int' to 'app.Models.Reservation
соответственно. Что я делаю неправильно? Мои Reservation
и Contact
модели есть,
namespace app.Models
{
[HandleError]
public class Reservation
{
//unique ID of location
public int Id { get; set; }
//name of location
[Required]
[StringLength(255)]
public string Name { get; set; }
public int Ranking { get; set; }
public bool Favorites { get; set; }
}
}
и
namespace app.Models
{
[HandleError]
public class Contact
{
public int Id { get; set; }
[Required]
[StringLength(255)]
[Display(Name = "Contact Name ...")]
public string Name { get; set; }
[Required]
[StringLength(255)]
[Display(Name = "Contact Type")]
public string ContactType { get; set; }
[Required]
[Display(Name = "Phone:")]
public long ContactNumber { get; set; }
[Column(TypeName = "date")]
[Display(Name = "Birthdate")]
public DateTime BirthDate { get; set; }
}
}
Я все перепробовал .. Думаю, возможно, я неправильно использую LINQ? Я в недоумении.