コード例 #1
0
        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());
        }
コード例 #2
0
ファイル: AppointmentService.cs プロジェクト: Lasanga/JWTDemo
        public async Task Create(CreateAppointmentDto appointmentDto)
        {
            await _demoContext.Appointments.AddAsync(new Appointment
            {
                Name = appointmentDto.Name
            });

            await _demoContext.SaveChangesAsync();
        }
コード例 #3
0
        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)));
        }
コード例 #4
0
        public ActionResult <CreateAppointmentDto> PostAppointment(CreateAppointmentDto appointment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _service.Create(appointment);

            return(appointment);
        }
コード例 #5
0
        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"));
        }
コード例 #6
0
 public async Task Create([FromBody] CreateAppointmentDto createAppointmentDto)
 {
     await _appointmentService.Create(createAppointmentDto);
 }
コード例 #7
0
        public async Task <IActionResult> Create(CreateAppointmentDto createAppointmentDto)
        {
            var appointment = await _appointmentService.CreateAsync(createAppointmentDto);

            return(CreatedAtAction(nameof(GetById), new { id = appointment.Id }, appointment));
        }