예제 #1
0
        public void AddCarTest()
        {
            Car car = new Car();

            car.StateNumber  = "1234-AA7";
            car.Manufacturer = "Tesla";
            car.Model        = "X";
            car.Year         = 2017;
            car.Color        = "Black";
            string username = "******";

            using (ParkingDBContext context = contextFactory.CreateDbContext())
            {
                ApplicationUser entity = new ApplicationUser();
                entity.UserName = username;
                context.Users.Add(entity);
                context.SaveChanges();
            }

            CarManager carManager = new CarManager(contextFactory);
            Car        addedCar   = carManager.AddCar(car, username);

            Assert.NotNull(addedCar);
            Assert.Equal(car.StateNumber, addedCar.StateNumber);
        }
        public HttpResponseMessage AddCar([FromBody] CarModel carModel)
        {
            using (logic = new CarManager())
            {
                try
                {
                    //בדיקה האם הפרמטר שעבר לפונקציה בתור מודל עומד בדרישות הואלידציה
                    //BOהגדרות הואלידציה מוגדרות בתוך ה
                    //Data annotation בתור
                    if (!ModelState.IsValid)
                    {
                        string error = ModelState.Where(ms => ms.Value.Errors.Any()).Select(ms => ms.Value.Errors[0].ErrorMessage).FirstOrDefault();
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, error));
                    }

                    // הולידציה עברה בהצלחה
                    carModel = logic.AddCar(carModel);

                    return(Request.CreateResponse(HttpStatusCode.Created, carModel));
                }
                catch (Exception ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ExceptionHelper.GetInnerMessage(ex)));
                }
            }
        }
예제 #3
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtName.Text) || string.IsNullOrEmpty(txtPrice.Text) || string.IsNullOrEmpty(fuPic.FileName) || string.IsNullOrEmpty(ddlBrand.Text))
            {
                Response.Write("请输入完整信息!!");
                return;
            }
            try
            {
                string   path          = Server.MapPath("~/Images/");
                bool     isPic         = false;
                string   fileExtension = Path.GetExtension(fuPic.FileName);
                string[] exts          = { ".gif", ".png", ".jpg", ".bmp", ".jpeg" };
                foreach (string each in exts)
                {
                    if (fileExtension == each)
                    {
                        isPic = true;
                        break;
                    }
                }

                if (isPic)
                {
                    //判断图片是否在服务器中存在
                    if (!File.Exists(path + fuPic.FileName))
                    {
                        fuPic.PostedFile.SaveAs(path + fuPic.FileName);//文件另存服务器指定目录下

                        Car c = new Car();
                        c.CarBrand           = new Brand();
                        c.CarBrand.BrandId   = Convert.ToInt32(ddlBrand.SelectedValue);
                        c.CarBrand.BrandName = ddlBrand.SelectedItem.Text;
                        c.CarName            = txtName.Text;
                        c.OfficilPrice       = Convert.ToDecimal(txtPrice.Text);
                        c.Picture            = txtPrice.Text;
                        c.Picture            = fuPic.FileName;
                        c.Click = 1;
                        cm.AddCar(c);
                        lblInfo.Text = "实物图上传成功!,增加成功!!车型号是:" + c.CarId;
                    }
                    else
                    {
                        lblInfo.Text = "实物图已经存在!!";
                    }
                }
                else
                {
                    lblInfo.Text = "只能上传.gif、.png、.jpg、 .bmp、 .jpeg图像文件";
                }
            }
            catch (Exception ex)
            {
                lblInfo.Text = ex.Message;
            }
        }
예제 #4
0
        public IActionResult SaveCar(CarViewModel addCarViewModel)
        {
            Car car = new Car();

            car.Color        = addCarViewModel.Color;
            car.Manufacturer = addCarViewModel.Make;
            car.Model        = addCarViewModel.Model;
            car.StateNumber  = addCarViewModel.StateNumber;
            car.Year         = addCarViewModel.Year.Value;
            carManager.AddCar(car, User.Identity.Name);
            return(RedirectToAction("CarSettings"));
        }
예제 #5
0
    private void SpawnFreeCar(float carspeed, int carline, float dist, Type carType)
    {
        Vector3    spawnpos = spawnPoints[carline].position;
        GameObject go;

        spawnpos.z += dist;
        int id;

        if (carType == Type.empty)
        {
            go = Instantiate(empty, spawnpos, Quaternion.identity) as GameObject;
        }
        else if (carType == Type.lift || carType == Type.barrier)
        {
            if (carType == Type.barrier)
            {
                id = Random.Range(0, 2);
            }
            else
            {
                id = Random.Range(2, stuffPrefab.Length);
            }

            go = Instantiate(stuffPrefab[id], spawnpos, stuffPrefab[id].transform.rotation) as GameObject;
        }
        else if (carType == Type.moto)
        {
            id = Random.Range(0, motoPrefab.Length);

            go = Instantiate(motoPrefab[id], spawnpos, motoPrefab[id].transform.rotation) as GameObject;
        }
        else
        {
            if (carType == Type.car)
            {
                id = Random.Range(0, 6);
            }
            else if (carType == Type.big)
            {
                id = Random.Range(6, 11);
            }
            else
            {
                id = Random.Range(11, carPrefab.Length);
            }

            go = Instantiate(carPrefab[id], spawnpos, carPrefab[id].transform.rotation) as GameObject;
        }

        carManager.AddCar(go, new Vector3(0, 0, -carspeed));
        freeCars[carline].entity   = go;
        freeCars[carline].carspeed = speed;
    }
예제 #6
0
 public ActionResult <Car> Post([FromBody] Car value)
 {
     try
     {
         Car    newCar = _manager.AddCar(value);
         string uri    = Url.RouteUrl(RouteData.Values) + "/" + newCar.Id;
         return(Created(uri, newCar));
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(ex.Message));
     }
 }
예제 #7
0
    public void BeginSpawningDucks()
    {
        Vector3 pos = player.position;

        if (spawnDuck)
        {
            pos.y = 25;
        }
        else
        {
            pos.y = -6.7f;
        }

        float z = pos.z + 300;

        while (pos.z < z)
        {
            pos.z += Random.Range(5, 30);

            pos.x = Random.Range(-5, 5);

            if (spawnDuck)
            {
                lastSpawned = (GameObject.Instantiate(DuckPrefab, pos, DuckPrefab.transform.rotation) as GameObject).transform;
            }
            else
            {
                lastSpawned = (GameObject.Instantiate(SeaGullPrefab, pos, SeaGullPrefab.transform.rotation) as GameObject).transform;
            }

            duckManager.AddCar(lastSpawned.gameObject, new Vector3(0, 0, -duckSpeed));
        }

        thisTransform.position = pos;
        delayNextSpawn         = Random.Range(0, 20);
        canSpawn = true;
    }
예제 #8
0
        private bool tryPost(ref Model.Car model, out string errMsg)
        {
            errMsg = "";
            bool re = false;

            model.Creater      = this.auth.UserId;
            model.CreatedDate  = DateTime.Now;
            model.Modifier     = this.auth.UserId;
            model.ModifiedDate = DateTime.Now;
            if (CarManager.AddCar(ref model, out errMsg))
            {
                re = true;
            }
            return(re);
        }
예제 #9
0
        public void AddCarUsernameExceptionTest(string username)
        {
            Car car = new Car();

            try
            {
                CarManager carManager = new CarManager(contextFactory);
                Car        addedCar   = carManager.AddCar(car, username);
                Assert.NotNull(addedCar);
                Assert.Equal(car.StateNumber, addedCar.StateNumber);
            }
            catch (ArgumentNullException ex)
            {
                Assert.True(ex is ArgumentNullException);
            }
        }
        public HttpResponseMessage PostCars([FromBody] Car car)
        {
            CarModel u = new CarModel {
                CarNum      = car.CarNum,
                CarPic      = car.CarPic,
                CarTypeID   = car.CarTypeID,
                BarnchID    = car.BranchID,
                KM          = car.KM,
                IsAvailable = car.IsAvailable,
                IsFix       = car.IsFix,
            };


            var x = logic.AddCar(u);


            return(Request.CreateResponse(HttpStatusCode.OK, x));
        }
예제 #11
0
        public async Task <IActionResult> AddCar([FromForm] Car car)
        {
            await _carManager.AddCar(car);

            return(Ok());
        }
예제 #12
0
        //新增插入
        protected void dvCars_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            FileUpload fuPic = (FileUpload)dvCars.FindControl("fulAddPic");

            TextBox txtName = (TextBox)dvCars.FindControl("txtAddCarName");

            DropDownList ddlBrand = (DropDownList)dvCars.FindControl("ddlInsertBrand");

            TextBox txtPrice = (TextBox)dvCars.FindControl("txtAddPrice");

            bool isPic = false;

            string fileExtension = System.IO.Path.GetExtension(fuPic.FileName);

            string[] exts = { ".png", ".gif", ".jpg", ".bmp", ".jpeg" };
            foreach (string each in exts)
            {
                if (each == fileExtension)
                {
                    isPic = true;
                    break;
                }
            }

            if (isPic)
            {
                string path = Server.MapPath("~/Images/");
                if (!System.IO.File.Exists(path + fuPic.FileName))
                {
                    fuPic.PostedFile.SaveAs(path + fuPic.FileName);


                    try
                    {
                        Car c = new Car();
                        c.CarBrand           = new Brand();
                        c.CarBrand.BrandId   = Convert.ToInt32(ddlBrand.SelectedValue);
                        c.CarBrand.BrandName = ddlBrand.SelectedItem.Text;
                        c.CarId        = Convert.ToInt32(dvCars.DataKey.Value);
                        c.CarName      = txtName.Text;
                        c.OfficilPrice = Convert.ToDecimal(txtPrice.Text);
                        c.Picture      = fuPic.FileName;

                        cm.AddCar(c);

                        dvCars.ChangeMode(DetailsViewMode.ReadOnly);//切状态
                        bindCarId(c.CarId);
                    }
                    catch (Exception ex)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + ex.Message + "')", true);
                    }
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "alert('添加失败,实物图已存在!!')", true);
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "alert('只能上传gif、png、gif、bmp和jpeg的图片!!')", true);
            }
        }
        public void TestItAll()
        {
            CarManager manager = new CarManager(_context);
            List <Car> allCars = manager.GetAllCars().ToList();

            string chars       = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string numbers     = "0123456789";
            var    stringChars = new char[7];
            var    random      = new Random();

            for (int i = 0; i < 2; i++)
            {
                stringChars[i] = chars[random.Next(chars.Length)];
            }
            for (int i = 2; i < 7; i++)
            {
                stringChars[i] = numbers[random.Next(numbers.Length)];
            }

            string licensePlateString = new String(stringChars);

            // Add
            Car data = new Car {
                Color = "Red", LicensePlate = licensePlateString
            };
            Car newCar = manager.AddCar(data);

            Assert.IsTrue(newCar.Id > 0);
            Assert.AreEqual(data.Color, newCar.Color);
            Assert.AreEqual(data.LicensePlate, newCar.LicensePlate);

            //Car nullModelData = new Car();
            //Assert.ThrowsException<CarException>(() => manager.AddCar(nullModelData));

            // GetById
            Car carById = manager.GetCarById(newCar.Id);

            Assert.AreEqual(newCar.Id, carById.Id);
            Assert.AreEqual(newCar.Color, carById.Color);
            Assert.AreEqual(newCar.LicensePlate, carById.LicensePlate);

            Assert.IsNull(manager.GetCarById(newCar.Id + 1));

            // Update
            Car updates = new Car {
                Color = "Volvo"
            };
            int id         = newCar.Id;
            Car updatedCar = manager.UpdateCar(id, updates);

            Assert.AreEqual(id, updatedCar.Id);
            Assert.AreEqual(updates.Color, updatedCar.Color);

            Assert.IsNull(manager.UpdateCar(id + 1, updates));
            //Assert.ThrowsException<CarException>(() => manager.UpdateCar(id, nullModelData));

            //Color test
            Assert.AreEqual(0, manager.ColorOfCars("FarveSomIkkeFindes"));
            Assert.AreEqual(3, manager.ColorOfCars("Dark-Slate-Gray"));

            /*
             * //Delete all
             * foreach(var d in manager.GetAllCars().ToList())
             * {
             *  manager.DeleteCar(d.Id);
             * }*/
        }
예제 #14
0
    public IEnumerator SpawnTrafficLight()
    {
        canSpawn = false;
        int curn;
        int i;
        int spSeqId = 2; //скопление машин на светофоре
        int id      = Random.Range(0, spawnSeq[spSeqId].count);

        GameObject go = Instantiate(TrafficLight, spawnPoints[1].position, TrafficLight.transform.rotation) as GameObject;

        go.tag = "Car";
        manager.AddCar(go, Vector3.zero);

        for (curn = 0; curn < spawnPoints.Count; curn++)
        {
            for (i = 0; i < spawnSeq[spSeqId].spawnData[id].lineData[curn].count; i++)
            {
                SpawnCar(
                    spawnSeq[spSeqId].spawnData[id].lineData[curn].carData[i].carspeed,
                    curn,
                    spawnSeq[spSeqId].spawnData[id].lineData[curn].carData[i].dist,
                    spawnSeq[spSeqId].spawnData[id].lineData[curn].carData[i].type,
                    spawnSeq[spSeqId].spawnData[id].lineData[curn].carData[i].bonusId);
            }
        }

        for (curn = 0; curn < spawnPoints.Count; curn++)
        {
            spawnedCar[curn].velocity = new Vector3(0, 0, -speed);
        }

        yield return(new WaitForSeconds(spawnSeq[spSeqId].spawnData[id].time));

        canSpawn = true;
    }
예제 #15
0
 /// <summary>
 /// Adicinar al carrito
 /// </summary>
 /// <param name="car"></param>
 /// <returns></returns>
 public RequestResponse <int> AddCar(Car car)
 {
     return(manager.AddCar(car));
 }
예제 #16
0
 public void AddCarToDB([FromBody] Car car)
 {
     _repo.AddCar(car);
 }