Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,LogNumber,LogTime,CurrentTime,PersonId,HospitalId")] SelectedHospitalLog selectedHospitalLog)
        {
            if (id != selectedHospitalLog.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(selectedHospitalLog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SelectedHospitalLogExists(selectedHospitalLog.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HospitalId"] = new SelectList(_context.Hospitals, "Id", "Id", selectedHospitalLog.HospitalId);
            ViewData["PersonId"]   = new SelectList(_context.Persons, "Id", "Id", selectedHospitalLog.PersonId);
            return(View(selectedHospitalLog));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Id,LogNumber,LogTime,CurrentTime,PersonId,HospitalId")] SelectedHospitalLog selectedHospitalLog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(selectedHospitalLog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HospitalId"] = new SelectList(_context.Hospitals, "Id", "Id", selectedHospitalLog.HospitalId);
            ViewData["PersonId"]   = new SelectList(_context.Persons, "Id", "Id", selectedHospitalLog.PersonId);
            return(View(selectedHospitalLog));
        }
Пример #3
0
        public async Task <IActionResult> RunLog()
        {
            var logTime = DateTime.Now.ToUniversalTime() + TimeSpan.Parse("05:30:00");

            var globalSettingsQuery = _context.GlobalSettings as IQueryable <GlobalSettings>;
            var personsQuery        = _context.Persons as IQueryable <Person>;
            var hospitalsQuery      = _context.Hospitals as IQueryable <Hospital>;

            var globalSettings = globalSettingsQuery.FirstOrDefault();
            var persons        = personsQuery.OrderBy(p => p.Rank).Include(p => p.HospitalChoices).ToList();
            var hospitals      = hospitalsQuery.Select(h => new HospitalViewModel
            {
                Id             = h.Id,
                TotalSlots     = h.TotalSlots.Value,
                RemainingSlots = h.TotalSlots.Value
            }).ToList();

            foreach (var person in persons)
            {
                var hospitalChoices = person.HospitalChoices.OrderBy(c => c.PreferenceNumber).Select(c => c.HospitalId).ToList();
                foreach (var hospitalChoiceId in hospitalChoices)
                {
                    var remSlots = hospitals.Where(h => h.Id == hospitalChoiceId).FirstOrDefault().RemainingSlots;
                    if (remSlots > 0)
                    {
                        hospitals.Where(h => h.Id == hospitalChoiceId).FirstOrDefault().RemainingSlots = remSlots - 1;
                        var log = new SelectedHospitalLog
                        {
                            CurrentTime = DateTime.Now.ToUniversalTime() + TimeSpan.Parse("05:30:00"),
                            LogNumber   = globalSettings.LogIndex + 1,
                            LogTime     = logTime,
                            PersonId    = person.Id,
                            HospitalId  = hospitalChoiceId
                        };
                        _context.Add(log);
                    }
                    break;
                }
                globalSettings.LogIndex = globalSettings.LogIndex + 1;
                globalSettings.LogTime  = logTime;
                _context.Update(globalSettings);
                _context.SaveChanges();
            }
            return(RedirectToAction(nameof(Index)));
        }