Exemple #1
0
        public async Task <IActionResult> Book(string partitionKey, string rowKey)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("Identity/Account/Login"));
            }
            try
            {
                var tbl = slots.CloudeTableStorage;

                var slot = tbl.Retrieve <Slot>(partitionKey, rowKey);
                slot.Id = 0;
                if (slot.IsBooked)
                {
                    return(RedirectToAction("Index"));
                }
                slot.IsBooked = true;

                _context.Add(GetAppointment(slot));
                Task <int> saving = _context.SaveChangesAsync();
                slots.Update(slot);

                await saving;
                sb.Send($"User: {User.Identity.Name} booked the slot: p[{slot.PartitionKey}] r[{slot.RowKey}] v[{slot.TimeStart}]");
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                return(RedirectToAction("Error", "Home"));
            }
        }
        private void setFirstPatientAsDoctor()
        {
            Patient p = _context.Patient.FirstOrDefault();

            if (p == null)
            {
                return;
            }

            if (_context.Staff.FirstOrDefault() != null)
            {
                return;
            }

            var staff = new Doctor()
            {
                AspNetUsersId = p.AspNetUsersId,
                Name          = p.Name,
                Title         = JobTitle.Doctor,
            };

            _context.Add(staff);
            _context.SaveChanges();
        }