Пример #1
0
        public async Task <IActionResult> Create([Bind("Id,StartTime,EndTime")] TimeSlot timeSlot)
        {
            if (ModelState.IsValid)
            {
                _context.Add(timeSlot);
                await _context.SaveChangesAsync();

                // Make all companies available at this time by default
                var allCompanies = await _context.Company.ToListAsync();


                allCompanies.ForEach(company =>
                {
                    var newAvailability = new CompanyAvailability()
                    {
                        CompanyId  = company.Id,
                        TimeSlotId = timeSlot.Id
                    };
                    _context.Add(newAvailability);
                });

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(timeSlot));
        }
        public async Task<IActionResult> Create([Bind("Id,Name, requiresBachelorsDegree, isLocal")] Company company)
        {
            if (ModelState.IsValid)
            {
                _context.Add(company);
                await _context.SaveChangesAsync();
                // Make companies available all the time by default
                var allTimeSlots = await _context.TimeSlot.ToListAsync();
               
                
                allTimeSlots.ForEach(time =>
                {
                    var newAvailability = new CompanyAvailability()
                    {
                        CompanyId = company.Id,
                        TimeSlotId = time.Id
                    };
                    _context.Add(newAvailability);
                });

                await _context.SaveChangesAsync();
                return RedirectToAction(nameof(Index));
            }
            return View(company);
        }