Пример #1
0
        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;
        }
Пример #2
0
        public ActionResult AreaDestroy([DataSourceRequest] DataSourceRequest request, AreaViewModel areaViewModel)
        {
            try
            {
                if (areaViewModel != null)
                {
                    using (var context = new ASJDE())
                    {
                        var videoArea = context.VideoAreas.FirstOrDefault(va => va.ID == areaViewModel.ID);
                        context.VideoAreas.Remove(videoArea);
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("Exception", e);
            }

            return Json(ModelState.ToDataSourceResult());
        }
Пример #3
0
        public ActionResult AreaUpdate([DataSourceRequest] DataSourceRequest dataSourceRequest, AreaViewModel areaViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (var context = new ASJDE())
                    {
                        var videoArea = context.VideoAreas.FirstOrDefault(va => va.ID == areaViewModel.ID);

                        if (videoArea != null)
                        {
                            videoArea.CompanyID = areaViewModel.CompanyID;
                            videoArea.StrategicBusinessUnitID = areaViewModel.StrategicBusinessUnitID;
                            videoArea.OperationalBusinessUnitID = areaViewModel.OperationalBusinessUnitID;
                            videoArea.BusinessUnitID = areaViewModel.BusinessUnitID;
                            videoArea.BranchID = areaViewModel.BranchID;
                            videoArea.DepotID = areaViewModel.DepotID;
                            videoArea.Name = areaViewModel.Name;
                        }

                        context.SaveChanges();
                    }

                }
            }
            catch (Exception e)
            {
                Logger.Error("Exception", e);
            }
            return Json(new[] { areaViewModel }.ToDataSourceResult(dataSourceRequest, ModelState));
        }
Пример #4
0
        public ActionResult AreaCreate([DataSourceRequest] DataSourceRequest request, AreaViewModel areaViewModel)
        {
            try
            {
                if (areaViewModel != null && ModelState.IsValid)
                {
                    using (var context = new ASJDE())
                    {
                        var videoArea = new VideoArea
                            {
                                CompanyID = areaViewModel.CompanyID,
                                StrategicBusinessUnitID = areaViewModel.StrategicBusinessUnitID,
                                OperationalBusinessUnitID = areaViewModel.OperationalBusinessUnitID,
                                BusinessUnitID = areaViewModel.BusinessUnitID,
                                BranchID = areaViewModel.BranchID,
                                DepotID = areaViewModel.DepotID,
                                Name = areaViewModel.Name
                            };

                        context.VideoAreas.Add(videoArea);
                        context.SaveChanges();

                        areaViewModel.ID = videoArea.ID;
                    }
                }

                return Json(new[] { areaViewModel }.ToDataSourceResult(request, ModelState));
            }
            catch (Exception e)
            {
                Logger.Error("Exception", e);
                return null;
            }
        }