public async Task <IActionResult> GetAppointment([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var appointment = await _context.Appointments.SingleOrDefaultAsync(m => m.Id == id);

            if (appointment == null)
            {
                return(NotFound());
            }

            ClientUser              client       = _userContext.Client.Find(appointment.ClientId);
            HealthWorkerUser        healthworker = _userContext.HealthWorker.Find(appointment.HealthworkerId);
            AppointmentGetViewModel viewModel    = new AppointmentGetViewModel
            {
                Id     = appointment.Id,
                Time   = appointment.Time,
                Status = _context.AppointmentStatuses.Find(appointment.StatusId),
                Bench  = _context.Benches.Find(appointment.BenchId),
                Client = new ClientViewModel {
                    id = client.Id, Email = client.Email, FirstName = client.FirstName, LastName = client.LastName, BirthDay = client.BirthDay, District = client.District, Gender = client.Gender, HouseNumber = client.HouseNumber, Province = client.Province, StreetName = client.StreetName
                },
                Healthworker = new HealthWorkerViewModel {
                    Id = healthworker.Id, Firstname = healthworker.FirstName, Lastname = healthworker.LastName, Birthday = healthworker.BirthDay, Gender = healthworker.Gender, Email = healthworker.Email
                }
            };

            return(Ok(viewModel));
        }
        public IEnumerable <AppointmentGetViewModel> GetAppointments()
        {
            List <AppointmentGetViewModel> appointments = new List <AppointmentGetViewModel>();

            foreach (Appointment appointment in _context.Appointments)
            {
                ClientUser       client       = _userContext.Client.Find(appointment.ClientId);
                HealthWorkerUser healthworker = _userContext.HealthWorker.Find(appointment.HealthworkerId);

                if (healthworker != null && client != null)
                {
                    appointments.Add(new AppointmentGetViewModel
                    {
                        Id     = appointment.Id,
                        Time   = appointment.Time,
                        Status = _context.AppointmentStatuses.Find(appointment.StatusId),
                        Bench  = _context.Benches.Find(appointment.BenchId),
                        Client = new ClientViewModel {
                            id = client.Id, Email = client.Email, FirstName = client.FirstName, LastName = client.LastName, BirthDay = client.BirthDay, District = client.District, Gender = client.Gender, HouseNumber = client.HouseNumber, Province = client.Province, StreetName = client.StreetName
                        },
                        Healthworker = new HealthWorkerViewModel {
                            Id = healthworker.Id, Firstname = healthworker.FirstName, Lastname = healthworker.LastName, Birthday = healthworker.BirthDay, Gender = healthworker.Gender, Email = healthworker.Email, PhoneNumber = healthworker.PhoneNumber
                        }
                    });
                }
                else
                {
                    return(null);
                }
            }

            return(appointments);
        }
Beispiel #3
0
        public async Task <IActionResult> RegisterHealthWorker([FromBody] RegisterHealthWorkerViewModel Credentials)
        {
            if (ModelState.IsValid)
            {
                var healthWorker = new HealthWorkerUser
                {
                    UserName    = Credentials.Email,
                    Email       = Credentials.Email,
                    FirstName   = Credentials.FirstName,
                    LastName    = Credentials.LastName,
                    Gender      = Credentials.Gender,
                    BirthDay    = Credentials.BirthDay,
                    PhoneNumber = Credentials.PhoneNumber,
                };
                var result = await _userManager.CreateAsync(healthWorker, Credentials.Password);

                if (result.Succeeded)
                {
                    await _userManager.AddToRoleAsync(healthWorker, "healthworker");

                    await _signInManager.SignInAsync(healthWorker, isPersistent : false);

                    return(Ok("User successfully registered"));
                }
                return(Errors(result));
            }
            return(Error("Unexpected error"));
        }
Beispiel #4
0
        public async Task <IActionResult> PutClientUserByEmail([FromRoute] string id, [FromBody] EditHealthWorkerViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var dbUser = _context.HealthWorker.AsNoTracking().SingleOrDefault(x => x.Id == id);

            HealthWorkerUser user = new HealthWorkerUser
            {
                Email             = dbUser.Email,
                PasswordHash      = dbUser.PasswordHash,
                AccessFailedCount = dbUser.AccessFailedCount,
                BirthDay          = vm.BirthDay,
                ConcurrencyStamp  = dbUser.ConcurrencyStamp,
                EmailConfirmed    = dbUser.EmailConfirmed,
                FirstName         = vm.FirstName,
                Gender            = vm.Gender,
                Id                   = dbUser.Id,
                LastName             = vm.LastName,
                LockoutEnabled       = dbUser.LockoutEnabled,
                LockoutEnd           = dbUser.LockoutEnd,
                NormalizedEmail      = dbUser.NormalizedEmail,
                NormalizedUserName   = dbUser.NormalizedUserName,
                PhoneNumber          = vm.PhoneNumber,
                PhoneNumberConfirmed = dbUser.PhoneNumberConfirmed,
                SecurityStamp        = dbUser.SecurityStamp,
                TwoFactorEnabled     = dbUser.TwoFactorEnabled,
                UserName             = dbUser.UserName,
            };

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HealthWorkerUserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }