public ActionResult GroupUpdate([DataSourceRequest] DataSourceRequest dataSourceRequest, GroupViewModel groupViewModel) { try { if (ModelState.IsValid) { using (var context = new ASJDE()) { var videoGroup = context.VideoGroups.FirstOrDefault(vg => vg.ID == groupViewModel.ID); if (videoGroup != null) { videoGroup.Name = groupViewModel.Name; videoGroup.VideoAreaID = groupViewModel.AreaID; } context.SaveChanges(); } } } catch (Exception e) { Logger.Error("Exception", e); } return Json(new[] { groupViewModel }.ToDataSourceResult(dataSourceRequest, ModelState)); }
public ActionResult GroupCreate([DataSourceRequest] DataSourceRequest request, GroupViewModel groupViewModel) { try { if (groupViewModel != null && ModelState.IsValid) { using (var context = new ASJDE()) { var videoGroup = new VideoGroup { VideoAreaID = groupViewModel.AreaID, Name = groupViewModel.Name, }; context.VideoGroups.Add(videoGroup); context.SaveChanges(); groupViewModel.ID = videoGroup.ID; } } return Json(new[] { groupViewModel }.ToDataSourceResult(request, ModelState)); } catch (Exception e) { Logger.Error("Exception", e); return null; } }
public ActionResult GroupDestroy([DataSourceRequest] DataSourceRequest request, GroupViewModel groupViewModel) { try { if (groupViewModel != null) { using (var context = new ASJDE()) { var videoGroup = context.VideoGroups.FirstOrDefault(vg => vg.ID == groupViewModel.ID); context.VideoGroups.Remove(videoGroup); context.SaveChanges(); } } } catch (Exception e) { Logger.Error("Exception", e); } return Json(ModelState.ToDataSourceResult()); }
public List<AreaViewModel> GetAreaViewModelsByVideoAreas(ASJDE context, IQueryable<VideoArea> videoAreas) { var areaViewModels = new List<AreaViewModel>(); foreach (var videoArea in videoAreas) { var areaViewModel = new AreaViewModel { ID = videoArea.ID, Name = videoArea.Name, GroupViewModels = new List<GroupViewModel>() }; var area = videoArea; var groups = context.VideoGroups.Where(g => g.VideoAreaID == area.ID); foreach (var videoGroup in groups) { var groupViewModel = new GroupViewModel { ID = videoGroup.ID, Name = videoGroup.Name, VideoViewModels = new List<VideoViewModel>() }; var vGroup = videoGroup; var videos = context.Videos.Where(v => v.VideoGroupID == vGroup.ID); foreach (var videoViewModel in videos.Select(video => new VideoViewModel { ID = video.ID, Name = video.Name, ReferenceID = video.ReferenceID, Type = "video", })) { groupViewModel.VideoViewModels.Add(videoViewModel); } areaViewModel.GroupViewModels.Add(groupViewModel); } areaViewModels.Add(areaViewModel); } return areaViewModels; }