예제 #1
0
        public ActionResult Edit(VideoTypesViewModel videoTypesViewModel)
        {
            if (ModelState.IsValid)
            {
                List <VideoTypeRoles> lstVideoTypeRoles = db.VideoTypeRoles.Where(u => u.VideoTypeID == videoTypesViewModel.VideoTypes.VideoTypeID).ToList();
                List <int>            roleIDs           = lstVideoTypeRoles.Select(r => r.RoleID).ToList();

                foreach (Roles role in db.Roles)
                {
                    if (roleIDs.Contains(role.RoleID) && !videoTypesViewModel.SelectedRoles.Contains(role.RoleID))
                    {
                        var videoTypeRoles = db.VideoTypeRoles.Where(r => r.RoleID == role.RoleID && r.VideoTypeID == videoTypesViewModel.VideoTypes.VideoTypeID).FirstOrDefault();
                        db.VideoTypeRoles.Remove(videoTypeRoles);
                    }
                    else if (!roleIDs.Contains(role.RoleID) && videoTypesViewModel.SelectedRoles.Contains(role.RoleID))
                    {
                        db.VideoTypeRoles.Add(new VideoTypeRoles {
                            VideoTypeID = videoTypesViewModel.VideoTypes.VideoTypeID, RoleID = role.RoleID
                        });
                    }
                }
                db.Entry(videoTypesViewModel.VideoTypes).State = EntityState.Modified;
                db.Entry(new VideoTypeRoles()).State           = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(videoTypesViewModel));
        }
예제 #2
0
        // GET: VideoTypes/Edit/5
        public ActionResult Edit(int?id)
        {
            VideoTypesViewModel videoTypesViewModel = new VideoTypesViewModel();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            VideoTypes videoTypes = db.VideoTypes.Find(id);

            if (videoTypes == null)
            {
                return(HttpNotFound());
            }
            else
            {
                videoTypesViewModel            = new VideoTypesViewModel();
                videoTypesViewModel.VideoTypes = videoTypes;
                videoTypesViewModel.AllRoles   = (from r in db.Roles
                                                  join vr in db.VideoTypeRoles on r.RoleID equals vr.RoleID into videoRoles
                                                  from vrs in videoRoles.DefaultIfEmpty()
                                                  orderby r.RoleID
                                                  select new RolesViewModel
                {
                    RoleID = r.RoleID,
                    RoleName = r.RoleName,
                    IsSelected = (bool?)(vrs.RoleID > 0)
                }
                                                  ).Distinct().ToList();
                videoTypesViewModel.SelectedRoles = db.VideoTypeRoles.Where(r => r.VideoTypeID == id).Select(r => r.RoleID).ToList();
            }
            return(View(videoTypesViewModel));
        }
예제 #3
0
        // Controller to display all videos on Create New Project Option
        // Used on NewProjectDisplay.cshtml in Projects View
        public async Task <IActionResult> NewProjectDisplay()
        {
            var user = await GetCurrentUserAsync();

            VideoTypesViewModel model = new VideoTypesViewModel(_context, user);

            return(View(model));
        }
예제 #4
0
        // GET: VideoTypes/Create
        public ActionResult Create()
        {
            VideoTypesViewModel videoTypesViewModel = new VideoTypesViewModel();

            videoTypesViewModel.AllRoles = (from r in db.Roles
                                            select new RolesViewModel
            {
                RoleID = r.RoleID,
                RoleName = r.RoleName,
                IsSelected = false
            }).ToList();
            videoTypesViewModel.SelectedRoles = new List <int>();
            return(View(videoTypesViewModel));
        }
예제 #5
0
        public ActionResult Create(VideoTypesViewModel videoTypesViewModel)
        {
            if (ModelState.IsValid)
            {
                VideoTypeRoles videoTypeRoles = null;
                videoTypesViewModel.VideoTypes.AssignedRoles = new List <VideoTypeRoles>();

                if (videoTypesViewModel.SelectedRoles == null)
                {
                    videoTypesViewModel.SelectedRoles = new List <int>();
                    videoTypesViewModel.SelectedRoles.Add(1);
                }
                else if (!videoTypesViewModel.SelectedRoles.Contains(1))
                {
                    videoTypesViewModel.SelectedRoles.Add(1);
                }

                if (videoTypesViewModel.SelectedRoles != null)
                {
                    foreach (int role in videoTypesViewModel.SelectedRoles)
                    {
                        videoTypeRoles        = new VideoTypeRoles();
                        videoTypeRoles.RoleID = role;
                        videoTypesViewModel.VideoTypes.AssignedRoles.Add(videoTypeRoles);
                    }
                }

                db.VideoTypes.Add(videoTypesViewModel.VideoTypes);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            videoTypesViewModel.AllRoles = (from r in db.Roles
                                            select new RolesViewModel
            {
                RoleID = r.RoleID,
                RoleName = r.RoleName,
                IsSelected = false
            }).ToList();
            videoTypesViewModel.SelectedRoles = new List <int>();
            return(View(videoTypesViewModel));
        }