Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <ModelCar> > PostModelCar(ModelCar modelCar)
        {
            _context.ModelCar.Add(modelCar);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetModelCar", new { id = modelCar.Id }, modelCar));
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
 public Location(int id, DateTime date, double price, Cliente cliente, ModelCar car)
 {
     Id      = id;
     Date    = date;
     Price   = price;
     Cliente = cliente;
     Car     = car;
 }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        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));
        }
Ejemplo n.º 8
0
        public IHttpActionResult GetModelCar(int id)
        {
            ModelCar modelCar = db.ModelCar.Find(id);

            if (modelCar == null)
            {
                return(NotFound());
            }

            return(Ok(modelCar));
        }
Ejemplo n.º 9
0
        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)));
        }
Ejemplo n.º 11
0
        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));
        }
Ejemplo n.º 12
0
        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);
            }
        }
Ejemplo n.º 13
0
        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));
        }
Ejemplo n.º 14
0
        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));
        }
Ejemplo n.º 15
0
    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);
    }
Ejemplo n.º 16
0
        public ActionResult Details(int ModelCarId)
        {
            ModelCar modelCar = db.ModelCars.Where(m => m.ModelCarId == ModelCarId).FirstOrDefault();

            return(View(modelCar));
        }