// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseSwagger();//Must be above the app.Mvc() method. if (env.IsDevelopment() || env.IsStaging()) { //When Server is Hosting app.UseSwaggerUI(options => options.SwaggerEndpoint("/swagger/v1/swagger.json", "Trip Tracker v1") ); } if (env.IsDevelopment()) {//App default condition app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } //App defaults app.UseHttpsRedirection(); app.UseMvc(); //Manual Injection for Seeding Data if the Database is Empty TripContext.SeedData(app.ApplicationServices); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, TripContext tripContext) { //swagger przed usmvc bo sie popsuje app.UseSwagger(); if (env.IsDevelopment() || env.IsStaging()) { app.UseSwaggerUI(o => o.SwaggerEndpoint("/swagger/v1/swagger.json", "Trip Tracker v1")); } ; if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(); tripContext.SeedData(app.ApplicationServices); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseSwagger(); app.UseSwaggerUI(options => options.SwaggerEndpoint("/swagger/v1/swagger.json", "Trip Tracker v1") ); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); TripContext.SeedData(app.ApplicationServices); }
public void UpdateInformation() { if (DriverList.SelectedValue != null) { using (TripContext db = new TripContext()) { var trips = db.Trips.Where(t => (t.Name == DriverList.SelectedValue.ToString() && t.State == "Завершена")); if (DriverList.SelectedValue.ToString() == "Вся компания") { trips = db.Trips.Where(t => t.State == "Завершена"); } DriverName.Text = DriverList.SelectedValue.ToString(); NumberOfTrips.Text = trips.Count().ToString(); int money = 0; foreach (Trip t in trips) { money += Convert.ToInt32(t.Price); } Money.Text = money.ToString() + "р"; PremiumTrip.Text = trips.Where(t => t.CarLevel == "Премиум").Count().ToString(); AverageTrip.Text = trips.Where(t => t.CarLevel == "Средний").Count().ToString(); EconomTrip.Text = trips.Where(t => t.CarLevel == "Эконом").Count().ToString(); } } }
public TripsController(TripContext context) { _context = context; //_context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; // This is good approach for // these kind of scenario as // it doesnt require to track }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { // Enable middleware to serve generated Swagger as a JSON endpoint. if (env.IsDevelopment() || env.IsStaging()) { app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/V1/swagger.json", "Trip Tracker v1"); }); app.UseSwagger(); app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(); TripContext.SeedData(app.ApplicationServices); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseSwagger(); if (env.IsDevelopment() || env.IsStaging()) { app.UseSwaggerUI(options => options.SwaggerEndpoint("/swagger/v1/swagger.json", "Trip Tracker v1") ); } if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(); TripContext.SeedData(app.ApplicationServices); // 1. what is up with the above // 2. in trip context where do i put closing brace? }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { //Using swashbuckle swagger in our application. app.UseSwagger(); if (env.IsDevelopment() || env.IsStaging()) { app.UseSwaggerUI(options => options.SwaggerEndpoint("/swagger/v1/swagger.json", "Trip Tracker v1") ); } if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(); TripContext.SeedData(app.ApplicationServices); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); app.UseHttpsRedirection(); app.UseMvc(); TripContext.SeedData(app.ApplicationServices); }
private async Task <bool> DoClockOut(string actualServicePerformed) { ClockOutDto clockOutDto = new ClockOutDto(); clockOutDto.JobId = long.Parse(this.btnClockInClick.CommandParameter.ToString()); clockOutDto.ActualClockOut = DateTime.Now; clockOutDto.ActualServicePerformed = actualServicePerformed; double weight = 0.0; if (CurrentJob.JobRequiresWeighInOut && !actualServicePerformed.StartsWith("Skipped")) { if (double.TryParse(txtWeightOut.Text, out weight)) { clockOutDto.ActualWeightOut = weight; } else { await DisplayAlert("Weigh Out is Required", "Before you clock out and leave the site, you must Weigh Out.", "OK"); SetSiteCompleteDisplay(btnClockInClick); return(false); } } bool success = await TripContext.ClockOut(clockOutDto); return(success); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseSwagger(); // only use swagger if we are in staging or development, not in production if (env.IsStaging() || env.IsDevelopment()) { // added in tutorial app.UseSwaggerUI(options => options.SwaggerEndpoint("/swagger/v1/swagger.json", "Travel Tracker v1")); } if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(); // pulls seed data from TripContext.cs TripContext.SeedData(app.ApplicationServices); }
public async void ButtonConfirmServiceClicked(object sender, EventArgs e) { bool success = await DoClockOut(lblServiceName.Text); if (success) { lblServiceConfirmMsg.Text = "Clock-Out Completed. Checking for the next Job..."; stkWebViewSiteMap.IsVisible = false; lblServiceConfirmMsg.TextColor = Color.DarkGreen; lblServiceCompleteMsg.IsVisible = true; lblServiceCompleteMsg.TextColor = Color.DarkGreen; stkBtnConfirm.IsVisible = false; stkServiceChoices.IsVisible = false; success = await TripContext.GetNextJob(); await Navigation.PopToRootAsync(); await Navigation.PushAsync(new DirectionsPage()); } else { lblServiceConfirmMsg.Text = "Clock-Out Encountered an Error. Please try again."; lblServiceConfirmMsg.TextColor = Color.DarkRed; stkBtnConfirm.IsVisible = true; } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseSwagger(); if (env.IsDevelopment() || env.IsStaging()) { // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); } // app.UseSwagger(); // app.UseSwaggerUI(options => { // options.SwaggerEndpoint("/v1/swagger.json", " trip"); //}); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); TripContext.SeedData(app.ApplicationServices); }
public string sendEmail(string id, string emailText) { try { if (User.Identity.IsAuthenticated) { string toEmail = null; TripContext a = new TripContext(); Trip b = a.Trips.Single(u => u.id.ToString() == id); AspNetUsersContext us = new AspNetUsersContext(); AspNetUsers au = us.AspNetUsers.Single(z => z.Id == b.created_by); toEmail = au.Email; if (SMTPSendEmail(toEmail, User.Identity.Name + " wants to carpool with you", emailText)) { return("success"); } else { return("fail"); } } else { return("fail"); } } catch { return("fail"); } }
public static void AddTrip(Trip trip, int vehicleId, int employeeId) { using (var db = new TripContext()) { var vehicles_ = db.Vehicles. Where(vehicle => (vehicle.VehicleId == vehicleId)); List <Vehicle> vehicles__ = new List <Vehicle>(); foreach (var vehicle in vehicles_) { vehicles__.Add(vehicle); } Vehicle _vehicle = vehicles__.ElementAt(0); var employees_ = db.Employees. Where(employee => (employee.EmployeeId == employeeId)); List <Employee> employees__ = new List <Employee>(); foreach (var employee in employees_) { employees__.Add(employee); } Employee _employee = employees__.ElementAt(0); trip.Employee = _employee; trip.Vehicle = _vehicle; db.Add(trip); db.SaveChanges(); } }
public static void AddEmployee(Employee employee) { using (var db = new TripContext()) { db.Employees.Add(employee); db.SaveChanges(); } }
public static void AddVehicle(Vehicle vehicle) { using (var db = new TripContext()) { db.Add(vehicle); db.SaveChanges(); } }
/// <summary> /// Initializes a new instance of the <see cref="TransactionBehaviour{TRequest, TResponse}" /> class. /// </summary> /// <param name="dbContext">The database context.</param> /// <param name="tripIntegrationEventService">The ordering integration event service.</param> /// <param name="logger">The logger.</param> /// <exception cref="ArgumentException">TripContext /// or /// tripIntegrationEventService /// or /// ILogger</exception> public TransactionBehaviour(TripContext dbContext, ITripIntegrationEventService tripIntegrationEventService, ILogger <TransactionBehaviour <TRequest, TResponse> > logger) { _dbContext = dbContext ?? throw new ArgumentException(nameof(TripContext)); this.tripIntegrationEventService = tripIntegrationEventService ?? throw new ArgumentException(nameof(tripIntegrationEventService)); _logger = logger ?? throw new ArgumentException(nameof(ILogger)); }
private void AddTrip_Click(object sender, RoutedEventArgs e) { if ((From.Text != "") && (Destination.Text != "") && (PhoneNumber.Text != "") && (Price.Text != "") && (Driver.SelectedValue != null) && (Car.SelectedValue != null)) { using (TripContext db = new TripContext()) { Trip trip = new Trip(); trip.FromWhere = From.Text; trip.Destination = Destination.Text; trip.Name = Driver.SelectedValue.ToString(); trip.CarName = Car.SelectedValue.ToString(); trip.PhoneNumber = PhoneNumber.Text; trip.Price = Price.Text; trip.Date = DateTime.Now.ToShortDateString(); trip.Time = DateTime.Now.ToLongTimeString(); trip.State = "В пути"; trip.CarLevel = TripLevel.SelectedValue.ToString(); using (CarContext cdb = new CarContext()) { Car car = cdb.Cars.Where(c => c.CarName == Car.SelectedValue.ToString()).FirstOrDefault(); if (car != null) { car.State = "Занята"; } cdb.SaveChanges(); } using (UserContext udb = new UserContext()) { User user = udb.Users.Where(u => u.Name == Driver.SelectedValue.ToString()).FirstOrDefault(); if (user != null) { user.state = "Занят"; } udb.SaveChanges(); } db.Trips.Add(trip); db.SaveChanges(); From.Text = ""; Destination.Text = ""; PhoneNumber.Text = ""; Price.Text = ""; } WarnngMessage.Foreground = Brushes.Green; WarnngMessage.Text = "Поездка успешно добавлена"; } else { WarnngMessage.Foreground = Brushes.Red; WarnngMessage.Text = "Заполните все поля"; } updateLists(); }
public TripController() { dbContext = new TripContext(); if (!dbContext.Trips.Any()) { dbContext.Trips.AddRange(Trips); dbContext.SaveChanges(); } }
public ActionResult deleteTrip(int id) { TripContext s = new TripContext(); Trip t = s.Trips.Single(u => u.id == id); s.Trips.Remove(t); s.SaveChanges(); return(RedirectToAction("Index", "Home")); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (_ctx != null) { _ctx.Dispose(); _ctx = null; } } }
public static void UpdateTrip(Trip trip) { List <Trip> trips = new List <Trip>(); using (var db = new TripContext()) { db.Trips.Update(trip); db.SaveChanges(); } }
public TripsController(TripContext dbcontext) // stash a copy of this repository in a private field so we can interact with it: { _dbcontext = dbcontext; // this instructs the app to not use resources tracking changes on any of the results returned from // HTTP requests. We just want a copy to go to the browser with no data built up around it. // "Short-Lived Queries" _dbcontext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; }
public TripInfo(string id) { InitializeComponent(); using (TripContext db = new TripContext()) { Trip trip = db.Trips.Where(t => t.Id.ToString() == id).FirstOrDefault(); if (trip != null) { TripId.Text = "Поездка номер: " + trip.Id.ToString(); FromWhere.Text = "Откуда: " + trip.FromWhere; Destination.Text = "Куда: " + trip.Destination; Driver.Text = "Водитель: " + trip.Name; Car.Text = "Машина: " + trip.CarName; switch (trip.CarLevel) { case "Премиум": CarLevel.Source = new BitmapImage(new Uri("../img/Premium.png", UriKind.Relative)); break; case "Средний": CarLevel.Source = new BitmapImage(new Uri("../img/Average.png", UriKind.Relative)); break; case "Эконом": CarLevel.Source = new BitmapImage(new Uri("../img/Econom.png", UriKind.Relative)); break; } Price.Text = "Цена: " + trip.Price; CustomerNumber.Text = "Номер клиента: " + trip.PhoneNumber; Date.Text = "Дата: " + trip.Date; Status.Text = "Статус: " + trip.State; switch (trip.State) { case "В пути": TripState.Source = new BitmapImage(new Uri("../img/processing.png", UriKind.Relative)); break; case "Завершена": TripState.Source = new BitmapImage(new Uri("../img/Complete.png", UriKind.Relative)); break; case "Отменена": TripState.Source = new BitmapImage(new Uri("../img/canceled.png", UriKind.Relative)); break; } } else { this.Close(); } } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseSwagger(); app.UseSwaggerUI(option => option.SwaggerEndpoint("/swagger/v1/swagger.json", "Trip Tracker v1")); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); TripContext.SeedData(app.ApplicationServices); }
public CarInfo(string number) { InitializeComponent(); using (CarContext db = new CarContext()) { Car car = db.Cars.Where(c => c.CarNumber == number).FirstOrDefault(); if (car != null) { switch (car.CarLevel) { case "Премиум": CarLevel.Source = new BitmapImage(new Uri("../img/Premium.png", UriKind.Relative)); break; case "Средний": CarLevel.Source = new BitmapImage(new Uri("../img/Average.png", UriKind.Relative)); break; case "Эконом": CarLevel.Source = new BitmapImage(new Uri("../img/Econom.png", UriKind.Relative)); break; } CarName.Text = "Модель: " + car.CarName; CarNumber.Text = "Номер Машины: " + car.CarNumber; TripsYear.Text = "Год выпуска: " + car.YearOfIssue; int tripNumber = 0; using (TripContext tdb = new TripContext()) { tripNumber = tdb.Trips.Where(t => t.CarName == car.CarName).Count(); } TripsNumber.Text = "Кол-во поездок: " + tripNumber; CarStatus.Text = "Статус: " + car.State; switch (car.State) { case "Свободна": CarStatus.Foreground = Brushes.ForestGreen; break; case "Занята": CarStatus.Foreground = Brushes.DarkRed; break; } } else { this.Close(); } } }
public void UpdateTripsList() { TripsList.Children.Clear(); using (TripContext db = new TripContext()) { var Trips = db.Trips.OrderByDescending(t => t.Id); foreach (Trip t in Trips) { tripRow tr = new tripRow(t.Id, t.FromWhere, t.Destination, t.Name, t.Date, t.State); TripsList.Children.Add(tr); } } }
public override string[] GetRolesForUser(string username) { string[] roles = new string[] { }; using (TripContext db = new TripContext("TripContext")) { User user = db.Users.FirstOrDefault(u => u.Email == username); if (user != null) { roles = new string[] { user.Role }; } return(roles); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseSwagger(); if (env.IsDevelopment() || env.IsStaging()) { app.UseSwaggerUI(options => options.SwaggerEndpoint(Url, "Trip Tracker v1")); } if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); TripContext.SeedData(app.ApplicationServices); }
public static List <Trip> GetTrips() { List <Trip> trips = new List <Trip>(); using (var db = new TripContext()) { var collection = db.Trips.Include(t => t.Employee). Include(t => t.Vehicle); foreach (var item in collection) { trips.Add(item); } } return(trips); }
public TripContextSeedData(TripContext context, UserManager<TripUser> userManager) { _context = context; _userManager = userManager; }
public TripRepository(TripContext context, ILogger<TripRepository> logger) { _context = context; _logger = logger; }