Beispiel #1
0
        public async Task <IActionResult> Create()
        {
            var currentUser = await GetCurrentUserAsync();

            AppointmentClientViewModel vm = new AppointmentClientViewModel();
            SelectList clients            = new SelectList(_context.Clients.Where(c => c.ApplicationUserId == currentUser.Id && c.isActive == true || c.ApplicationUserId == null && c.isActive == true), "Id", "FullName");
            // Add a 0 option to the select list
            SelectList clients0 = ClientDropdown(clients);

            vm.Clients = clients0;
            return(View(vm));
        }
Beispiel #2
0
        public async Task <IActionResult> Create(AppointmentClientViewModel vm)
        {
            var currentUser = await GetCurrentUserAsync();

            SelectList clients = new SelectList(_context.Clients.Where(c => c.ApplicationUserId == currentUser.Id && c.isActive == true || c.ApplicationUserId == null && c.isActive == true), "Id", "FullName");
            // Add a '0' option to the select list
            SelectList clients0 = ClientDropdown(clients);

            ModelState.Remove("appointment.ApplicatationUser");
            ModelState.Remove("appointment.ApplicationUserId");

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

                return(RedirectToAction("Index"));
            }
            vm.Clients = clients0;
            return(View(vm));
        }