至少,任何用户都可以为任何员工预订假期,
我已将 [Authorization] 添加到控制器和 @if (User.Identity.IsAuthenticated)
在布局中,因此只有登录的用户才能查看页面。但是我怎么能只允许用户为他们自己预订假期呢?
类似于 if loggedInUserID(这是在创建用户时自动分配的吗?)=currentPersoID,尽管这只是一个猜测,我可能不得不将相同的 loggedInUserID 分配给 personID。
编辑:
[HttpPost]
public ActionResult Create(Holiday holiday)
{
var holidays = db.Holidays.Include("Person");
HolidayList model = new HolidayList();
//run through person
foreach (Person person in model.PList4DD)
{
//if Logged in user = person name
if (HttpContext.User.Identity.Name == person.Name)
{
//allow
if (ModelState.IsValid)
{
db.Holidays.AddObject(holiday);
db.SaveChanges();
return RedirectToAction("Index");
}
}
else
{
return RedirectToAction("Index");
}
}
model.PList4DD = db.People.ToList();
model.HList4DD = db.Holidays.ToList();
ViewBag.Id = new SelectList(db.People, "Id", "Name", holiday.Id);
return View(holiday);
}
谢谢