public async Task <bool> AddBookingv2(ObjectId practiceid, AppointmentDto booking) { try { using (var session = _context.MongoClient.StartSession()) { //AUTOMAPPER REQUIRED AppointmentDao _appointment = new AppointmentDao { BookingId = ObjectId.Parse(booking.BookingId), LineNumber = booking.LineNumber, PatientID = ObjectId.Parse(booking.PatientID), DateAndTimeOfAppointment = booking.DateAndTimeOfAppointment, HasSeenGP = booking.HasSeenGP, IsSerapisBooking = booking.IsSerapisBooking, HasBeenToThisPractice = booking.HasBeenToThisPractice, DoctorsId = ObjectId.Parse(booking.DoctorsId), PracticeID = ObjectId.Parse(booking.PracticeID) }; session.StartTransaction(); //Make First Update var filter = Builders <PracticeInformation> .Filter .Eq(x => x.Id, practiceid); var updatev2 = Builders <PracticeInformation> .Update.Push <AppointmentDao>(e => e.Appointment, _appointment); UpdateResult updateResult = await _context .PracticeCollection .UpdateOneAsync(session, filter : filter, update : updatev2, options : new UpdateOptions { IsUpsert = true }); //Make Second Update var filter2 = Builders <PracticeInformation> .Filter .Eq(x => x.Id, ObjectId.Parse(booking.PatientID)); /*var update2 = Builders<AppointmentDao> * .Update.Push(booking);*/ // This step will be skipped if we throw an exception session.CommitTransaction(); } } catch (Exception ex) { //log or manage the exception Debug.WriteLine(ex); throw ex; } return(false); }
public void GetAppointmentsInCurrentWeekTest() { List <Appointment> appts = AppointmentDao.GetAppointmentsInCurrentWeek(); if (appts.Count > 0) { Assert.IsTrue(appts.Count > 0); } }
public async Task <IActionResult> PutAppointment(int?id, AppointmentDao appointment) { if (id != appointment.Id) { return(BadRequest()); } _service.Update(appointment); return(NoContent()); }
public static AppointmentDto CreateAppointmentDto(AppointmentDao appointment) { AppointmentDto newAppointmentDto = new AppointmentDto() { //AppointmentId=appointment.BookingId, //DateBooked=DateTime.Parse(appointment.DateBooked), //TimeBooked=DateTime.Parse(appointment.TimeBooked) }; return(newAppointmentDto); }
//using (var session = mongoClient.StartSession()) public async Task <bool> AddBooking(ObjectId practiceid, AppointmentDto booking) { try { AppointmentDao _appointment = new AppointmentDao { BookingId = ObjectId.Parse(booking.BookingId), LineNumber = booking.LineNumber, PatientID = ObjectId.Parse(booking.PatientID), DateAndTimeOfAppointment = booking.DateAndTimeOfAppointment, HasSeenGP = booking.HasSeenGP, IsSerapisBooking = booking.IsSerapisBooking, HasBeenToThisPractice = booking.HasBeenToThisPractice, DoctorsId = ObjectId.Parse(booking.DoctorsId), PracticeID = ObjectId.Parse(booking.PracticeID) }; var filter = Builders <PracticeInformation> .Filter .Eq(x => x.Id, practiceid); var updatev2 = Builders <PracticeInformation> .Update.Push <AppointmentDao>(e => e.Appointment, _appointment); UpdateResult updateResult = await _context .PracticeCollection .UpdateOneAsync( filter : filter, update : updatev2, options : new UpdateOptions { IsUpsert = true }); // if modifed document is equal to 1 or more then that means the document was updated if (updateResult.IsAcknowledged && updateResult.ModifiedCount > 0) { Debug.WriteLine("Did DB update? [" + updateResult.IsAcknowledged + "]+ How many Documents updated [" + updateResult.ModifiedCount + "]"); return(true); //This will trigger an success message on the Client device } else { Debug.WriteLine("DB Didn't update updateResult.IsAcknowledged[ " + updateResult.IsAcknowledged + "]+updateResult.ModifiedCount[" + updateResult.ModifiedCount + "]"); return(false); //This will trigger an unsuccesful message on the Client device } } catch (Exception ex) { //log or manage the exception Debug.WriteLine(ex); throw ex; } }
public void GetAppointmentById() { Appointment appt = AppointmentDao.GetAppointmentById(1); if (appt != null) { Assert.IsInstanceOfType(appt, typeof(Appointment)); } else { Assert.IsNull(appt); } }
public void CreateUpdateSaveDeleteAppointmentTest() { int customerId = 1; int userId = 0; string title = "Test Appointment"; string description = "Test Descriptiton"; string location = "Test Location"; string contact = "Test contact"; string type = "Test Type"; string url = "Test.url.com"; DateTime start = DateTime.UtcNow; DateTime end = DateTime.UtcNow; end.AddDays(1); DateTime createdDate = DateTime.Now; string createdBy = "system"; DateTime modifiedDate = DateTime.Now; string modifiedBy = "system"; Appointment appt = AppointmentDao.CreateNewAppointment(customerId, userId, title, description, location, contact, type, url, start, end, createdDate, createdBy, modifiedDate, modifiedBy); Assert.IsInstanceOfType(appt, typeof(Appointment)); Assert.IsTrue(appt.Title == title); Assert.IsTrue(appt.CreateDate == createdDate); bool saved = AppointmentDao.SaveAppointment(appt); Assert.IsTrue(saved == true); appt.Title = "Updated Test Title"; bool update = AppointmentDao.UpdateAppointment(appt); Assert.IsTrue(update == true); bool delete = AppointmentDao.DeleteAppointment(appt); Assert.IsTrue(delete == true); }
private void SetDefaults() { var weekData = AppointmentDao.GetAppointmentsInCurrentWeek() .Select(a => new { a.Title, Start = a.Start.ToLocalTime(), End = a.End.ToLocalTime() }); var week = new BindingSource(); week.DataSource = weekData; var monthData = AppointmentDao.GetAppointmentsInCurrentMonth() .Select(a => new { a.Title, Start = a.Start.ToLocalTime(), End = a.End.ToLocalTime() }); var month = new BindingSource(); month.DataSource = monthData; EditAddressComboBox.DataSource = AddressDao.GetAddresses(); RenameTextBox.Text = ""; ApptInCurrentWeek.DataSource = week; ApptInCurrentMonth.DataSource = month; Dictionary <string, int> cities = AddressDao.GetAllCities(); CitySelectBox.DataSource = new BindingSource(cities, null); CitySelectBox.DisplayMember = "Key"; CitySelectBox.ValueMember = "Value"; Dictionary <string, int> customers = CustomerDao.GetAllCustomers(); EditCustomerComboBox.DataSource = new BindingSource(customers, null); EditCustomerComboBox.DisplayMember = "Key"; EditCustomerComboBox.ValueMember = "Value"; CustomerAptComboBox.DataSource = new BindingSource(customers, null); CustomerAptComboBox.DisplayMember = "Key"; CustomerAptComboBox.ValueMember = "Value"; CustomerUpdateComboBox.DataSource = new BindingSource(customers, null); CustomerUpdateComboBox.DisplayMember = "Key"; CustomerUpdateComboBox.ValueMember = "Value"; Dictionary <string, int> appts = AppointmentDao.GetAllAppointments(); if (appts.Count > 0) { AppointmentsComboBox.DataSource = new BindingSource(appts, null); AppointmentsComboBox.DisplayMember = "Key"; AppointmentsComboBox.ValueMember = "Value"; } }
public AppointmentDao EntityToDao(Appointment entity) { AppointmentDao dao = new AppointmentDao { Id = entity.Id, DateTimeEnd = entity.DateTimeEnd, DateTimeStart = entity.DateTimeStart, Description = entity.Description, Price = entity.Price, Type = entity.Type, RefLabelId = _labelConverter.EntityToDao(entity.RefLabelId), RefLocationId = _locationConverter.EntityToDao(entity.RefLocationId) }; return(dao); }
public Appointment DaoToEntity(AppointmentDao dao) { Appointment entity = new Appointment { Id = dao.Id, DateTimeEnd = dao.DateTimeEnd, DateTimeStart = dao.DateTimeStart, Description = dao.Description, Price = dao.Price, Type = dao.Type, RefLabelId = _labelConverter.DaoToEntity(dao.RefLabelId), RefLocationId = _locationConverter.DaoToEntity(dao.RefLocationId) }; return(entity); }
private void DeleteApptButton_Click(object sender, EventArgs e) { int appointmentId = Convert.ToInt32(AppointmentsComboBox.SelectedValue); var appt = AppointmentDao.GetAppointmentById(appointmentId); bool deleted = AppointmentDao.DeleteAppointment(appt); if (deleted == true) { MessageBox.Show("Deleted appointment successfully."); SetDefaults(); } else { MessageBox.Show("Appointment wasn't able to be deleted."); } }
private void AddApptButton_Click(object sender, EventArgs e) { int customerId = Convert.ToInt32(CustomerAptComboBox.SelectedValue); int userId = UserDao.GetUserIdByName(LoginForm.username); bool saved = false; DateTime start = DateTimeOffset.Parse(StartDateDatePicker.Text).UtcDateTime; DateTime end = DateTimeOffset.Parse(EndDateDatePicker.Text).UtcDateTime;; if (start.Hour >= 9 && start.Hour <= 17 && end.Hour >= 9 && end.Hour <= 17) { var newAppt = AppointmentDao.CreateNewAppointment(customerId, userId, TitleApptTextBox.Text, DescriptionText.Text, LocationText.Text, ContactText.Text, TypeText.Text, UrlText.Text, start, end, DateTime.UtcNow, LoginForm.username, DateTime.UtcNow, LoginForm.username); saved = AppointmentDao.SaveAppointment(newAppt); } else { MessageBox.Show("Please select a time within business hours."); return; } if (saved == true) { MessageBox.Show("Appointment was saved successfully!"); SetDefaults(); } else if (saved == false) { MessageBox.Show("Appointment wasn't able to save."); } }
private void UpdateApptButton_Click(object sender, EventArgs e) { int apptId = Convert.ToInt32(AppointmentsComboBox.SelectedValue); int customerId = Convert.ToInt32(CustomerUpdateComboBox.SelectedValue); int userId = UserDao.GetUserIdByName(LoginForm.username); DateTime start = DateTimeOffset.Parse(StartDateUpdateDatePicker.Text).UtcDateTime; DateTime end = DateTimeOffset.Parse(EndDateUpdateDatePicker.Text).UtcDateTime;; var newAppt = AppointmentDao.CreateNewAppointment(customerId, userId, TitleUpdateText.Text, DescriptionUpdateText.Text, LocationUpdateText.Text, ContactUpdateText.Text, TypeUpdateText.Text, UrlUpdateText.Text, start, end, DateTime.UtcNow, LoginForm.username, DateTime.UtcNow, LoginForm.username); newAppt.AppointmentId = apptId; bool update = AppointmentDao.UpdateAppointment(newAppt); if (update == true) { MessageBox.Show("Appointment was updated successfully!"); SetDefaults(); } else if (update == false) { MessageBox.Show("Appointment wasn't able to update."); } }
public void GetAllAppointmentsTest() { List <Appointment> AllAppointments = AppointmentDao.GetAppointments(); }
public async Task <ActionResult <AppointmentDao> > PostAppointment(AppointmentDao appointment) { _service.Add(appointment); return(CreatedAtAction("GetAppointment", new { id = appointment.Id }, appointment)); }