我已经建立了一个程序来创建员工日程安排并为员工分配这些日程安排。我可以毫无问题地分配时间表,但是如果已经将该时间表分配给员工,那么如果将该时间表从下拉列表中消失,我就会遇到问题,因此不会向两名员工提供相同的时间表。
@Html.DropDownListFor(m => m.ApplicationUser.ScheduleSum, new SelectList(Model.ScheduleBuilderList, "ScheduleSummary", "ScheduleSummary"), "Choose a schedule", new {@class = "form-control"}
如何在分配时让计划ID消失,如果未分配则重新出现?
如果您需要任何其他信息,请与我们联系。
日程表模型
public int Id { get; set; }
public int ScheduleId { get; set; }
public string DaysMatching { get; set; }
public string Days { get; set; }
public string ScheduleSummary { get; set; }
public string MondaySchedule { get; set; }
public string TuesdaySchedule { get; set; }
public string WednesdaySchedule { get; set; }
public string ThursdaySchedule { get; set; }
public string FridaySchedule { get; set; }
public string SaturdaySchedule { get; set; }
public string SundaySchedule { get; set; }
public string MondayStartTime { get; set; }
public string TuesdayStartTime { get; set; }
public string WednesdayStartTime { get; set; }
public string ThursdayStartTime { get; set; }
public string FridayStartTime { get; set; }
public string SaturdayStartTime { get; set; }
public string SundayStartTime { get; set; }
public string MondayEndTime { get; set; }
public string TuesdayEndTime { get; set; }
public string WednesdayEndTime { get; set; }
public string ThursdayEndTime { get; set; }
public string FridayEndTime { get; set; }
public string SaturdayEndTime { get; set; }
public string SundayEndTime { get; set; }
public string MondayFirstBreak { get; set; }
public string TuesdayFirstBreak { get; set; }
public string WednesdayFirstBreak { get; set; }
public string ThursdayFirstBreak { get; set; }
public string FridayFirstBreak { get; set; }
public string SaturdayFirstBreak { get; set; }
public string SundayFirstBreak { get; set; }
public string MondaySecondBreak { get; set; }
public string TuesdaySecondBreak { get; set; }
public string WednesdaySecondBreak { get; set; }
public string ThursdaySecondBreak { get; set; }
public string FridaySecondBreak { get; set; }
public string SaturdaySecondBreak { get; set; }
public string SundaySecondBreak { get; set; }
public string MondayLunch { get; set; }
public string TuesdayLunch { get; set; }
public string WednesdayLunch { get; set; }
public string ThursdayLunch { get; set; }
public string FridayLunch { get; set; }
public string SaturdayLunch { get; set; }
public string SundayLunch { get; set; }
员工模型
public class ApplicationUser : IdentityUser
{
public int ScheduleId { get; set; }
public ScheduleBuilder ScheduleBuilder { get; set; }
public string ScheduleSum { get; set; }
[Required]
[DataType(DataType.PhoneNumber)]
[RegularExpression(@"^\(?([0-9]{3})\)?[-]([0-9]{3})[-]([0-9]{4})$", ErrorMessage = "Please enter correct format with hyphens. i.e. 407-200-2000")]
[Display(Name = "Phone Number")]
public string PhoneNumbers { get; set; }
[Required]
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Required]
[Display(Name = "Last Name")]
public string LastName { get; set; }
[Required(ErrorMessage = "You must provide a valid Email")]
public string EmailAccount => Email;
}
安排控制器保存ActionResult
[HttpPost]
public ActionResult Save(ScheduleBuilder scheduleBuilder)
{
if (!ModelState.IsValid)
{
var viewModel = new TierViewModel()
{
ScheduleBuilder = scheduleBuilder
};
return View("ScheduleBuilder", viewModel);
}
if (scheduleBuilder.Id == 0)
{
_context.ScheduleBuilder.Add(scheduleBuilder);
if (scheduleBuilder.MondayStartTime != null)
{
scheduleBuilder.MondaySchedule = "Mon";
}
if (scheduleBuilder.TuesdayStartTime != null)
{
scheduleBuilder.TuesdaySchedule = "Tue";
}
if (scheduleBuilder.WednesdayStartTime != null)
{
scheduleBuilder.WednesdaySchedule = "Wed";
}
if (scheduleBuilder.ThursdayStartTime != null)
{
scheduleBuilder.ThursdaySchedule = "Thur";
}
if (scheduleBuilder.FridayStartTime != null)
{
scheduleBuilder.FridaySchedule = "Fri";
}
if (scheduleBuilder.SaturdayStartTime != null)
{
scheduleBuilder.SaturdaySchedule = "Sat";
}
if (scheduleBuilder.SundayStartTime != null)
{
scheduleBuilder.SundaySchedule = "Sun";
}
scheduleBuilder.Days = scheduleBuilder.SundaySchedule + " " +
scheduleBuilder.MondaySchedule + " " +
scheduleBuilder.TuesdaySchedule + " " +
scheduleBuilder.WednesdaySchedule + " " +
scheduleBuilder.ThursdaySchedule + " " +
scheduleBuilder.FridaySchedule + " " +
scheduleBuilder.SaturdaySchedule;
scheduleBuilder.DaysMatching = "Yes";
var startTime = scheduleBuilder.MondayStartTime + "-" + scheduleBuilder.MondayEndTime;
if (scheduleBuilder.MondayStartTime == null)
{
startTime = scheduleBuilder.TuesdayStartTime + "-" + scheduleBuilder.TuesdayEndTime;
}
if (scheduleBuilder.MondayStartTime == null && scheduleBuilder.TuesdayStartTime == null)
{
startTime = scheduleBuilder.WednesdayStartTime + "-" + scheduleBuilder.WednesdayEndTime;
}
if (scheduleBuilder.WednesdayStartTime == null && scheduleBuilder.MondayStartTime == null && scheduleBuilder.TuesdayStartTime == null)
{
startTime = scheduleBuilder.ThursdayStartTime + "-" + scheduleBuilder.ThursdayEndTime; ;
}
if (scheduleBuilder.ThursdayStartTime == null && scheduleBuilder.WednesdayStartTime == null && scheduleBuilder.MondayStartTime == null && scheduleBuilder.TuesdayStartTime == null)
{
startTime = scheduleBuilder.FridayStartTime + "-" + scheduleBuilder.FridayEndTime; ;
}
if (scheduleBuilder.FridayStartTime == null && scheduleBuilder.ThursdayStartTime == null && scheduleBuilder.WednesdayStartTime == null && scheduleBuilder.TuesdayStartTime == null && scheduleBuilder.MondayStartTime == null)
{
startTime = scheduleBuilder.SaturdayStartTime + "-" + scheduleBuilder.SaturdayEndTime; ;
}
if (scheduleBuilder.SaturdayStartTime == null && scheduleBuilder.FridayStartTime == null && scheduleBuilder.ThursdayStartTime == null && scheduleBuilder.WednesdayStartTime == null && scheduleBuilder.TuesdayStartTime == null && scheduleBuilder.MondayStartTime == null)
{
startTime = scheduleBuilder.SundayStartTime + "-" + scheduleBuilder.SundayEndTime; ;
}
System.Diagnostics.Debug.Write("Monday End Time: " + scheduleBuilder.MondayEndTime);
System.Diagnostics.Debug.Write("Sunday End Time: " + scheduleBuilder.SundayEndTime);
if (scheduleBuilder.SundayStartTime != scheduleBuilder.MondayStartTime && scheduleBuilder.MondayStartTime != null && scheduleBuilder.SundayStartTime != null || scheduleBuilder.SundayEndTime != scheduleBuilder.MondayEndTime && scheduleBuilder.MondayEndTime != null && scheduleBuilder.SundayEndTime != null
|| scheduleBuilder.SundayStartTime != scheduleBuilder.TuesdayStartTime && scheduleBuilder.TuesdayStartTime != null && scheduleBuilder.SundayStartTime != null || scheduleBuilder.SundayEndTime != scheduleBuilder.TuesdayEndTime && scheduleBuilder.TuesdayEndTime != null && scheduleBuilder.SundayEndTime != null
|| scheduleBuilder.SundayStartTime != scheduleBuilder.WednesdayStartTime && scheduleBuilder.WednesdayStartTime != null && scheduleBuilder.SundayStartTime != null || scheduleBuilder.SundayEndTime != scheduleBuilder.WednesdayEndTime && scheduleBuilder.WednesdayEndTime != null && scheduleBuilder.SundayEndTime != null
|| scheduleBuilder.SundayStartTime != scheduleBuilder.ThursdayStartTime && scheduleBuilder.ThursdayStartTime != null && scheduleBuilder.SundayStartTime != null || scheduleBuilder.SundayEndTime != scheduleBuilder.ThursdayEndTime && scheduleBuilder.ThursdayEndTime != null && scheduleBuilder.SundayEndTime != null
|| scheduleBuilder.SundayStartTime != scheduleBuilder.FridayStartTime && scheduleBuilder.FridayStartTime != null && scheduleBuilder.SundayStartTime != null || scheduleBuilder.SundayEndTime != scheduleBuilder.FridayEndTime && scheduleBuilder.FridayEndTime != null && scheduleBuilder.SundayEndTime != null
|| scheduleBuilder.SundayStartTime != scheduleBuilder.SaturdayStartTime && scheduleBuilder.SaturdayStartTime != null && scheduleBuilder.SundayStartTime != null || scheduleBuilder.SundayEndTime != scheduleBuilder.SaturdayEndTime && scheduleBuilder.SaturdayEndTime != null && scheduleBuilder.SundayEndTime != null
|| scheduleBuilder.MondayStartTime != scheduleBuilder.TuesdayStartTime && scheduleBuilder.TuesdayStartTime != null && scheduleBuilder.MondayStartTime != null || scheduleBuilder.MondayEndTime != scheduleBuilder.TuesdayEndTime && scheduleBuilder.MondayEndTime != null && scheduleBuilder.TuesdayEndTime != null
|| scheduleBuilder.MondayStartTime != scheduleBuilder.WednesdayStartTime && scheduleBuilder.WednesdayStartTime != null && scheduleBuilder.MondayStartTime != null || scheduleBuilder.MondayEndTime != scheduleBuilder.WednesdayEndTime && scheduleBuilder.MondayEndTime != null && scheduleBuilder.WednesdayEndTime != null
|| scheduleBuilder.MondayStartTime != scheduleBuilder.ThursdayStartTime && scheduleBuilder.ThursdayStartTime != null && scheduleBuilder.MondayStartTime != null || scheduleBuilder.MondayEndTime != scheduleBuilder.ThursdayEndTime && scheduleBuilder.MondayEndTime != null && scheduleBuilder.ThursdayEndTime != null
|| scheduleBuilder.MondayStartTime != scheduleBuilder.FridayStartTime && scheduleBuilder.FridayStartTime != null && scheduleBuilder.MondayStartTime != null || scheduleBuilder.MondayEndTime != scheduleBuilder.FridayEndTime && scheduleBuilder.MondayEndTime != null && scheduleBuilder.FridayEndTime != null
|| scheduleBuilder.MondayStartTime != scheduleBuilder.SaturdayStartTime && scheduleBuilder.SaturdayStartTime != null && scheduleBuilder.MondayStartTime != null || scheduleBuilder.MondayEndTime != scheduleBuilder.SaturdayEndTime && scheduleBuilder.MondayEndTime != null && scheduleBuilder.SaturdayEndTime != null
|| scheduleBuilder.TuesdayStartTime != scheduleBuilder.WednesdayStartTime && scheduleBuilder.WednesdayStartTime != null && scheduleBuilder.TuesdayStartTime != null || scheduleBuilder.TuesdayEndTime != scheduleBuilder.WednesdayEndTime && scheduleBuilder.WednesdayEndTime != null && scheduleBuilder.TuesdayEndTime != null
|| scheduleBuilder.TuesdayStartTime != scheduleBuilder.ThursdayStartTime && scheduleBuilder.ThursdayStartTime != null && scheduleBuilder.TuesdayStartTime != null || scheduleBuilder.TuesdayEndTime != scheduleBuilder.ThursdayEndTime && scheduleBuilder.ThursdayEndTime != null && scheduleBuilder.TuesdayEndTime != null
|| scheduleBuilder.TuesdayStartTime != scheduleBuilder.FridayStartTime && scheduleBuilder.FridayStartTime != null && scheduleBuilder.TuesdayStartTime != null || scheduleBuilder.TuesdayEndTime != scheduleBuilder.FridayEndTime && scheduleBuilder.FridayEndTime != null && scheduleBuilder.TuesdayEndTime != null
|| scheduleBuilder.TuesdayStartTime != scheduleBuilder.SaturdayStartTime && scheduleBuilder.SaturdayStartTime != null && scheduleBuilder.TuesdayStartTime != null || scheduleBuilder.TuesdayEndTime != scheduleBuilder.SaturdayEndTime && scheduleBuilder.SaturdayEndTime != null && scheduleBuilder.TuesdayEndTime != null
|| scheduleBuilder.WednesdayStartTime != scheduleBuilder.ThursdayStartTime && scheduleBuilder.ThursdayStartTime != null && scheduleBuilder.WednesdayStartTime != null || scheduleBuilder.WednesdayEndTime != scheduleBuilder.ThursdayEndTime && scheduleBuilder.ThursdayEndTime != null && scheduleBuilder.WednesdayEndTime != null
|| scheduleBuilder.WednesdayStartTime != scheduleBuilder.FridayStartTime && scheduleBuilder.FridayStartTime != null && scheduleBuilder.WednesdayStartTime != null || scheduleBuilder.WednesdayEndTime != scheduleBuilder.FridayEndTime && scheduleBuilder.FridayEndTime != null && scheduleBuilder.WednesdayEndTime != null
|| scheduleBuilder.WednesdayStartTime != scheduleBuilder.SaturdayStartTime && scheduleBuilder.SaturdayStartTime != null && scheduleBuilder.WednesdayStartTime != null || scheduleBuilder.WednesdayEndTime != scheduleBuilder.SaturdayEndTime && scheduleBuilder.SaturdayEndTime != null && scheduleBuilder.WednesdayEndTime != null
|| scheduleBuilder.ThursdayStartTime != scheduleBuilder.FridayStartTime && scheduleBuilder.ThursdayStartTime != null && scheduleBuilder.FridayStartTime != null || scheduleBuilder.ThursdayEndTime != scheduleBuilder.FridayEndTime && scheduleBuilder.ThursdayEndTime != null && scheduleBuilder.FridayEndTime != null
|| scheduleBuilder.ThursdayStartTime != scheduleBuilder.SaturdayStartTime && scheduleBuilder.ThursdayStartTime != null && scheduleBuilder.SaturdayStartTime != null || scheduleBuilder.ThursdayEndTime != scheduleBuilder.SaturdayEndTime && scheduleBuilder.ThursdayEndTime != null && scheduleBuilder.SaturdayEndTime != null
|| scheduleBuilder.FridayStartTime != scheduleBuilder.SaturdayStartTime && scheduleBuilder.FridayStartTime != null && scheduleBuilder.SaturdayStartTime != null || scheduleBuilder.FridayEndTime != scheduleBuilder.SaturdayEndTime && scheduleBuilder.FridayEndTime != null && scheduleBuilder.SaturdayEndTime != null
)
{
System.Diagnostics.Debug.Write("Tuesday and Sunday Don't Match!");
scheduleBuilder.DaysMatching = "No";
}
scheduleBuilder.ScheduleSummary = scheduleBuilder.Days + " " + startTime + " | Scheduled Days Match: " + scheduleBuilder.DaysMatching;
}
else
{
var scheduleInDb = _context.ScheduleBuilder.Single(a => a.Id == scheduleBuilder.Id);
scheduleInDb.MondayStartTime = scheduleBuilder.MondayStartTime;
scheduleInDb.TuesdayStartTime = scheduleBuilder.TuesdayStartTime;
scheduleInDb.WednesdayStartTime = scheduleBuilder.WednesdayStartTime;
scheduleInDb.ThursdayStartTime = scheduleBuilder.ThursdayStartTime;
scheduleInDb.FridayStartTime = scheduleBuilder.FridayStartTime;
scheduleInDb.SaturdayStartTime = scheduleBuilder.SaturdayStartTime;
scheduleInDb.SundayStartTime = scheduleBuilder.SundayStartTime;
scheduleInDb.MondayEndTime = scheduleBuilder.MondayEndTime;
scheduleInDb.TuesdayEndTime = scheduleBuilder.TuesdayEndTime;
scheduleInDb.WednesdayEndTime = scheduleBuilder.WednesdayEndTime;
scheduleInDb.ThursdayEndTime = scheduleBuilder.ThursdayEndTime;
scheduleInDb.FridayEndTime = scheduleBuilder.FridayEndTime;
scheduleInDb.SaturdayEndTime = scheduleBuilder.SaturdayEndTime;
scheduleInDb.SundayEndTime = scheduleBuilder.SundayEndTime;
scheduleInDb.MondayFirstBreak = scheduleBuilder.MondayFirstBreak;
scheduleInDb.TuesdayFirstBreak = scheduleBuilder.TuesdayFirstBreak;
scheduleInDb.WednesdayFirstBreak = scheduleBuilder.WednesdayFirstBreak;
scheduleInDb.ThursdayFirstBreak = scheduleBuilder.ThursdayFirstBreak;
scheduleInDb.FridayFirstBreak = scheduleBuilder.FridayFirstBreak;
scheduleInDb.SaturdayFirstBreak = scheduleBuilder.SaturdayFirstBreak;
scheduleInDb.SundayFirstBreak = scheduleBuilder.SundayFirstBreak;
scheduleInDb.MondaySecondBreak = scheduleBuilder.MondaySecondBreak;
scheduleInDb.TuesdaySecondBreak = scheduleBuilder.TuesdaySecondBreak;
scheduleInDb.WednesdaySecondBreak = scheduleBuilder.WednesdaySecondBreak;
scheduleInDb.ThursdaySecondBreak = scheduleBuilder.ThursdaySecondBreak;
scheduleInDb.FridaySecondBreak = scheduleBuilder.FridayFirstBreak;
scheduleInDb.SaturdaySecondBreak = scheduleBuilder.SaturdaySecondBreak;
scheduleInDb.SundaySecondBreak = scheduleBuilder.SundaySecondBreak;
scheduleInDb.MondayLunch = scheduleBuilder.MondayLunch;
scheduleInDb.TuesdayLunch = scheduleBuilder.TuesdayLunch;
scheduleInDb.WednesdayLunch = scheduleBuilder.WednesdayLunch;
scheduleInDb.ThursdayLunch = scheduleBuilder.ThursdayLunch;
scheduleInDb.FridayLunch = scheduleBuilder.FridayLunch;
scheduleInDb.SaturdayLunch = scheduleBuilder.SaturdayLunch;
scheduleInDb.SundayLunch = scheduleBuilder.SundayLunch;
}
_context.SaveChanges();
return RedirectToAction("ScheduleBuilder", "Schedule");
}
视图模型
public class TierViewModel
{
public IEnumerable<Tier> TierLevel { get; set; }
public ApplicationUser ApplicationUser { get; set; }
public IEnumerable<ShiftLevel> ShiftLevel { get; set; }
public ScheduleBuilder ScheduleBuilder { get; set; }
public IEnumerable<ScheduleBuilder> ScheduleBuilderList { get; set; }
public ScheduleBuilderTier2 ScheduleBuilderTwo { get; set; }
}