public string ShowJoinButton(string id)
        {
            if (tp == null)
            {
                tp = new TripContext();
            }
            try
            {
                TripGroupContext   g = new TripGroupContext();
                AspNetUsersContext u = new AspNetUsersContext();
                Trip        te       = tp.Trips.Single(a1 => a1.id.ToString() == id);
                AspNetUsers a        = u.AspNetUsers.Single(c1 => c1.Id == te.created_by);

                if (a.UserName == User.Identity.Name)
                {
                    return("1");
                }
                else if (te.vacant_seats == 0)
                {
                    return("2");
                }
                else
                {
                    return("3");
                }
            }
            catch
            {
                return("3");
            }
        }
Пример #2
0
        public DatabaseFixture()
        {
            var options = new DbContextOptionsBuilder <TripContext>()
                          .UseInMemoryDatabase(databaseName: "TripManagement")
                          .Options;

            //Initializing DbContext with InMemory
            context = new TripContext(options);

            // Insert seed data into the database using one instance of the context
            context.Trips.Add(new Trip {
                TripId = 1, CustomerId = 1, EmployeeId = 1, VechileId = 1, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(5), From = "Coimbatore", To = "Mumbai", Status = "Booked", Fare = 0
            });
            context.SaveChanges();
        }
        public ActionResult ShowTripData(SearchBarModel f)
        {
            if (tp == null)
            {
                tp = new TripContext();
            }
            List <Trip> l_t = new List <Trip>();

            if (f.source == null && f.destination == null && f.date == null)   //all fields null
            {
                l_t = tp.Trips.ToList();
            }
            else if (f.source == null && f.destination == null)      //only date is provided
            {
                l_t = tp.Trips.Where(u => u.date == f.date).ToList();
            }
            else if (f.source == null && f.date == null)    //only destination is provided
            {
                l_t = tp.Trips.Where(u => u.destination == f.destination).ToList();
            }
            else if (f.destination == null && f.date == null)   //only source is provided
            {
                l_t = tp.Trips.Where(u => u.source == f.source).ToList();
            }
            else if (f.date == null)         //Source and destination are provided
            {
                l_t = tp.Trips.Where(u => u.source == f.source && u.destination == f.destination).ToList();
            }
            else if (f.destination == null)      //Source and date are provided
            {
                l_t = tp.Trips.Where(u => u.source == f.source && u.date == f.date).ToList();
            }
            else if (f.source == null)           // destination and date are provided
            {
                l_t = tp.Trips.Where(u => u.destination == f.destination && u.date == f.date).ToList();
            }
            else               //all fields are provided
            {
                l_t = tp.Trips.Where(u => u.source == f.source && u.date == f.date && u.destination == f.destination).ToList();
            }
            return(View("ShowTripData", l_t));
        }
Пример #4
0
 public TripRepository(ITripContext context)
 {
     _context = context;
 }
Пример #5
0
 public void Dispose()
 {
     context = null;
 }
 public TripController(ITripContext I_t)
 {
     tp = I_t;
 }
Пример #7
0
 public TripRepository(ITripContext dbContext)
 {
     _context = dbContext;
 }