public void Update(CurrentTrip trips)
        {
            var _trips = _context.CurrentTrips.Find(trips.CurrentTripId);

            if (_trips == null)
            {
                throw new AppException("User not found");
            }
            else
            {
                // update user properties\
                _trips.TripName         = trips.TripName;
                _trips.StartingLocation = trips.StartingLocation;
                _trips.TotalBudget      = trips.TotalBudget;
                _trips.Descount         = trips.Descount;
                _trips.TripPackgesId    = trips.TripPackgesId;
                //      _trips.VisitingPlacesId = trips.VisitingPlacesId;
                _trips.TripDuration     = trips.TripDuration;
                _trips.AdvisorsContact1 = trips.AdvisorsContact1;
                _trips.AdvisorsContact2 = trips.AdvisorsContact2;
                _trips.UserId           = trips.UserId;
                _trips.TotalSeats       = trips.TotalSeats;
                _trips.RemainingSeats   = trips.RemainingSeats;
            }


            _context.CurrentTrips.Update(_trips);
            _context.SaveChanges();
        }
        public CurrentTrip Create(CurrentTrip trip)
        {
            if (_context.CurrentTrips.Any(x => x.TripName == trip.TripName))
            {
                throw new AppException("TripName \"" + trip.TripName + "\" is already taken");
            }


            _context.CurrentTrips.Add(trip);
            _context.SaveChanges();

            return(trip);
        }
        public async Task <ActionResult <CurrentTrip> > PostCurrentTrip(CurrentTrip currentTrip)
        {
            var claimsIdentity = this.User.Identity as ClaimsIdentity;
            var Myusername     = claimsIdentity.FindFirst(ClaimTypes.Surname)?.Value;


            currentTrip.UserId      = int.Parse(User.Identity.Name);
            currentTrip.CreatedBy   = Myusername;
            currentTrip.CreatedDate = DateTime.Now;


            _context.CurrentTrips.Add(currentTrip);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCurrentTrip", new { id = currentTrip.CurrentTripId }, currentTrip));
        }
        public async Task <IActionResult> PutCurrentTrip(int id, CurrentTrip currentTrip)
        {
            var claimsIdentity = this.User.Identity as ClaimsIdentity;                // Calling User Data From Users Controller
            var Myusername     = claimsIdentity.FindFirst(ClaimTypes.Surname)?.Value; // Finding Current User

            //      var mycurrentTrip = await _context.CurrentTrips.FindAsync(id);      // finding  Db Values

            if (id != currentTrip.CurrentTripId)
            {
                return(BadRequest());
            }
            //         currentTrip = mycurrentTrip;                // Assigning Values To Current Model
            currentTrip.CurrentTripId  = id;
            currentTrip.ModifiedUserId = int.Parse(User.Identity.Name); // Auto Update
            currentTrip.ModifiedBy     = Myusername;                    // Auto Update
            currentTrip.ModifiedDate   = DateTime.Now;                  // Auto Update



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

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

            return(NoContent());
        }