Exemplo n.º 1
0
        public async Task <IActionResult> PutCustomer(int id, [FromBody] Customer customer)
        {
            if (id != customer.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutReservation(int id, Reservation reservation)
        {
            _logger.LogInformation(nameof(PutReservation) + "(1) - Invoked...");


            if (id != reservation.ReservationID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PutInvoice(int id, [FromBody] Invoice invoice)
        {
            if (id != invoice.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> PutReservations(int id, Reservations reservations)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != reservations.ReservationID)
            {
                return(BadRequest());
            }

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

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

            return(Ok(reservations));
        }
Exemplo n.º 5
0
        // PUT api/Countries/5
        public async Task <IHttpActionResult> PutCountry(int id, Country country)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> PutReservation(int id, Reservation reservation)
        {
            if (id != reservation.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
 public virtual void Edit(T entity)
 {
     using (context = new ReservationContext())
     {
         context.Entry(entity).State = EntityState.Modified;
         context.SaveChanges();
         //context.Entry(entity).Reload();
     }
 }
 public ActionResult Edit([Bind(Include = "Id,BookISBN,StudentId,Doyoureserve,Date")] Reservation reservation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(reservation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(reservation));
 }
        public async Task <MeetingRoom> GetAsync(int meetingRoomId)
        {
            var meetingRoom = await _context.MeetingRooms
                              .FirstOrDefaultAsync(m => m.Id == meetingRoomId);

            if (meetingRoom == null)
            {
                meetingRoom = _context.MeetingRooms.Local
                              .FirstOrDefault(m => m.Id == meetingRoomId);
            }

            if (meetingRoom != null)
            {
                await _context.Entry(meetingRoom)
                .Collection(i => i.UnmovableResources).LoadAsync();
            }

            return(meetingRoom);
        }
Exemplo n.º 10
0
 public ActionResult Edit([Bind(Include = "Id,UserId,Password,FirstName,LastName,Gender,DateOfBirth,Email,ContactNumber")] User user)
 {
     if (ModelState.IsValid)
     {
         con.Entry(user).State = EntityState.Modified;
         con.SaveChanges();
         return(RedirectToAction("Index", user));
     }
     return(View(user));
 }
 public ActionResult Edit([Bind(Include = "Id,TrainId,TrainName,Source,Destination,DateOfTravel,TimeOfArrival,TrainType,SeatAvailability,NoOfSeat")] Train train)
 {
     if (ModelState.IsValid)
     {
         db.Entry(train).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(train));
 }
 public ActionResult Edit([Bind(Include = "Id,Name,SName,Grade")] Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(student));
 }
Exemplo n.º 13
0
        public async Task <Reservation> GetAsync(int reservationId)
        {
            var reservation = await _context.Reservations
                              .FirstOrDefaultAsync(r => r.Id == reservationId);

            if (reservation == null)
            {
                reservation = _context.Reservations.Local
                              .FirstOrDefault(r => r.Id == reservationId);
            }

            if (reservation != null)
            {
                await _context.Entry(reservation)
                .Collection(i => i.MovableResources).LoadAsync();
            }

            return(reservation);
        }
Exemplo n.º 14
0
 public ActionResult Edit([Bind(Include = "ID,LastName,FirstName,Occupation")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
Exemplo n.º 15
0
 public ActionResult Edit([Bind(Include = "ID,LastName,FirstName,Phone,StrAdd,City,State")] Client client)
 {
     if (ModelState.IsValid)
     {
         db.Entry(client).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(client));
 }
Exemplo n.º 16
0
 public ActionResult Edit([Bind(Include = "ID,UserName,Hair,Gender")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
Exemplo n.º 17
0
 public ActionResult Edit([Bind(Include = "id,check_in_date,check_out_date,room_count,reserve_date,cancel_date,notes,user_id")] Reservation reservation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(reservation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(reservation));
 }
Exemplo n.º 18
0
 public ActionResult Edit([Bind(Include = "ISBN,Title,Detail")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(book));
 }
Exemplo n.º 19
0
 public ActionResult Edit([Bind(Include = "Id,TrainId,Stop,ArrivalTime")] TrainSchedule trainSchedule)
 {
     if (ModelState.IsValid)
     {
         db.Entry(trainSchedule).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(trainSchedule));
 }
Exemplo n.º 20
0
 public ActionResult Edit([Bind(Include = "ReservationID,UserID,Hair,ReservationDate")] Reservation reservation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(reservation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserID = new SelectList(db.Users, "ID", "UserName", reservation.UserID);
     return(View(reservation));
 }
 public int Add(T entity)
 {
     using (context = new ReservationContext())
     {
         context.Set <T>().Add(entity);
         context.SaveChanges();
         DbPropertyValues sa      = context.Entry(entity).GetDatabaseValues();
         string           keyName = sa.PropertyNames.First();
         int Id = sa.GetValue <int>(keyName);
         return(Id);
     }
 }
Exemplo n.º 22
0
 public ActionResult Edit([Bind(Include = "ID,ReservationDate,CourseID,StudentID")] Reservation reservation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(reservation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CourseID  = new SelectList(db.Courses, "CourseID", "Name", reservation.CourseID);
     ViewBag.StudentID = new SelectList(db.Students, "StudentID", "FirstName", reservation.StudentID);
     return(View(reservation));
 }
Exemplo n.º 23
0
 public ActionResult Edit([Bind(Include = "ReservationID,ClientID,EmployeeID,Date,Time,ClientName,EmployeeName")] Reservation reservation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(reservation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ClientID   = new SelectList(db.Clients, "ID", "LastName", reservation.ClientID);
     ViewBag.EmployeeID = new SelectList(db.Employees, "ID", "LastName", reservation.EmployeeID);
     return(View(reservation));
 }
Exemplo n.º 24
0
        public void DeleteReservation(Guid reservationId)
        {
            ReservationContext context = new ReservationContext();

            Reservation reservation = (from r in context.Reservations where r.Id == reservationId select r).FirstOrDefault();

            if (reservation == null)
            {
                throw new ArgumentException(string.Format("There's no reservation by ID {0}", reservationId));
            }
            context.Entry <Reservation>(reservation).State = System.Data.Entity.EntityState.Deleted;

            context.SaveChanges();
        }
Exemplo n.º 25
0
        public void AddReservation(AddReservationValidationResult addReservationValidationResult)
        {
            ReservationContext context = new ReservationContext();

            if (addReservationValidationResult.ValidationComplete)
            {
                context.Entry <Reservation>(addReservationValidationResult.ToBeInserted).State = System.Data.Entity.EntityState.Added;
            }
            else
            {
                throw new InvalidOperationException("Validation is not complete. You have to call the AddReservation method of the Timetable class first.");
            }

            context.SaveChanges();
        }
Exemplo n.º 26
0
        public bool ExchangeReservation(string pTeacherFrom, int pReservationFrom, string pTeacherTo, int pReservationTo)
        {
            if (_reservationContext.Teachers.Find(pTeacherFrom) == null ||
                _reservationContext.Teachers.Find(pTeacherTo) == null)
            {
                //Teachers couldnt be found
                return(false);
            }

            Reservation reservationFrom = _reservationContext.Reservations.Find(pReservationFrom);
            Reservation reservationTo   = null;

            if (pReservationTo != -1)
            {
                reservationTo = _reservationContext.Reservations.Find(pReservationTo);
            }

            if (reservationFrom == null || (pReservationTo != -1 && reservationTo == null))
            {
                return(false);
            }

            //Es wird getauscht
            reservationFrom.TeacherId = pTeacherTo;
            reservationFrom.CourseId  = null;
            if (pReservationTo != -1)
            {
                reservationTo.TeacherId = pTeacherFrom;
                reservationTo.CourseId  = null;
                _reservationContext.Entry(reservationTo).State = EntityState.Modified;
            }
            _reservationContext.Entry(reservationFrom).State = EntityState.Modified;
            _reservationContext.SaveChanges();

            return(true);
        }
        public async Task <IActionResult> PutReservation(int id, ReservationCreateDTO reservationDTO)
        {
            if (!ReservationExists(id))
            {
                return(NotFound());
            }

            var reservation = DTOCreateToReservation(reservationDTO);

            reservation.Id                    = id;
            reservation.UpdatedAt             = DateTime.UtcNow;
            _context.Entry(reservation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest());
            }

            return(NoContent());
        }
Exemplo n.º 28
0
        //[HttpGet]
        public IActionResult EditIncoming(int exchangeid, bool accept)
        {
            ExchangeReservation exchangeReservation = _databaseHandler.GetExchangeReservationById(exchangeid);

            if (_userManager.GetUserAsync(User).Result.Id == exchangeReservation.TeacherFrom)
            {
                exchangeReservation.ExchangeAccepted = accept;
                if (accept)
                {
                    _databaseHandler.ExchangeReservation(exchangeReservation.TeacherFrom,
                                                         exchangeReservation.ReservationFromId, exchangeReservation.TeacherTo,
                                                         exchangeReservation.ReservationOfferId);
                }
            }

            exchangeReservation.ExchangeStatus = true;
            _reservationContext.Entry(exchangeReservation).State = EntityState.Modified;
            _reservationContext.SaveChanges();
            return(RedirectToAction("Anfragen"));
        }
Exemplo n.º 29
0
        public async Task <IActionResult> PutContact(int id, ContactCreateDTO contactCreateDTO)
        {
            if (!ContactExists(id))
            {
                return(BadRequest());
            }

            var contactType = ContactTypeExists(contactCreateDTO.ContactType);

            if (contactType == null)
            {
                return(BadRequest());
            }

            var contact = new Contact
            {
                Id          = id,
                Name        = contactCreateDTO.Name,
                Birthdate   = contactCreateDTO.Birthdate,
                ContactType = contactCreateDTO.ContactType,
                Phone       = contactCreateDTO.Phone,
                UpdatedAt   = DateTime.UtcNow
            };

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

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

            return(NoContent());
        }
Exemplo n.º 30
0
        public async Task <IActionResult> PutContactType(int id, ContactTypeCreateDTO contactTypeCreateDTO)
        {
            if (!ContactTypeExists(id))
            {
                return(NotFound());
            }

            var contactType = new ContactType {
                Id = id, Description = contactTypeCreateDTO.Description, UpdatedAt = DateTime.UtcNow
            };

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest());
            }

            return(NoContent());
        }