У меня есть класс, в котором есть набор строк активности хедера, который связан со многими линиями активности id.
public class ActivityHeader
{
public int ActivityHeaderId { get; set; } //(int, null)
public DateTime? ActivityDate { get; set; } //(date, null)
public string Name { get; set; } //(nvarchar(350), null)
public DateTime? ActivityEndDate { get; set; } //(datetime, null)
public string ProblemDescription { get; set; }
public string Description { get; set; } //(nvarchar(max), null)
public int? ActivityLinesId { get; set; } //(int, null)
public int? HoursLeftOnProject { get; set; } //(time(7), null)
public int? Status { get; set; } //(nchar(10), null)
public DateTime? CreatedDate { get; set; } //(date, null)
public string CreatedBy { get; set; } //(nvarchar(50), null)
public bool? isActive { get; set; } //(bit, null)
public bool? isDeleted { get; set; } //(bit, null)
public bool? isArchived { get; set; } //(bit, null)
public int? SOP { get; set; } //(nvarchar(50), null)
public int? OnSite { get; set; }
public int? Remote { get; set; }
public int? DepartmentId { get; set; } //(int, null)
public string EmployeeName { get; set; } //(nvarchar(301), null)
[ForeignKey("StaffId")]
public int? StaffId { get; set; }
public virtual StaffMembers StaffMembers { get; set; }
public ICollection<ActivityLines> ActivityLines { get; set; }
}
Activity Lines classs
public class ActivityLines
{
[Key]
public int ActivityLineId { get; set; } //(int, not null)
public int ActivitiyHeadId { get; set; } //(int, null)
public string Description { get; set; } //(nvarchar(max), null)
public string Notes { get; set; } //(nvarchar(max), null)
public DateTime StartTime { get; set; } //(time(7), null)
public DateTime EndTime { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; } //(time(7), null)
public int? StaffMemeber { get; set; } //(int, null)
public bool? isActive { get; set; } //(bit, null)
public bool? isDeleted { get; set; } //(bit, null)
public string CreatedBy { get; set; } //(nvarchar(50), null)
public DateTime? CreatedDate { get; set; } //(date, null)
public int? Status { get; set; } //(int, null)
}
Однако, как вы видите, это не позволяет мне ссылаться без перехода к первой записи с использованием linq, что является наилучшей практикой для возможности ссылки на строки correclty.
@model ActivityTrackerDal.ViewModels.ActivityEditViewModal
<div class="container py-5">
<div class="row">
<div class="col-md-10 mx-auto">
<form>
<div class="form-group row">
<div class="col-sm-9">
<label for="inputFirstname">Activty Name</label>
<input type="text" class="form-control" id="inputFirstname" placeholder="Activity name">
</div>
</div>
<div class="form-group row">
<div class="col-sm-3">
<label for="inputLastname" class="form-control">Activity Start Date</label>
@Html.Kendo().DateTimePickerFor(model => model.ActivityDate)
</div>
<div class="col-sm-3">
<label for="inputLastname" class="form-control">Activity End Date</label>
@Html.Kendo().DateTimePickerFor(model => model.ActivityEndDate)
</div>
</div>
<div class="form-group row">
<div class="col-sm-3">
<label for="inputLastname" class="form-control">Location</label>
@foreach (var item in (SelectList)ViewBag.Location)
{
@Html.RadioButtonFor(model => model.OnSite, item.Value, false)
<label class="control-label">@item.Text</label>
}
</div>
</div>
<div class="form-group row">
<div class="col-md-10">
<label for="inputLastname" class="form-control">Description</label>
@Html.TextAreaFor(model => model.Description, new { @class = "whatever-class", @cols = 115, @rows = 10 })
</div>
</div>
<div class="form-group row">
<div class="col-sm-6">
<label for="inputCity">Status </label>
<select asp-for="Status"
class="form-control"
asp-items="@(new SelectList(@ViewBag.ProjectStatusTypes,"LookupCode", "LookupDescription"))"></select>
</div>
<div class="col-sm-3">
<label for="inputState">ActivityType </label>
<select asp-for="ActivityType"
class="form-control"
asp-items="@(new SelectList(@ViewBag.ProjectTypes,"LookupCode", "LookupDescription"))"></select>
</div>
</div>
<div class="form-group row">
<div class="col-sm-6">
<label for="inputCity">Staff </label>
<select asp-for="StaffID"
class="form-control"
asp-items="@(new SelectList(@ViewBag.ListOfStaff,"StaffID", "FirstName"))"></select>
</div>
<div class="col-sm-3">
<label for="inputState">Hours Left On Project </label>
<label for="inputState"><div class="badge" style="font-size:18px;">26</div> </label>
<label for="projecthours">If Porject hours fall below ten Contact Charlie.</label>
</div>
</div>
<div class="form-group row">
<div class="col-sm-12">
@(Html.Kendo().Grid<FuelActivityTrackerDal.Models.ActivityLines>().Name("activityLines")
.Columns(columns =>
{
columns.Bound(p => p.Description).Filterable(false);
columns.Bound(p => p.StartTime).Filterable(false);
columns.Bound(p => p.EndTime).Filterable(false);
columns.Bound(p => p.Status);
columns.Command(command => command.Custom("ViewDetails").Click("showDetails"));
})
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.ActivityLineId))
.Read(read => read.Action("ActivityLines_Read", "Activity"))))
</div>
</div>
<div class="form-group row">
<div class="col-sm-6">
</div>
</div>
<button type="button" class="btn btn-primary px-4 float-right">Add Work Item</button>
<button type="button" class="btn btn-primary px-4 float-right">Put Case & Client On Hold</button>
<button type="button" class="btn btn-primary px-4">Cancel</button>
</form>
</div>
</div>
@(Html.Kendo().Window().Name("Details")
.Title("Activity Details")
.Visible(false)
.Modal(true)
.Draggable(true)
.Width(400)
)
<script type="text/x-kendo-template" id="template">
<form method="post" action="@Url.Action("SaveWorkItem", "Activity")">
<div id="details-container">
ActivitiyHeadId
<div class="form-group row">
<div class="col-sm-9">
<label for="inputFirstname">Activty Name</label>
<input type="text" class="form-control" id="inputFirstname" placeholder="Activity name">
</div>
</div>
<div class="form-group row">
<div class="col-md-10">
<label for="inputLastname" class="form-control">Description</label>
@Html.Kendo().TimePickerFor(model => model.ActivityLines.First(), new { @class = "whatever-class", @cols = 115, @rows = 10 })
</div>
</div>
<div class="form-group row">
<div class="col-md-6">
<label for="inputLastname" class="form-control">Start Time</label>
</div>
<div class="col-md-6">
<label for="inputLastname" class="form-control">End Time </label>
</div>
</div>
</div>
<input type="submit" class="btn btn-file px-4" value="Save Work Item" />
<button type="button" class="btn btn-primary px-4">Cancel</button>
</form>
</script>
<script type="text/javascript">
var detailsTemplate = kendo.template($("#template").html());
function showDetails(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var wnd = $("#Details").data("kendoWindow");
wnd.content(detailsTemplate(dataItem));
wnd.center().open();
}
</script>
</div>
Это это всплывающее окно внутри.с возможностью ссылаться на строки деятельности
<script type="text/x-kendo-template" id="template">
<form method="post" action="@Url.Action("SaveWorkItem", "Activity")">
<div id="details-container">
ActivitiyHeadId
<div class="form-group row">
<div class="col-sm-9">
<label for="inputFirstname">Activty Name</label>
<input type="text" class="form-control" id="inputFirstname" placeholder="Activity name">
</div>
</div>
<div class="form-group row">
<div class="col-md-10">
<label for="inputLastname" class="form-control">Description</label>
@Html.Kendo().TimePickerFor(model => model.ActivityLines.First(), new { @class = "whatever-class", @cols = 115, @rows = 10 })
</div>
</div>
<div class="form-group row">
<div class="col-md-6">
<label for="inputLastname" class="form-control">Start Time</label>
</div>
<div class="col-md-6">
<label for="inputLastname" class="form-control">End Time </label>
</div>
</div>
</div>
<input type="submit" class="btn btn-file px-4" value="Save Work Item" />
<button type="button" class="btn btn-primary px-4">Cancel</button>
</form>
</script>
Это основной блок сверху, с которым у меня возникла проблема.
<div class="form-group row">
<div class="col-md-10">
<label for="inputLastname" class="form-control">Description</label>
@Html.Kendo().TimePickerFor(model => model.ActivityLines.First(), new { @class = "whatever-class", @cols = 115, @rows = 10 })
</div>
</div>
Нужно ли использовать здесь наActivityHeader получить заявление, как я сделал для персонала?.
public List<ActivityEditViewModal> GetAllActivites()
{
var staffRepo = new StaffRepositry(_db);
List<ActivityHeader> activity = new List<ActivityHeader>();
activity = _db.ActivityHeader.AsNoTracking()
.Include(x => x.StaffMembers)
.ToList();
if (activity != null)
{
List<ActivityEditViewModal> activityDisplay = new List<ActivityEditViewModal>();
foreach (var x in activity)
{
var customerDisplay = new ActivityEditViewModal()
{
ActivityHeaderId = x.ActivityHeaderId,
ActivityDate = x.ActivityDate,
Name = x.Name,
ActivityEndDate = x.ActivityEndDate,
Description = x.Description
};
activityDisplay.Add(customerDisplay);
}
return activityDisplay;
}
return null;
}