public ActionResult AppointmentUpdate(Guid appointmentGuid, [FromForm] AppointmentCO request) { var sonuc = new ResultDTO(); if (request == null) { throw new PetClinicAppointmentBadRequestException("You have not sent any data!"); } if (appointmentGuid == null && appointmentGuid == default(Guid)) { throw new PetClinicAppointmentBadRequestException("Appointment guid cannot be empty!"); } var appointment = _appointmentService.GetByGuid(appointmentGuid); if (appointment == null) { throw new PetClinicAppointmentBadRequestException("Appointment guid cannot be empty!"); } if (request.PetGuid == null && request.PetGuid == default(Guid)) { throw new PetClinicAppointmentBadRequestException("Pet guid cannot be empty!"); } if (request.AvailableAppointmentTimeGuid == null && request.AvailableAppointmentTimeGuid == default(Guid)) { throw new PetClinicAppointmentBadRequestException("Available appointment time guid cannot be empty!"); } var pet = _petService.GetByGuid(request.PetGuid); if (pet == null) { throw new PetClinicAppointmentNotFoundException("Pet not found!"); } var availableAppointment = _availableAppointmentService.GetByGuid(request.AvailableAppointmentTimeGuid); if (availableAppointment == null) { throw new PetClinicAppointmentNotFoundException("Admin has not created such an appointment time. Please send another appointment time!"); } var appointmentVarMi = _appointmentService.GetByAppointment(request.PetGuid, request.AvailableAppointmentTimeGuid); if (appointmentVarMi.Count > 0) { throw new PetClinicAppointmentBadRequestException("Such an appointment already exists!"); } appointment.AppointmentTime = availableAppointment.AppointmentTime; appointment.PetId = pet.Id; appointment.UserId = pet.UserId; appointment.Pet = null; var durum = _appointmentService.Update(appointment); if (durum > 0) { sonuc.Status = EDurum.SUCCESS; sonuc.Message.Add(new MessageDTO() { Code = HttpStatusCode.OK, Status = EDurum.SUCCESS, Description = "The appointment has been successfully updated." }); sonuc.Data = new { appointment = new { appointment.Guid } }; } else { throw new PetClinicAppointmentBadRequestException("The appointment could not be updated!"); } return(Ok(sonuc)); }
public ActionResult AppointmentCreate([FromForm] AppointmentCO request) { var sonuc = new ResultDTO(); if (request.PetGuid == null && request.PetGuid == default(Guid)) { throw new PetClinicAppointmentBadRequestException("Pet guid cannot be empty!"); } if (request.AvailableAppointmentTimeGuid == null && request.AvailableAppointmentTimeGuid == default(Guid)) { throw new PetClinicAppointmentBadRequestException("Available appointment time guid cannot be empty!"); } var pet = _petService.GetByGuid(request.PetGuid); if (pet == null) { throw new PetClinicAppointmentNotFoundException("Pet not found!"); } var availableAppointment = _availableAppointmentService.GetByGuid(request.AvailableAppointmentTimeGuid); if (availableAppointment == null) { throw new PetClinicAppointmentNotFoundException("Admin has not created such an appointment time. Please send another appointment time!"); } var appointmentVarMi = _appointmentService.GetByAppointment(request.PetGuid, request.AvailableAppointmentTimeGuid); if (appointmentVarMi.Count > 0) { throw new PetClinicAppointmentBadRequestException("Such an appointment already exists!"); } var dto = new AppointmentDTO() { Guid = Guid.NewGuid(), Deleted = false, Actived = true, CreatedDate = DateTime.Now, AppointmentTime = availableAppointment.AppointmentTime, UserId = pet.UserId, PetId = pet.Id, Pet = null, User = null }; var durum = _appointmentService.Create(dto); if (durum > 0) { var appo = _appointmentService.GetById(durum); sonuc.Status = EDurum.SUCCESS; sonuc.Message.Add(new MessageDTO() { Code = HttpStatusCode.OK, Status = EDurum.SUCCESS, Description = "Appointment was created successfully." }); sonuc.Data = new { appointment = new { appo.Guid, appo.AppointmentTime, pet = new { appo.Pet.Guid, appo.Pet.Name, appo.Pet.DogumTarihi, appo.Pet.DogumYeri, owner = new { appo.User.Guid, appo.User.Name, appo.User.Surname, appo.User.Email } } } }; } else { throw new PetClinicAppointmentBadRequestException("Couldn't create an appointment!"); } return(Ok(sonuc)); }