Exemplo n.º 1
0
        public async Task <IEnumerable <Guest> > GetAll()
        {
            var guests = await _bookingContext.Guests.ToListAsync();

            guests.ForEach(x => { _bookingContext.Entry(x).Reference(y => y.Reservation).LoadAsync(); });
            return(guests);
        }
Exemplo n.º 2
0
        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 IHttpActionResult PutBooking(int id, Booking booking)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != booking.BookingID)
            {
                return(BadRequest());
            }

            db.Entry(booking).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Put(Book developer)
        {
            _context.Entry(developer).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemplo n.º 5
0
        public IHttpActionResult PutAttendee(int id, Attendee attendee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != attendee.AttendeeID)
            {
                return(BadRequest());
            }

            db.Entry(attendee).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AttendeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> PutCar(int id, Car car)
        {
            if (id != car.CarID)
            {
                return(BadRequest());
            }

            _context.Entry(car).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public IHttpActionResult PutLogin(int id, Login login)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != login.StudentID)
            {
                return(BadRequest());
            }

            db.Entry(login).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LoginExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> PutCategoryModel(int id, CategoryModel categoryModel)
        {
            logger.LogInformation("Updating Category by id");

            if (id != categoryModel.Id)
            {
                return(BadRequest());
            }

            _context.Entry(categoryModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    logger.LogWarning("API couldn't update database");
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 9
0
        public async Task <IActionResult> PutTimeslot(int id, Timeslot timeslot)
        {
            if (id != timeslot.Id)
            {
                return(BadRequest());
            }

            _context.Entry(timeslot).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TimeslotExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 10
0
        public async Task <IHttpActionResult> PutRoom(int id, Room room)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != room.RoomID)
            {
                return(BadRequest());
            }

            db.Entry(room).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoomExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> PutBookings([FromRoute] string id, [FromBody] Bookings bookings)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bookings.Booking_id)
            {
                return(BadRequest());
            }

            _context.Entry(bookings).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookingsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutRooms([FromRoute] int id, [FromBody] Rooms rooms)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != rooms.ID)
            {
                return(BadRequest());
            }

            _context.Entry(rooms).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                //if (!RoomsExists(id))
                //{
                //    return NotFound();
                //}
                //else
                //{
                //    throw;
                //}
            }

            return(NoContent());
        }
Exemplo n.º 13
0
        public async void Test_Repository_InsertAsync()
        {
            using var ctx = new BookingContext(options);
            var bookings = new Repository <BookingModel>(ctx);

            await bookings.InsertAsync(_booking);

            Assert.Equal(EntityState.Added, ctx.Entry(_booking).State);
        }
Exemplo n.º 14
0
 public ActionResult Edit([Bind(Include = "TableId,TableNumber,TableCapacity")] TableModel tableModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tableModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tableModel));
 }
Exemplo n.º 15
0
 public ActionResult Edit([Bind(Include = "Id,RoomNumber,CapacityOfPeople")] Room room)
 {
     if (ModelState.IsValid)
     {
         db.Entry(room).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(room));
 }
Exemplo n.º 16
0
 public ActionResult Edit([Bind(Include = "Id,ClientName,Phone,Email,Insurance")] Client client)
 {
     if (ModelState.IsValid)
     {
         db.Entry(client).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(client));
 }
Exemplo n.º 17
0
 public ActionResult Edit([Bind(Include = "Booking_id,booking_title,start_time,end_time,participants,note,room_id,users_id")] Bookings bookings)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bookings).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(bookings));
 }
Exemplo n.º 18
0
 public ActionResult Edit([Bind(Include = "CustomerId,FirstName,LastName,Telephone,Email")] CustomerModel customerModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customerModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerId = new SelectList(db.Bookings, "BookingId", "BookingComments", customerModel.CustomerId);
     return(View(customerModel));
 }
Exemplo n.º 19
0
 public ActionResult Edit([Bind(Include = "BookingId,BookingDateTime,Duration,PartySize,TableAllocation,BookingComments")] BookingModel bookingModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bookingModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BookingId = new SelectList(db.Customers, "CustomerId", "FirstName", bookingModel.BookingId);
     ViewBag.BookingId = new SelectList(db.Tables, "TableId", "TableId", bookingModel.BookingId);
     return(View(bookingModel));
 }
Exemplo n.º 20
0
        public async Task <IActionResult> PutTodoItem(long id, Appointment appointment)
        {
            if (id != appointment.Id)
            {
                return(BadRequest());
            }

            _context.Entry(appointment).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemplo n.º 21
0
        public async Task <IActionResult> PutTodoItem(int id, Club item)
        {
            if (id != item.Id)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemplo n.º 22
0
        public async Task <IActionResult> PutSeatItem(string seatNumber, SeatItem seatItem)
        {
            var requestedSeat = await _context.SeatItems.AsNoTracking().Where(t => t.SeatNumber == seatNumber).FirstAsync();

            if (!seatNumber.Equals(seatItem.SeatNumber))
            {
                return(BadRequest());
            }//doesn't allow  null values for email or unique names to be entered
            else if (seatItem.EmailAddress == null || seatItem.UniqueName == null)
            {
                return(BadRequest());
            }
            else if (requestedSeat.Booked) //doesn't allow if seat is already booked
            {
                return(BadRequest());
            }

            _context.Entry(seatItem).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Ok());
        }
Exemplo n.º 23
0
 public async Task<Booking> UpdateBooking(Booking booking)
 {
     _context.Entry(booking).State = EntityState.Modified;
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         return null;
     }
     return booking;
 }
Exemplo n.º 24
0
        public async Task <Domain.Model.Booking> GetBookingAsync(int bookingId)
        {
            var bookingEntity = await context.Set <BookingEntity>().FindAsync(bookingId);

            if (bookingEntity != null)
            {
                // load court
                await context.Entry(bookingEntity).Reference(i => i.Court).LoadAsync();

                var court = new Court(bookingEntity.Court.Id, (CourtType)bookingEntity.Court.CourtType);

                return(new Domain.Model.Booking(bookingEntity.Id, bookingEntity.PhoneNo, court, bookingEntity.BookedFrom, (BookingStatus)bookingEntity.Status));
            }

            return(null);
        }
Exemplo n.º 25
0
        public async void Test_Repository_Update()
        {
            using var ctx = new BookingContext(options);
            var bookings = new Repository <BookingModel>(ctx);

            ctx.Bookings.Add(
                new BookingModel()
            {
                EntityId  = 0,
                AccountId = 1,
                LodgingId = 1,
                CheckIn   = DateTime.Now.Date,
                CheckOut  = DateTime.Now.AddDays(3).Date,
                Guests    = new List <GuestModel>()
                {
                    new GuestModel()
                    {
                        EntityId       = 0,
                        BookingModelId = 0,
                        FirstName      = "First Name User",
                        LastName       = "Last Name User",
                        IsMinor        = false
                    }
                },
                Rentals = new List <RentalModel>()
                {
                    new RentalModel()
                    {
                        LodgingRentalId = 1
                    }
                }
            }
                );
            await ctx.SaveChangesAsync();

            var booking = await ctx.Bookings.FirstAsync();

            booking.CheckOut = DateTime.Now;
            bookings.Update(booking);

            var result = ctx.Bookings.Find(booking.EntityId);

            Assert.Equal(booking.CheckOut, result.CheckOut);
            Assert.Equal(EntityState.Modified, ctx.Entry(result).State);
        }
        public async Task <IActionResult> PutEvents([FromRoute] int id, [FromBody] Events events)
        {
            //todo add in user check here

            string UserEmail = User.Identity.Name;

            if (!ModelState.IsValid || UserEmail == null || events.Email != UserEmail)
            {
                return(BadRequest(ModelState));
            }

            if (id != events.Id)
            {
                return(BadRequest());
            }

            _context.Entry(events).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                //if (!EventsExists(id))
                //{
                //    return NotFound();
                //}
                //else
                //{
                //    throw;
                //}
            }

            return(NoContent());
        }
Exemplo n.º 27
0
 public void Update(Booking booking)
 {
     bookingDb.Entry(booking).State = System.Data.Entity.EntityState.Modified;
 }
Exemplo n.º 28
0
 public void Update(Author author)
 {
     db.Entry(author).State = System.Data.Entity.EntityState.Modified;
 }
Exemplo n.º 29
0
 public void Update(Book book)
 {
     db.Entry(book).State = System.Data.Entity.EntityState.Modified;
 }
Exemplo n.º 30
0
 public void Update(TEntity entity)
 {
     _context.Entry(entity).State = EntityState.Modified;
     _context.SaveChanges();
 }