// PUT api/CarsAPI/5 public HttpResponseMessage PutCars(int id, Cars cars) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != cars.Id_Cars) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(cars).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
public void TestMethod1() { var carFactory = new CarFactory(); var carsArray = new Cars(new ICar[] { carFactory.GetProduct("Audi"), carFactory.GetProduct("Mercedes"), carFactory.GetProduct("BMW"), carFactory.GetProduct("Audi"), }); int[] intArray ={ 1, 2, 3, 4, 5 }; /* Array myArray2 = Array.CreateInstance() IList list = myArray2;*/ List<string> list = new List<string>(5); LinkedList<int> acs = new LinkedList<int>(); // LinkedL // //This throws Exception // list.Add(5); foreach (ICar car in carsArray) { var value = car.Desc(); } }
//------------------------------------------------------------------ public Police(Cars.Car car) : base(car) { Velocity = 400; ChangeLaneSpeed = 2; AddInLoop (new Shrink (this)); AddInLoop (new Overtake (this, Car.Lane.Road.Player)); AddInLoop (new Block (this, Car.Lane.Road.Player)); }
// Constructor public MainPage() { InitializeComponent(); cars = new Cars(); carsList.ItemsSource = cars; // Sample code to localize the ApplicationBar //BuildLocalizedApplicationBar(); }
// POST api/CarsAPI public HttpResponseMessage PostCars(Cars cars) { if (ModelState.IsValid) { db.Cars.Add(cars); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, cars); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = cars.Id_Cars })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
public static Car Create(Cars car) { switch (car) { case Cars.BMW: return new BMW(); case Cars.Ferrari: return new Ferrari(); case Cars.Toyota: return new Toyota(); case Cars.Chevrolet: return new Chevrolet(); } return null; }
public JsonResult UpdateCar(Cars car) { var result = false; { try { Cars carObj = db.Cars.Where(x => x.Id == car.Id).Single(); carObj.Model = car.Model; carObj.Name = car.Name; carObj.Capability = car.Capability; db.SaveChanges(); result = true; } catch (Exception ex) { throw ex; } return(Json(result, JsonRequestBehavior.AllowGet)); } }
public void Register(int id, string type, string brand, string model, int yearOfProduction, int horsepower, int acceleration, int suspension, int durability) { Car car = null; switch (type) { case "Performance": car = new PerformanceCar(brand, model, yearOfProduction, horsepower, acceleration, suspension, durability); break; case "Show": car = new ShowCar(brand, model, yearOfProduction, horsepower, acceleration, suspension, durability); break; } if (!Cars.ContainsKey(id)) { Cars.Add(id, car); } }
public async Task <IActionResult> InsertInRelationshipAsync() { var CarID = new HelperMongo().Random(); var dt = new Cars { CarID = CarID, Brand = 3, Model = "2012", Price = 12, Year = 2021, ImageUrl = "deneme.jpg", Comment = new List <Comment> { new Comment { CommentID = new HelperMongo().Random(), CarID = CarID, Name = "Eyüp 2", Message = "Test Mesajı 1" }, new Comment { CommentID = new HelperMongo().Random(), CarID = CarID, Name = "Ensar 2", Message = "Test Mesajı 2" } } }; var result = await _carService.AddOneAsync(dt); return(View()); }
public override void AddCar(Car car) { bool check = Validity.Equals("Valid"); if (Cars.Count != MaxParticipant) { if (car.Validity == check) { Cars.Add(car); } else { throw new InvalidCar("This car doesn't meet with the requirments! - The car's validity is Valid!"); } } else { throw new InvalidCar("You can't add this car to the race because it's full!"); } }
private void SwitchTwoCars() { int carId_1 = Cars.GetRandomCar().Id; int carId_2 = Cars.GetRandomCar().Id; if (carId_2 != carId_1) { SwitchTwoCars(carId_1, carId_2); double tonnage_1 = Cars.GetCar(carId_1).Tonnage; double tonnage_2 = Cars.GetCar(carId_2).Tonnage; int smallerTonnageId; double smallerTonnage; if (tonnage_1 == tonnage_2) { return; } else if (tonnage_1 < tonnage_2) { smallerTonnageId = carId_1; smallerTonnage = tonnage_1; } else { smallerTonnageId = carId_2; smallerTonnage = tonnage_2; } if (!distribution.ContainsKey(smallerTonnageId)) { return; } foreach (var unitPair in this.distribution[smallerTonnageId]) { if (smallerTonnage < unitPair.Weight) { SwitchTwoCars(carId_1, carId_2); return; } } } }
void Start_Scenario() { Close_Everything(); // Restarts Everything // Set Player running true Player.Instance.SetRunning(true); // Inıtilize the current variables current_entrance = Entrences[current_scenario]; current_exit = Exits[current_scenario]; current_car = Cars[current_scenario]; // Activates start and end points current_entrance.SetActive(true); current_exit.SetActive(true); // Activates the current car and spawn in start point current_car.transform.position = current_entrance.transform.position; current_car.transform.rotation = current_entrance.transform.rotation; current_car.SetActive(true); current_cars_script = current_car.GetComponent <Cars>(); // Moves the camera to car virtualCamera.Follow = current_car.transform; virtualCamera.LookAt = current_car.transform; // Activates NPC cars int it = current_scenario; while (it > 0) { it -= 1; Cars[it].transform.position = Entrences[it].transform.position; Cars[it].SetActive(true); Cars[it].GetComponent <Cars>().ResetSavedTime(); } // Starts countdown timer episode_Timer.ResetTimer(); count_Down_Controller.StartCountDownTimer(); }
public override void Load() { Cars.Clear(); try { string carsOutput = File.ReadAllText(@"./Cars.xml"); XElement carsXElement = XElement.Parse(carsOutput); foreach (var item in carsXElement.Descendants("car")) { int tempParkingSpot = int.Parse(item.Element("parkingSpot").Value); string tempCarNumber = item.Element("carNumber").Value; string tempDriverName = item.Element("driverName").Value; string tempPhoneNumber = item.Element("phoneNumber").Value; DateTime tempParkingTime = item.Element("parkingTime").Value == "" ? DateTime.Now : DateTime.Parse(item.Element("parkingTime").Value); ParkingCar tempCar = new ParkingCar() { parkingSpot = tempParkingSpot, carNumber = tempCarNumber, driverName = tempDriverName, phoneNumber = tempPhoneNumber, parkingTime = tempParkingTime }; Cars.Add(tempCar); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); dataSource.PrintLog(ex.Message); dataSource.PrintLog(ex.StackTrace); //만약 파일이 없어서 여기로 진입한 경우라면 CreateFile(); //파일을 다시 만들고 Save(null); //그 파일을 저장한 다음 Load(); //다시 불러들여본다. //단, Load 함수 자체가 잘못된거라면 이 코드는 무한루프에 빠진다. } }
public ActionResult Edit(int?ID, Cars c) { using (var ctx = new Context()) { Users tmp = (Users)Session["user"]; Users usr = ctx.Users.Where(x => x.ID == tmp.ID).FirstOrDefault(); Cars car = ctx.Cars.Where(x => x.ID == ID).FirstOrDefault(); car.State = c.State; car.Type = c.Type; car.Damaged = c.Damaged; car.ProdDate = c.ProdDate; car.Fuel = c.Fuel; car.Gearbox = c.Gearbox; car.Mileage = c.Mileage; car.Drive = c.Drive; car.Engine = c.Engine; car.bHP = c.bHP; car.Price_ = c.Price_; car.Negotiable = c.Negotiable; car.Registered = c.Registered; car.Netto = c.Netto; car.VAT = c.VAT; car.Leasing = c.Leasing; car.OC = c.OC; car.Color = c.Color; car.Country = c.Country; car.FirstOwner = c.FirstOwner; car.NoAcc = c.NoAcc; car.ASO = c.ASO; car.Desc = c.Desc; car.City = c.City; car.PostCode = c.PostCode; car.Phone = c.Phone; ctx.SaveChanges(); } return(RedirectToAction("Index", "Car", new { ID = ID })); }
public void GetCars() { List <Cars> listCars = new List <Cars>(); JavaScriptSerializer js = new JavaScriptSerializer(); using (SqlConnection con = new SqlConnection(Connection.GetConnection)) { Cars cars = new Cars(); Connection.openConection(con); SqlCommand cmd = new SqlCommand("sp_GetAllCars", con); cmd.CommandType = CommandType.StoredProcedure; SqlDataReader data = cmd.ExecuteReader(); while (data.Read()) { cars = new Cars() { ID = Convert.ToInt32(data["ID"]), CAR_Brand = data["CAR_Brand"].ToString(), CAR_No = data["CAR_No"].ToString(), CAR_Type = data["CAR_Type"].ToString(), CAR_Status = data["CAR_Status"].ToString(), Category_Type = data["Category_Type"].ToString(), CAR_Model = data["CAR_Model"].ToString(), Check_Status = data["Check_Status"].ToString(), Colors = data["Colors"].ToString(), Car_Size = data["Car_Size"].ToString(), CAR_Photo = data["CAR_Photo"].ToString(), Check_Photo = data["Check_Photo"].ToString(), City = data["City"].ToString(), Pay_Type = data["Pay_Type"].ToString(), Location = data["Location"].ToString(), Notes = data["Notes"].ToString(), CAR_Price = Convert.ToDecimal(data["CAR_Price"]), Check_Date = data["Check_Date"].ToString() }; listCars.Add(cars); } } Context.Response.Write(js.Serialize(listCars)); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Cars).State = EntityState.Modified; var ModelId = Cars.CarsModelId; var cid = Cars.Id; var ModelName = _context.CarsModel.FindAsync(ModelId).Result; Cars = _context.Cars.FindAsync(cid).Result; if (FileUpload == null && MultipleFileUpload.Count == 0) { Cars.DisplayFileName = Cars.DisplayFileName; Cars.FolderName = Cars.FolderName; Cars.ArrayFileName = Cars.ArrayFileName; Cars.ThumbFolderName = Cars.ThumbFolderName; //_context.Remove(Cars.ThumbFolderName).State = EntityState.Detached; //_context.Remove(Cars.FolderName).State = EntityState.Detached; //_context.Remove(Cars.ArrayFileName).State = EntityState.Detached; //_context.Remove(Cars.DisplayFileName).State = EntityState.Detached; } try // process properties or fields changes to database { Cars.ModelName = ModelName.Name; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { ModelState.AddModelError("", "Unable to save changes.Try again, and if the problem persists, see your system administrator."); } return(RedirectToPage("./Index")); }
private void UpdateThat() { int MadeID = db.Mades.FirstOrDefault(c => c.Made == comboBox1.Text).Id; Cars updateme = db.Cars.Find(UpdateDelete); updateme.Made = MadeID; updateme.Make = txtMake.Text; updateme.Year = Convert.ToInt32(txtYear.Text); updateme.FuelCons = Convert.ToInt32(txtFuelC.Text); updateme.Price = Convert.ToInt32(txtPrice.Text); db.SaveChanges(); carDGV.Rows.Clear(); fillDGV(); //txtName.Clear(); //txtDrivingLicence.Clear(); //txtIdentity.Clear(); //txtAge.Clear(); ClearUpDel(); }
public void LeaveParking(int slot) { if (RegistrationToParkingLotMapping.ContainsValue(slot)) { var registrationNumber = RegistrationToParkingLotMapping.FirstOrDefault(f => f.Value == slot).Key; if (RegistrationToParkingLotMapping.ContainsKey(registrationNumber)) { RegistrationToParkingLotMapping.Remove(registrationNumber); } if (Cars.ContainsKey(registrationNumber)) { var car = Cars[registrationNumber]; Cars.Remove(registrationNumber); ColorToRegistrationsMapping[car.Color.ToLower()].Remove(car.RegistrationNumber); } } UpdateEmptyLot(slot); }
public bool DeleteRecord(Cars auto) { bool result = true; Connect(); try { SqlCommand cmd = new SqlCommand("DELETE FROM Cargo WHERE Id = @id", sqlConnection); cmd.Parameters.Add(new SqlParameter("@id", auto.ID)); cmd.ExecuteNonQuery(); } catch (Exception) { result = false; } finally { Disconnect(); } return(result); }
public async Task <IActionResult> ChangeCars(int id, string make, string model, string color, int year) { List <Cars> cars = await CD.GetCars(); Cars found = _context.Cars.Find(id); if (found != null) { found.Make = make; found.Model = model; found.Year = year; found.Color = color; _context.Entry(found).State = EntityState.Modified; _context.Update(found); await _context.SaveChangesAsync(); CD.UpdateCar(id, found); } return(RedirectToAction("Index", cars)); }
public void AddCar(SupplierNew s) { using (RatesDBContext ctx = new RatesDBContext()) { Cars c = ctx.Cars.FirstOrDefault(o => o.CarName.Contains(s.CarName)); if (c == null) { ctx.Cars.Add(new Cars { CarName = s.CarName, Category = s.Category.Contains("skip") ? s.Category.Substring(4) : s.Category, Seats = s.Seats, Transmission = s.Transmission, SupplierName = s.SupplierName, SupplierType = s.SupplierType, IsAssigned = true }); ctx.SaveChanges(); } } }
//баланс авто public void ShowCarBalance() { Console.Clear(); Console.WriteLine("Який номер вашого авто [1,2,3...]?"); try { Guid userInput = Guid.Parse(Console.ReadLine()); Car _Car = Cars.Find(x => x.ID == userInput); Console.Clear(); Console.WriteLine("Баланс Вашого авто {0} грн. ", _Car.Balance.ToString()); } catch { Console.WriteLine("На жаль, таке авто у нас не припарковане"); Console.WriteLine("Натисніть будь-яку клавішу..."); Console.ReadLine(); } }
public void Add(Cars car) { if (car.BrandName.Length >= 2) { if (car.DailyPrice > 0) { _carDal.Add(car); Console.WriteLine("{0} added.", car.BrandName); } else { Console.WriteLine("Daily price should be bigger than 0"); } } else { Console.WriteLine("Car name should be longer than 1"); } }
static void Main(string[] args) { CosmosDBHelper dbHelper = new CosmosDBHelper(documentUri, documentKey, "ecar", "cars"); var car = new Cars() { Name = "Polo", Category = "Volkswogan", Fuel = "Diesel", Price = 1200000 }; //var response = dbHelper.InsertDocumentAsync(car).GetAwaiter().GetResult(); Console.WriteLine("Hello World!"); var carcoll = dbHelper.GetCars(); foreach (var c in carcoll) { Console.WriteLine("{0,-20} {1,-10} {2,-10} {3,-10}", c.Name, c.Price, c.Category, c.Fuel); } Console.ReadLine(); }
public void RemoveCar(int carId) { var car = Cars.FirstOrDefault(x => x.Id == carId); if (car == null) { throw new InvalidIdException($"Invalid Id {carId}. No cars with such Id found."); } if (car.Balance < 0) { throw new NegativeBalanceException( $"Can't remove car with id {carId}, it has negative balance: {car.Balance}."); } Cars.Remove(car); if (CarRemoved != null) { CarRemoved(this, new ParkingEventArgs("been removed", car)); } }
public async Task <ActionResult <Cars> > PostCars(Cars cars) { _context.Cars.Add(cars); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (CarsExists(cars.PlateNumber)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetCars", new { id = cars.PlateNumber }, cars)); }
public void OnCarChange() { Range.SetActive(false); if (_instantiateCar != null) { Destroy(_instantiateCar); } Debug.Log($"{Dropdown.value}"); for (int i = 0; i < _loadedCarsObjectArr.Length; i++) { Cars Car = new Cars(); Car.SetIdAndName(_loadedCarsObjectArr[i].name); Debug.Log($"ID -- {Car.ID}, Name -- {Car.Name}"); if (Dropdown.value == Car.ID) { _instantiateCar = Instantiate(_loadedCarsObjectArr[i], Parent.transform); return; } } }
public CarsViewModel() { if (IsInDesignMode) { } else { // INIT this.cars = new ObservableCollection <Car>(); this.selectedCar = null; // FAKE DATA for (int i = 1; i <= 10; i++) { Car newCar = new Car { Id = i, Company = "Company_" + i, Name = "Name_" + i, Year = "200" + i }; Cars.Add(newCar); } } }
public IActionResult Post([FromBody] Cars car) { if (car.Id == Guid.Empty) { car.Id = Guid.NewGuid(); return(new ObjectResult(_repository.AddEntity <Cars>(car))); } else { var existingOne = _repository.GetEntity <Cars>(car.Id); existingOne.Brand = car.Brand; existingOne.Model = car.Model; existingOne.Year = car.Year; existingOne.Price = car.Price; existingOne.New = car.New; _repository.UpdateEntity <Cars>(existingOne); return(new ObjectResult(existingOne)); } }
protected override void Load() { Reservations.Clear(); Customers.Clear(); Cars.Clear(); foreach (CustomerDto Customer in Service.Customers) { Customers.Add(Customer); } foreach (CarDto Car in Service.Cars) { Cars.Add(Car); } foreach (ReservationDto reservation in Service.Reservations) { Reservations.Add(reservation); } SelectedReservation = Reservations.FirstOrDefault(); }
private void OnFindCar() { Cars.Clear(); Cars = new ObservableCollection <CarModel>(baseConverter.GetCars()); var count = Cars.Where(x => x.Name.Contains(_findCarText) || x.BrandCar.Contains(_findCarText) || x.FuelCar.Contains(_findCarText) || x.Capacity.ToString().Contains(_findCarText) || x.DateRelease.ToString().Contains(_findCarText) || x.TypeCar.Contains(_findCarText) || x.Available.Contains(_findCarText)).Count(); if (count != 0) { Cars = new ObservableCollection <CarModel>(Cars.Where(x => x.Name.Contains(_findCarText) || x.BrandCar.Contains(_findCarText) || x.FuelCar.Contains(_findCarText) || x.Capacity.ToString().Contains(_findCarText) || x.DateRelease.ToString().Contains(_findCarText) || x.TypeCar.Contains(_findCarText) || x.Available.Contains(_findCarText))); } else { Cars.Clear(); } OnPropertyChanged(nameof(Cars)); }
public async Task <IActionResult> DeleteConfirmed(int id) { //new IQueryable <Contracts> contracts = from o in _context.Contracts where o.CarId == id select o; Cars cars = _context.Cars.Find(id); foreach (Contracts contracts1 in contracts) { _context.Contracts.Remove(contracts1); } _context.Cars.Remove(cars); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); //new /*var cars = await _context.Cars.FindAsync(id); * _context.Cars.Remove(cars); * await _context.SaveChangesAsync(); * return RedirectToAction(nameof(Index));*/ }
public ActionResult Create(Cars cars) { if (ModelState.IsValid) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/App_Data/Images/"), fileName); file.SaveAs(path); cars.Photo = path; } db.Cars.Add(cars); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CarTypeId = new SelectList(db.CarType, "Id", "Type", cars.CarTypeId); return(View(cars)); }
public IResult Add(Cars cars) { if (cars.Description.Length > 2 && cars.DailyPrice > 0) { _carDal.Add(cars); } else if (cars.Description.Length < 2) { Console.WriteLine("Açıklama en az 2 karakter olmalıdır!!!"); } else if (cars.DailyPrice < 0) { Console.WriteLine("Arabanın günlük fiyatı 0'dan büyük olmalıdır!!!"); } else if (cars.Description.Length < 2 && cars.DailyPrice < 0) { Console.WriteLine("Açıklama en az 2 karakter olmalıdır ve arabanın günlük fiyatı 0'dan büyük olmalıdır!!!"); } return(new SuccessResult(SuccessMessages.CarDeleted)); }
public List <Car> GetCars() { Car car = null; Cars.Clear(); using (Stream stream = new System.IO.FileStream(filePath, FileMode.Open)) { using (xmlStreamReader = new XmlStreamReader(stream)) { while (xmlStreamReader.Read()) { car = xmlStreamReader.Deserialize(); if (car != null) { Cars.Add(car); } } } } return(Cars); }
//---- public int AddCar(ICar car) { if (Cars.Count != Settings.ParkingSpace) { if (Cars.Count > 0) { car.Id = Cars.FindLast(c => c is ICar).Id + 1; } else { car.Id = 1; } Cars.Add(car); return(car.Id); } else { throw new NotEnoughParkingSpaceException("Not enough parking space!"); } }
// Use this for initialization void Start() { int selectedcar; if (PlayerPrefs.HasKey("selectedcar")) { selectedcar = PlayerPrefs.GetInt("selectedcar"); PlayerPrefs.DeleteKey("selectedcar"); } else { selectedcar = -1; } for (int i = 0; i < carobjects.Count; i++) { Cars temp = new Cars(); temp.obj = carobjects[i]; temp.rigid = carobjects[i].GetComponent<Rigidbody>(); temp.vars = carobjects[i].GetComponent<GoForward>(); cars.Add(temp); if (selectedcar != -1) { if (i == selectedcar) { cam.GetComponent<CarCam>().carObject = temp.obj; cam.GetComponent<CarCam>().car = carobjects[i].GetComponent<Transform>(); cam.GetComponent<CarCam>().carBody = temp.rigid; carobjects[i].GetComponent<AudioListener>().enabled = true; temp.vars.navGroup = navigationGroups[0]; temp.vars.isAI = false; } else { temp.vars.isAI = true; carobjects[i].GetComponent<AudioListener>().enabled = false; } } temp.vars.CStart(); //initalize the objects from here } for (int i = 0; i < navigationGroups.Length;i++ ) //hide the nav arrays { int rep = navigationGroups[i].transform.childCount; for (int ii = 0; ii < rep; ii++) { navigationGroups[i].transform.GetChild(ii).GetComponent<MeshRenderer>().enabled = false; } } Physics.gravity = new Vector3(0F, -5F, 0F); vicscr = GetComponent<Victory_screen>(); }