Пример #1
0
        public async Task <IActionResult> Create(CreateFUnActivityViewModel vm)
        {
            ApplicationUser user = await GetCurrentUserAsync();

            if (ModelState.IsValid)
            {
                vm.FUnActivity.ApplicationUserId = user.Id;
                _context.Add(vm.FUnActivity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            List <ActivityType> activityTypes = await _context.ActivityTypes.ToListAsync();

            vm.ActivityTypeOptions = activityTypes.Select(a => new SelectListItem
            {
                Value = a.Id.ToString(),
                Text  = a.Type
            }).ToList();

            List <UserGroup> userGroups = await _context.UserGroups.ToListAsync();

            vm.UserGroupOptions = userGroups.Select(u => new SelectListItem
            {
                Value = u.Id.ToString(),
                Text  = u.Name
            }).ToList();

            return(View(vm.FUnActivity));
        }
Пример #2
0
        // GET: FUnActivities/Create
        public async Task <IActionResult> Create()
        {
            List <ActivityType> ActivityTypes = await _context.ActivityTypes.ToListAsync();

            List <UserGroup> UserGroups = await _context.UserGroups.ToListAsync();

            var viewModel = new CreateFUnActivityViewModel()
            {
                ActivityTypeOptions = ActivityTypes.Select(a => new SelectListItem
                {
                    Value = a.Id.ToString(),
                    Text  = a.Type
                }).ToList(),

                UserGroupOptions = UserGroups.Select(u => new SelectListItem
                {
                    Value = u.Id.ToString(),
                    Text  = u.Name
                }).ToList()
            };


            return(View(viewModel));
        }