public bool StartMonitoring_FeatureIndexViewModel(FeatureIndexViewModel model) { //Add this user as watching features for this project id Groups.Add(Context.ConnectionId, LiveUpdateHelper.GroupName(ViewModelDataType.Feature, ActionType.Index, model.ProjectId)); Task.Factory.StartNew(() => { //Check if the model has changed, call update if it has using (var db = new ApplicationDbContext()) { var project = db.Projects.Find(model.ProjectId); var newModel = new FeatureIndexViewModel(project); //Check features in list foreach (var oldFeature in model.Features) { var newFeature = newModel.Features.Find(feature => feature.Id == oldFeature.Id); if (newFeature == null) { //Data has been removed! LiveUpdateSingleton.Instance.EntityUpdated(new featureList() { new Tuple <EntityState, Feature>(EntityState.Deleted, new Feature() { Id = oldFeature.Id, ProjectId = model.ProjectId }) }); } else if (!oldFeature.PublicInstancePropertiesEqual(newFeature)) { //Data has changed var feature = db.Features.Find(oldFeature.Id); LiveUpdateSingleton.Instance.EntityUpdated(new featureList() { new Tuple <EntityState, Feature>(EntityState.Modified, feature) }); } } foreach (var newFeature in newModel.Features) { var oldFeature = model.Features.Find(feature => feature.Id == newFeature.Id); if (oldFeature == null) { //Data has been added! var feature = db.Features.Find(newFeature.Id); LiveUpdateSingleton.Instance.EntityUpdated(new featureList() { new Tuple <EntityState, Feature>(EntityState.Added, feature) }); } } } }); return(true); }
/// <summary> /// Get list of features /// </summary> /// <returns>Feature index list view</returns> public ActionResult Index() { using (var context = dataContextFactory.CreateByUser()) { //Authorized vendors var vendorGuids = (from v in context.Vendors select v).Select(x => x.ObjectId).ToList(); //Eager loading feature var featureQuery = (from f in context.Features where vendorGuids.Contains(f.VendorId) orderby f.FeatureCode select f) .Include(x => x.Vendor) .OrderBy(x => x.FeatureName); FeatureIndexViewModel viewModel = new FeatureIndexViewModel(featureQuery.ToList()); return(View(viewModel)); } }
// GET: Feature public async Task <ActionResult> Index(int?id) { //Check if valid input if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "No Project Id presented.")); } //Find project from database var project = await _db.Projects.FindAsync(id); if (project == null) { return(HttpNotFound("Project not found.")); } //TODO: Ensure user is allowed access to this project //Assemble view model var model = new FeatureIndexViewModel(project); return(View(model)); }