public async Task <IActionResult> PutDbBooking(int id, DbBooking dbBooking) { if (id != dbBooking.id) { return(BadRequest()); } _context.Entry(dbBooking).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DbBookingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <DbBooking> > PostDbBooking(DbBooking dbBooking) { _context.DBookings.Add(dbBooking); await _context.SaveChangesAsync(); return(CreatedAtAction("GetDbBooking", new { id = dbBooking.id }, dbBooking)); }
private ActionResult SetStatusIfExistsAndUserIsOwner(int?bookingId, EBookingStatus status) { if (bookingId == null) { return(RedirectToAction("Index")); } var bookingsRepository = _unitOfWork.BookingsRepository; DbBooking booking = bookingsRepository.Get((int)bookingId); if (booking == null) { return(RedirectToAction("Index")); } AuthenticatedUser user = (AuthenticatedUser)User; if (user.Id != booking.Location.CreatedByUserId) { return(RedirectToAction("Index")); } booking.StatusId = (int)status; bookingsRepository.Update(booking); return(RedirectToAction("Index")); }
public async Task Reserve(Guid productId) { var product = await _context.Products .FirstAsync(x => x.Id == productId); var productBooking = await _context.Bookings .FirstOrDefaultAsync(x => x.ProductId == productId); if (product.Count == 0) { throw new InvalidOperationException(); } if (productBooking != null) { product.Count--; productBooking.Count++; } else { product.Count--; productBooking = new DbBooking { ProductName = product.Name, Count = 1, ProductId = productId, BookerUserId = Guid.Parse(_httpContextAccessor.HttpContext.User.Claims .First(c => c.Type == "UserId").Value), OwnerUserId = product.OwnerId }; } _context.Update(product); _context.Update(productBooking); await _context.SaveChangesAsync(); }
public async Task AddBookingAsync( TenantId tenantId, BookingId bookingId, CustomerId clientId, DateTime proposedTime, TimeSpan duration, CancellationToken cancellationToken) { using (var context = CreateBookingEntityContext()) { var booking = new DbBooking { BookingId = bookingId.Id, TenantId = tenantId.Id, CustomerId = clientId.Id, Status = BookingStatus.Provisional, ProposedTime = proposedTime, Duration = duration }; context.Bookings.Add(booking); await context .SaveChangesAsync(cancellationToken) .ConfigureAwait(false); } }
public IHttpActionResult GetBooking(int id) { DbBooking booking = this.db.Bookings.Find(id); if (booking == null) { return(this.NotFound()); } return(this.Ok(booking.ToApiBooking())); }
public BookingDTO(DbBooking booking) { foreach (var i in typeof(DbBooking).GetProperties()) { var property = typeof(BookingDTO).GetProperty(i.Name); if (property != null) { property.SetValue(this, i.GetValue(booking)); } } }
public ReadBooking(DbBooking booking) { _innerBooking = booking; BookingId = new BookingId(_innerBooking.BookingId); CustomerId = new CustomerId(_innerBooking.CustomerId); TherapistBookings = _innerBooking .TherapistBookings .Select(tb => (IReadTherapistBooking) new ReadTherapistBooking(tb)) .ToList() .AsReadOnly(); }
public ActionResult Cancel(int id) { DbBooking booking = db.Bookings.Find(id); if (booking != null) { booking.Canceled = DateTime.Now; db.Entry(booking).CurrentValues.SetValues(booking); db.SaveChanges(); } return(RedirectToAction("Index")); }
public void Delete(DeleteBookingRequest request) { DbBooking dbBooking = new DbBooking(); if (request.Id.HasValue) { dbBooking.Delete(request.Id.Value); } else { throw new Exception("Please enter a valid ID"); } }
public static DbBooking Update(DbBooking booking, BookingDTO dto) { booking.Comments = dto.Comments; booking.EndDateTime = dto.EndDateTime; booking.GarageId = dto.GarageId; booking.ServiceLineId = dto.ServiceLineId; booking.Id = dto.Id; booking.LicensePlate = dto.LicensePlate; booking.Phone = dto.Phone; booking.StartDateTime = dto.StartDateTime; booking.Type = dto.Type; booking.TyreHotel = dto.TyreHotel; return(booking); }
public IHttpActionResult DeleteBooking(int id) { DbBooking booking = this.db.Bookings.Find(id); if (booking == null) { return(this.NotFound()); } this.db.Bookings.Remove(booking); this.db.SaveChanges(); return(this.Ok(booking)); }
public ActionResult PostDetails(int?id, LocationBookingViewModel model) { if (!DoesLocationExist(id)) { return(RedirectToAction("Index")); } if (model.From > model.To) { ModelState.AddModelError("From", "Van datum moet voor Tot datum liggen"); } if (!ModelState.IsValid) { return(Details((int)id, model)); } // Only allow booking if the location is not yet booked during this period var bookingsRepository = _unitOfWork.BookingsRepository; bool isAlreadyBooked = bookingsRepository.IsLocationBookedDuringPeriod((int)id, model.From, model.To); if (isAlreadyBooked) { ModelState.AddModelError(string.Empty, "Locatie is al geboekt in deze periode"); return(Details((int)id, model)); } try { DbBooking booking = new DbBooking(); booking.LocationId = (int)id; booking.Organisation = model.Organisation; booking.StartDateTime = model.From; booking.EndDateTime = model.To; booking.StatusId = (int)EBookingStatus.Pending; booking.UserId = ((AuthenticatedUser)User).Id; bookingsRepository.Insert(booking); TempData["AlertType"] = "success"; TempData["AlertMessage"] = "De aanvraag om deze locatie te boeken van " + model.From.Date + " tot " + model.To.Date + " is successvol ingediend."; } catch { TempData["AlertType"] = "danger"; TempData["AlertMessage"] = "Er is iets fout gelopen tijdens het verwerken van de boeking!"; return(Details((int)id, model)); } return(RedirectToAction("Details", new { id = id })); }
public ActionResult Edit(DbBooking model) { DbBooking booking = db.Bookings.Where( x => x.Id == model.Id).SingleOrDefault(); if (booking != null) { model.Edited = DateTime.Now; db.Entry(booking).CurrentValues.SetValues(model); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public MainWindow() { InitializeComponent(); DbBooking b = new DbBooking(); //b.InsertBooking(1, 1, DateTime.Now, DateTime.Now); var xxx = b.GetAllUnits(false); foreach (var item in xxx) { Button b1 = new Button(); b1.Content = item.Name; b1.Click += (sender, evt) => b.InsertBooking(item.UnitId, 1, DateTime.Now, DateTime.Now); stackPanel.Children.Add(b1); } }
public ActionResult Create(DbBooking dbbooking) { FormValidation(dbbooking); SelectGarage(); SelectVehicle(); if (ModelState.IsValid) { db.Bookings.Add(dbbooking); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dbbooking)); }
public object Get(GetBookingByUserIdRequest request) { DbBooking dbBooking = new DbBooking(); if (request.UserId.HasValue) { var booking = dbBooking.GetBookingByUserID(request.UserId.Value); return(new BookingResponse { Result = booking }); } else { throw new Exception("Please enter a vaild UserID"); }; }
public object Get(BookingRequest request) { DbBooking dbBooking = new DbBooking(); if (request.Id.HasValue) { var booking = dbBooking.GetBookingById(request.Id.Value); return(new BookingResponse { Result = new Booking[] { booking } }); } else { throw new Exception("Please enter a vaild BookingID"); }; }
public object Get(GetAllCafeBookingsRequest request) { DbBooking dbBooking = new DbBooking(); if (request.CafeId.HasValue) { var booking = dbBooking.GetAllCafeBookings(request.CafeId.Value); return(new BookingResponse { Result = booking }); } else { throw new Exception("Please enter a vaild CafeID"); }; }
public object Post(BookingRequest request) { DbBooking dbBooking = new DbBooking(); var bookingDate = DateTime.Now; var booking = new Booking { BookedDate = bookingDate, StartDate = request.StartDate.Value, EndDate = request.StartDate.Value.AddHours(2) }; var bookingId = dbBooking.CreateBooking(request.CafeId.Value, request.UserId.Value, booking, request.NoOfPeople.Value); booking.Id = bookingId; return(new BookingResponse { Result = new Booking[] { booking } }); }
public async Task <IActionResult> GetUserBookings() { var currentUserId = Guid.Parse( _httpContextAccessor.HttpContext.User.Claims.First(c => c.Type == "UserId").Value); DbBooking[] bookings = new DbBooking[0]; if (_httpContextAccessor.HttpContext.User.Claims.First(c => c.Type == "UserRole").Value == "Manager") { bookings = await _context.Bookings.Where(x => x.OwnerUserId == currentUserId && x.Count > 0).ToArrayAsync(); } if (_httpContextAccessor.HttpContext.User.Claims.First(c => c.Type == "UserRole").Value == "Customer") { bookings = await _context.Bookings.Where(x => x.BookerUserId == currentUserId && x.Count > 0).ToArrayAsync(); } return(View(bookings)); }
private void FormValidation(DbBooking dbbooking) { if (ModelState.IsValidField("CustomersPhoneNumber") && dbbooking.CustomersPhoneNumber.ToString().Length < 5) { ModelState.AddModelError("CustomersPhoneNumber", "Customer’s phone number can only contain numbers and must have at least 5 characters"); } else if (ModelState.IsValidField("StartDateTime") && dbbooking.StartDateTime < DateTime.Now) { ModelState.AddModelError("StartDateTime", "Start date and time can't be in past"); } else if (ModelState.IsValidField("EndTime")) { if (dbbooking.EndTime <= dbbooking.StartDateTime.TimeOfDay) { ModelState.AddModelError("EndTime", "End time can’t be earlier or same than Start time"); } else if (dbbooking.EndTime > (dbbooking.StartDateTime.AddHours(2).TimeOfDay)) { ModelState.AddModelError("EndTime", "End time can’t be later than 2 hours from Start time."); } } }