public void Insert(ModelCar car) { NpgsqlCommand cmd = new NpgsqlCommand(); Conexao con = new Conexao(); cmd.CommandText = "insert into tb_model_car (brand, model, type, board, color, avable) " + "values (@brand, @model, @type, @board, @color, @avable)"; cmd.Parameters.AddWithValue("@brand", car.Brand); cmd.Parameters.AddWithValue("@model", car.Model); cmd.Parameters.AddWithValue("@type", car.Type); cmd.Parameters.AddWithValue("@board", car.Board); cmd.Parameters.AddWithValue("@color", car.Color); cmd.Parameters.AddWithValue("@avable", car.Avable); try { cmd.Connection = con.openConnect(); cmd.ExecuteNonQuery(); MessageBox.Show("Successfully inserted"); } catch (NpgsqlException ex) { if (ex.Message.Contains("duplicate key")) { MessageBox.Show("Placa já registrada", "Ateção!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show(ex.Message, "Ateção!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } finally { con.closeConnect(); } }
public async Task <ActionResult <ModelCar> > PostModelCar(ModelCar modelCar) { _context.ModelCar.Add(modelCar); await _context.SaveChangesAsync(); return(CreatedAtAction("GetModelCar", new { id = modelCar.Id }, modelCar)); }
public async Task <IActionResult> PutModelCar(int id, ModelCar modelCar) { if (id != modelCar.Id) { return(BadRequest()); } this.db.Entry(modelCar).State = EntityState.Modified; try { await this.db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!await ModelCarExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PutModelCar(int id, ModelCar modelCar) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != modelCar.id) { return(BadRequest()); } db.Entry(modelCar).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ModelCarExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public Location(int id, DateTime date, double price, Cliente cliente, ModelCar car) { Id = id; Date = date; Price = price; Cliente = cliente; Car = car; }
public ActionResult Edit(string urlPrevious, int ModelCarId, string ModelCarName, int BrandId) { ModelCar modelCar = db.ModelCars.Where(m => m.ModelCarId == ModelCarId).FirstOrDefault(); modelCar.ModelCarName = ModelCarName; modelCar.BrandId = BrandId; modelCar.UpdatedDate = DateTime.Now; db.SaveChanges(); return(Redirect(urlPrevious)); }
public ActionResult Edit(int ModelCarId) { List <Brand> list = db.Brands.ToList(); SelectList listBrand = new SelectList(list, "BrandId", "BrandName"); ViewBag.CategoryList = listBrand; ModelCar modelCar = db.ModelCars.Where(m => m.ModelCarId == ModelCarId).FirstOrDefault(); ViewBag.urlPrevious = Request.UrlReferrer.ToString(); return(View(modelCar)); }
public IHttpActionResult GetModelCar(int id) { ModelCar modelCar = db.ModelCar.Find(id); if (modelCar == null) { return(NotFound()); } return(Ok(modelCar)); }
public IHttpActionResult PostModelCar(ModelCar modelCar) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.ModelCar.Add(modelCar); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = modelCar.id }, modelCar)); }
public IActionResult Get(string makename, string modelname) { ModelCar model = _modelRepo.GetModelByName(modelname); if (model == null) { return(NotFound()); } if (model.Make.Name != makename) { return(BadRequest("there is no model for this make")); } return(Ok(_mapper.Map <ModelCarViewModel>(model))); }
public IHttpActionResult DeleteModelCar(int id) { ModelCar modelCar = db.ModelCar.Find(id); if (modelCar == null) { return(NotFound()); } db.ModelCar.Remove(modelCar); db.SaveChanges(); return(Ok(modelCar)); }
public void insert(TextBox brand, TextBox model, ComboBox type, MaskedTextBox board, ComboBox color) { ModelCarDAO daoCar = new ModelCarDAO(); ModelCar car = new ModelCar(brand, model, type, board, color); if (car.Board == " -" || car.Model == "" || car.Brand == "" || car.Color == "") { MessageBox.Show("Favor preencher todos os campos!!", "Atenção!!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { daoCar.Insert(car); } }
public ActionResult CarDetails(string ModelNumberCar) { Car carByNumber = db.Cars.Where(c => c.ModelNumberCar == ModelNumberCar).FirstOrDefault(); PurchaseOrder purchaseOrderById = db.PurchaseOrders.Where(po => po.Id == carByNumber.Id).FirstOrDefault(); ModelCar modelCarById = db.ModelCars.Where(mc => mc.ModelCarId == purchaseOrderById.ModelCarId).FirstOrDefault(); Brand brandById = db.Brands.Where(b => b.BrandId == modelCarById.BrandId).FirstOrDefault(); List <Image> listImages = db.Images.Where(i => i.CarId == carByNumber.CarId).ToList(); DateTime date = (DateTime)carByNumber.CreatedDate; ViewBag.CreatedDate = date.ToString("MM-dd-yyyy"); ViewBag.Images = listImages; ViewBag.ModelCars = modelCarById.ModelCarName; ViewBag.Brands = brandById.BrandName; return(View(carByNumber)); }
public JsonResult Delete(int ModelCarId) { bool check = false; bool checkExistedPurchaseOrder = db.PurchaseOrders.Any(p => p.ModelCarId == ModelCarId); if (!checkExistedPurchaseOrder) { ModelCar modelCar = db.ModelCars.Where(m => m.ModelCarId == ModelCarId).FirstOrDefault(); db.ModelCars.Remove(modelCar); int d = db.SaveChanges(); if (d > 0) { check = true; } } return(Json(check)); }
public static ModelCar GetCarModelById(int id) { ModelCar result = null; string key = KEY_CARPREFIX + id; if (PlayerPrefs.HasKey(key)) { string json = PlayerPrefs.GetString(key); result = JsonUtility.FromJson <ModelCar>(json); } if (result == null) { result = new ModelCar(); result.Id = id; } return(result); }
public ActionResult Details(int ModelCarId) { ModelCar modelCar = db.ModelCars.Where(m => m.ModelCarId == ModelCarId).FirstOrDefault(); return(View(modelCar)); }