0
使用MVC Orchard服務文件允許用戶在'HoursWorkedToday'表中輸入新記錄,允許用戶輸入當天工作了多少小時。POST後不會創建新記錄
//HoursWorkedService
public class HoursWorkedService : IHoursWorkedService
{
private IRepository<HoursWorkedPerDay> _repository = null;
public HoursWorkedService(IRepository<HoursWorkedPerDay> Repository)
{
_repository = Repository;
}
public Models.HoursWorkedPerDay Create(HoursWorkedPerDay newRecordForHoursWorked)
{
_repository.Create(newRecordForHoursWorked);
return newRecordForHoursWorked;
}
//IHoursWorkedService
public interface IHoursWorkedService : IDependency
{
HoursWorkedPerDay Create(HoursWorkedPerDay newRecordForHoursWorked);
}
//controller
[HttpPost, ActionName("HoursWorkedPerDay")]
public ActionResult HoursWorkedPerDayPOST(int userId, int hours)
{
DateTime TodaysDate = DateTime.UtcNow;
HoursWorkedPerDay HoursPerDay = new HoursWorkedPerDay();
HoursPerDay.Date = TodaysDate;
HoursPerDay.WorkerRecord_Id = userId;
HoursPerDay.HoursWorked = hours;
_hoursWorked.Create(HoursPerDay);
_notifier.Add(NotifyType.Information, T("Thank you, Hours Added."));
return RedirectToAction("Index");
}
但後門柱我得到的「網站無法顯示」
日誌顯示:
無法將NULL值插入列「ID」,表「Orchard.Timekeeper.dbo。 Timekeeper_HoursWorkedPerDay「;列不允許有空值。 INSERT失敗
在我的移民文件,我有「身份證」設置爲.ContentPartRecord(),這我以爲創造了一個記錄時自動服務使用
你能發佈相關的遷移嗎? – Hazza