public async Task <IActionResult> PutBookingRecord([FromRoute] int id, [FromBody] BookingRecord bookingRecord) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != bookingRecord.BookingId) { return(BadRequest()); } _context.Entry(bookingRecord).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookingRecordExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task BookAppointment_ShouldBeSuccessful_ForNewContact() { var dummyContact = new Contact { ID = 0 }; var dummyAddedContactID = 10; var dummyBookingRecord = new BookingRecord { contact = dummyContact }; _appointmentRepoMock.Setup(x => x.VerifyTimeSlotAvailable(dummyBookingRecord)).ReturnsAsync(true); _contactRepoMock.Setup(x => x.CheckDuplicate(dummyBookingRecord.contact)) .ReturnsAsync(dummyContact); _contactRepoMock.Setup(x => x.AddContact(dummyContact)).ReturnsAsync(dummyAddedContactID); _appointmentRepoMock.Setup(x => x.AddAppointment(dummyBookingRecord, dummyAddedContactID)) .ReturnsAsync(true); var response = await _appointmentService.BookAppointment(dummyBookingRecord); Assert.True(response); }
public IHttpActionResult PutBookingRecord(int id, BookingRecord bookingRecord) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != bookingRecord.BookingRecord_ID) { return(BadRequest()); } db.Entry(bookingRecord).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookingRecordExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public int Insert(BookingRecord saveThis) { _dataEngine.InitialiseParameterList(); _dataEngine.AddParameter("@TimeArrived", saveThis.TimeArrived.ToString()); _dataEngine.AddParameter("@ArrivalRegistrationMethod", ((int)saveThis.ArrivalRegistrationMethod).ToString()); _dataEngine.AddParameter("@BookingStatus", ((int)saveThis.BookingStatus).ToString()); _dataEngine.AddParameter("@BookingRecordUniqueId", saveThis.BookingRecordUniqueId.ToString()); _dataEngine.AddParameter("@BookingRecordPin", saveThis.BookingRecordPin.ToString()); _sqlToExecute = "INSERT INTO [dbo].[BookingRecord] "; _sqlToExecute += "([TimeArrived]"; _sqlToExecute += ",[ArrivalRegistrationMethod]"; _sqlToExecute += ",[BookingStatus]"; _sqlToExecute += ",[BookingRecordUniqueId]"; _sqlToExecute += ",[BookingRecordPin]) "; _sqlToExecute += "OUTPUT INSERTED.Id "; _sqlToExecute += "VALUES "; _sqlToExecute += "("; _sqlToExecute += _dataEngine.GetParametersForQuery(); _sqlToExecute += ")"; int insertedRowId = 0; if (!_dataEngine.ExecuteSql(_sqlToExecute, out insertedRowId)) { throw new Exception("BookingRecord - Save failed"); } return(insertedRowId); }
public async Task <bool> BookAppointment(BookingRecord bookingRecord) { var removeTimePortion = new TimeSpan(0, 0, 0); bookingRecord.Date = bookingRecord.Date.Date + removeTimePortion; var timeSlotavailability = await _appointmentRepository.VerifyTimeSlotAvailable(bookingRecord); if (!timeSlotavailability) { // TODO: log time slot unavailable return(false); } var existingContact = await _contactRepository.CheckDuplicate(bookingRecord.contact); var contactID = existingContact.ID != 0 ? existingContact.ID : await _contactRepository.AddContact(bookingRecord.contact); var added = await _appointmentRepository.AddAppointment(bookingRecord, contactID); // TODO: log added successful return(added); }
public IHttpActionResult PostBookingRecord(BookingRecord bookingRecord) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.BookingRecords.Add(bookingRecord); try { db.SaveChanges(); } catch (DbUpdateException) { if (BookingRecordExists(bookingRecord.BookingRecord_ID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = bookingRecord.BookingRecord_ID }, bookingRecord)); }
public void GivenIEnterDataForTheFollowingFields(string firstName, string lastname, string price, string deposit, string startDate, string endDate) { //retrieving number of rows on the page so that we can compare that later on to find // whether a row has been added or not int CurrentRowCount = _bookingPage.GetCurrentRowsOnPage(); //Generating a random number to create a unique record Random random = new Random(); var NewBooking = new BookingRecord { FirstName = firstName, Surname = "surname" + random.Next(10, 1000), Price = price, Deposit = deposit, CheckIn = startDate, CheckOut = endDate, }; _bookingPage.CreateBooking(NewBooking); _bookingPage.WaitUntilRowHasBeenAdded(CurrentRowCount); FeatureContext.Current[NewlyCreatedBookingRecord] = NewBooking; }
public async Task<bool> VerifyTimeSlotAvailable(BookingRecord bookingRecord) { const string verifyTimeSlot = @" SELECT Count(*) FROM bookingrecord WHERE Date = @Date AND TimeSlotID = @TimeSlotID AND Cancel = 0"; try { await using var _connection = new MySqlConnection(_mySqlConfig.ConnectionString); var bookingRecords = await _connection.QueryAsync<int>(verifyTimeSlot, new { bookingRecord.Date, bookingRecord.TimeSlotID }); return bookingRecords.Single() == 0; } catch (MySqlException exception) { // TODO: log expection Console.WriteLine(exception); throw; } catch (InvalidOperationException exception) { // TODO: log expection Console.WriteLine(exception); throw; } }
public async Task <IActionResult> PostBookingRecord([FromBody] BookingRecord bookingRecord) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.BookingRecords.Add(bookingRecord); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (BookingRecordExists(bookingRecord.BookingId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetBookingRecord", new { id = bookingRecord.BookingId }, bookingRecord)); }
public ActionResult DeleteConfirmed(int id) { BookingRecord bookingRecord = db.Bookings.Find(id); db.Bookings.Remove(bookingRecord); db.SaveChanges(); return(RedirectToAction("Index")); }
public Task AddAsync(BookingRecord booking) { var data = booking.ToDataModel(); context.BookingRecords.Add(data); return(Task.CompletedTask); }
public LocalBookingModel GetConfirmedEvents(System.String bookId) { //Update person details BookingRecord record = this.Provider.DataProvider.Learning.Booking.GetConfirmedEvents(bookId); LocalBookingModel model = record == null ? null : new LocalBookingModel(this.Provider, record); return(model); }
public override void Modify(BookingRecord record) { DbCommand command = this.Provider.GetStoredProcedure("spInsertUpdateBooking"); this.MapParameterIn(command, "@PA_USER_LOGIN_ID", "dev"); this.MapParametersIn(command, record, true); this.Execute(command); this.MapParametersOut(command, record); }
public bool Equals(BookingRecord other) { return(other != null && FirstName != null && FirstName.Equals(other.FirstName) && Surname != null && Surname.Equals(other.Surname) && Price != null && Price.Equals(other.Price) && Deposit != null && Deposit.Equals(other.Deposit) && CheckIn != null && CheckIn.Equals(other.CheckIn) && CheckIn != null && CheckIn.Equals(other.CheckIn)); }
public async Task BookAppointment_ShouldReturnFalse_WhenTimeSlotIsTaken() { var dummyBookingRecord = new BookingRecord(); _appointmentRepoMock.Setup(x => x.VerifyTimeSlotAvailable(dummyBookingRecord)).ReturnsAsync(false); var timeSlotavailability = await _appointmentService.BookAppointment(dummyBookingRecord); Assert.False(timeSlotavailability); }
public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,Age,Gender,Departure,Arrival,DepartureTime,ArrivalTime,FlightNumber,Price,FareClass,PromoCode,State,Note")] BookingRecord bookingRecord) { if (ModelState.IsValid) { db.Entry(bookingRecord).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bookingRecord)); }
public IHttpActionResult GetBookingRecord(int id) { BookingRecord bookingRecord = db.BookingRecords.Find(id); if (bookingRecord == null) { return(NotFound()); } return(Ok(bookingRecord)); }
public static Domain.Models.BookingRecord ToDomainModel(this BookingRecord record) => Domain.Models.BookingRecord.FromStorage(record.Id, record.User, record.AccommodationId, record.AccommodationName, record.FacilityId, record.FacilityName, record.StreetAddress, record.FromDate, record.ToDate, record.CanceledOn, record.CheckedInOn);
public static BookingRepresentation ToRepresentation(this BookingRecord record) => new BookingRepresentation { Id = record.Id, AccommodationId = record.AccommodationId, AccommodationName = record.AccommodationName, FacilityId = record.FacilityId, FacilityName = record.FacilityName, StreetAddress = record.StreetAddress, FromDate = record.FromDate, ToDate = record.ToDate };
public void Delete(BookingRecord deleteThis) { _dataEngine.InitialiseParameterList(); _dataEngine.AddParameter("@Id", deleteThis.Id.ToString()); _sqlToExecute = "DELETE FROM [dbo].[BookingRecord] WHERE Id = " + _dataEngine.GetParametersForQuery(); if (!_dataEngine.ExecuteSql(_sqlToExecute)) { throw new Exception("BookingRecord - Delete failed"); } }
public void Update(BookingRecord updateThis) { try { _db.Bookings.Attach(updateThis); _db.Refresh(RefreshMode.KeepCurrentValues, updateThis); _db.SubmitChanges(); } catch (Exception e) { throw new Exception(e.Message); } }
public int Insert(BookingRecord saveThis) { try { _db.Bookings.InsertOnSubmit(saveThis); _db.SubmitChanges(); return(saveThis.Id); } catch (Exception e) { throw new Exception(e.Message); } }
/// <summary> /// Creates the object from the data returned from the database /// </summary> /// <returns></returns> private BookingRecord CreateBookingRecordFromData() { var bookingRecord = new BookingRecord { TimeArrived = int.Parse(_dataEngine.Dr["TimeArrived"].ToString()), ArrivalRegistrationMethod = (ArrivalRegistrationMethod)int.Parse(_dataEngine.Dr["ArrivalRegistrationMethod"].ToString()), BookingStatus = (BookingStatus)int.Parse(_dataEngine.Dr["BookingStatus"].ToString()), BookingRecordUniqueId = _dataEngine.Dr["BookingRecordUniqueId"].ToString(), BookingRecordPin = int.Parse(_dataEngine.Dr["BookingRecordPin"].ToString()), Id = int.Parse(_dataEngine.Dr["Id"].ToString()) }; return(bookingRecord); }
public IHttpActionResult DeleteBookingRecord(int id) { BookingRecord bookingRecord = db.BookingRecords.Find(id); if (bookingRecord == null) { return(NotFound()); } db.BookingRecords.Remove(bookingRecord); db.SaveChanges(); return(Ok(bookingRecord)); }
// GET: BookingRecords/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BookingRecord bookingRecord = db.Bookings.Find(id); if (bookingRecord == null) { return(HttpNotFound()); } return(View(bookingRecord)); }
public void Delete(BookingRecord deleteThis) { try { if (deleteThis.Id > 0) { _db.Bookings.DeleteOnSubmit(deleteThis); _db.SubmitChanges(ConflictMode.FailOnFirstConflict); } } catch (Exception e) { throw new Exception(e.Message); } }
public async Task UpdateAsync(BookingRecord booking) { var data = await context.BookingRecords.FindAsync(booking.Id); data.User = booking.User; data.AccommodationId = booking.AccommodationId; data.AccommodationName = booking.AccommodationName; data.FacilityId = booking.FacilityId; data.FacilityName = booking.FacilityName; data.StreetAddress = booking.StreetAddress; data.FromDate = booking.FromDate; data.ToDate = booking.ToDate; data.CanceledOn = booking.CanceledOn; data.CheckedInOn = booking.CheckedInOn; }
public ActionResult NewBookingRecord(int ID) { //WIP var bookingRecord = new BookingRecord(); bookingRecord.HomeID = ID; bookingRecord.UserID = User.Identity.GetUserId(); var viewModel = new BookingViewModel() { bookingRecord = bookingRecord, Home = _context.Homes.Where(m => m.ID == ID).SingleOrDefault() }; return(View("BookingRecordForm", viewModel)); }
public async Task<bool> AddAppointment(BookingRecord bookingRecord, int contactID) { const string addAppointment = @" INSERT INTO bookingrecord ( ContactID, TimeSlotID, Date, Description, CreatedDate, Cancel) VALUES ( @ContactID, @TimeSlotID, @Date, @Description, @CreatedDate, @Cancel);"; try { await using var _connection = new MySqlConnection(_mySqlConfig.ConnectionString); var inserted = await _connection.ExecuteAsync(addAppointment, new { ContactID = contactID, TimeslotID = bookingRecord.TimeSlotID, bookingRecord.Date, bookingRecord.Description, CreatedDate = DateTime.Now, Cancel = false }); return inserted > 0; } catch (MySqlException exception) { // TODO: log expection Console.WriteLine(exception); throw; } catch (InvalidOperationException exception) { // TODO: log expection Console.WriteLine(exception); throw; } }
public async Task <Guid> Handle(BookAccommodationCommand request, CancellationToken cancellationToken) { var accommodation = await facilityDataSource.FindAccommodationAsync(request.AccommodationId); if (accommodation == null) { throw new AccommodationNotFoundException(request.AccommodationId); } var facility = await facilityDataSource.FindFacilityAsync(accommodation.FacilityId); var bookingRecord = BookingRecord.NewBooking(accommodation, facility, request.FromDate, request.ToDate, securityContext); await bookingRepository.AddAsync(bookingRecord); await bookingRepository.SaveChangesAsync(bookingRecord, commandContext); return(bookingRecord.Id); }