public async Task <Appointment> CreateAsync(CreateAppointmentDto createAppointmentDto) { var(start, end, timezone, purpose, location, organizationId) = createAppointmentDto; var appointment = new Appointment { Start = start, End = end, Timezone = timezone, Purpose = purpose, Location = location, Status = "PENDING", CreatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow, }; var organization = await _context.Organizations .Include(o => o.Appointments) .FirstOrDefaultAsync(o => o.Id == organizationId); if (organization == null) { throw new NullReferenceException(); } organization.Appointments.Add(appointment); await _context.SaveChangesAsync(); return(organization.Appointments .LastOrDefault()); }
public async Task Create(CreateAppointmentDto appointmentDto) { await _demoContext.Appointments.AddAsync(new Appointment { Name = appointmentDto.Name }); await _demoContext.SaveChangesAsync(); }
public async Task <IActionResult> PostAsync([FromBody] CreateAppointmentDto createAppointmentDto) { var appointment = _mapper.Map <Appointment>(createAppointmentDto); var createdAppointment = await _appointmentService.CreateAppointmentAsync(appointment); var appointmentDto = _mapper.Map <AppointmentDto>(createdAppointment); return(CreatedAtRoute(nameof(GetAsync), new { appointmentDto.Id }, new Response <AppointmentDto>(appointmentDto))); }
public ActionResult <CreateAppointmentDto> PostAppointment(CreateAppointmentDto appointment) { if (!ModelState.IsValid) { return(BadRequest()); } _service.Create(appointment); return(appointment); }
public async Task <ActionResult <AppointmentDto> > CreateAppointment(int userId, CreateAppointmentDto createAppointmentDto) { var appointment = new Appointment { AppointmentTime = createAppointmentDto.AppointmentTime, Date = createAppointmentDto.Date, Location = createAppointmentDto.Location, Notes = createAppointmentDto.Notes, Type = (Appointment.AppointmentType)createAppointmentDto.Type, WithWhom = createAppointmentDto.WithWhom, User = await _unitOfWork.UserRepository.GetUserByIdAsync(userId) }; _unitOfWork.AppointmentsRepository.AddItem(appointment); if (await _unitOfWork.Complete()) { return(Ok(_mapper.Map <AppointmentDto>(appointment))); } return(BadRequest("Unable to create Appointment")); }
public async Task Create([FromBody] CreateAppointmentDto createAppointmentDto) { await _appointmentService.Create(createAppointmentDto); }
public async Task <IActionResult> Create(CreateAppointmentDto createAppointmentDto) { var appointment = await _appointmentService.CreateAsync(createAppointmentDto); return(CreatedAtAction(nameof(GetById), new { id = appointment.Id }, appointment)); }