コード例 #1
0
        public async Task <IActionResult> PutCheckListRef([FromRoute] int id, [FromBody] CheckListRef checkListRef)
        {
            Blockage blockage = new Blockage();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != checkListRef.Id)
            {
                return(BadRequest());
            }

            _context.Entry(checkListRef).State = EntityState.Modified;


            blockage.IdVehicule   = checkListRef.IdVehicule;
            blockage.DateBlockage = checkListRef.Date.Value.Date;
            blockage.IdCheckList  = checkListRef.IdCheckListRef;

            if (!(bool)checkListRef.Etat)
            {
                // _context.Entry(blockage).State = EntityState.Modified;
                var blockageUpdated = await _context.Blockage.FirstOrDefaultAsync(x => x.IdCheckList == blockage.IdCheckList);

                if (blockageUpdated != null)
                {
                    blockageUpdated.DateDeblockage = DateTime.Now.Date;
                    // blockageUpdated = blockage;
                    System.Diagnostics.Debug.WriteLine("Updated: " + blockageUpdated.IdCheckList + ", " + blockageUpdated.Id);
                }
            }
            else
            {
                if ((bool)checkListRef.Etat)
                {
                    _context.Blockage.Add(blockage);
                }
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CheckListRefExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Blockage") && isAlive)
     {
         blockage = other.GetComponent <Blockage>();
         enemy    = blockage.enemy;
     }
 }
コード例 #3
0
        public async Task <IActionResult> PutBlockage([FromRoute] int id, [FromBody] Blockage blockage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != blockage.Id)
            {
                return(BadRequest());
            }

            _context.Entry(blockage).State = EntityState.Modified;

            if (blockage.ImageUrl.Contains("Upload"))
            {
                System.Diagnostics.Debug.WriteLine(blockage.ImageUrl);
            }
            else
            {
                if (blockage.ImageUrl != "")
                {
                    System.Diagnostics.Debug.WriteLine("Base64");
                    var imagePath = ConvertImage(blockage.ImageUrl);
                    blockage.ImageUrl = imagePath;
                }
                else
                {
                    blockage.ImageUrl = (string)null;
                }
            }


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BlockageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #4
0
        public void BlockedThree()
        {
            const string fen = "5k2/8/8/p1p1pPp1/P1P1P1P1/8/8/4K3 w - - 0 1";

            const bool expected = true;

            var g = GameFactory.Create();

            g.NewGame(fen);
            var pos = g.Pos;

            var blockage = new Blockage(pos);

            var actual = blockage.IsBlocked();

            Assert.Equal(expected, actual);
        }
コード例 #5
0
        public void BlockedTwo()
        {
            const string fen = "4k3/5p2/1p1p1P1p/1P1P1P1P/3P4/8/4K3/8 w - - 0 1";

            const bool expected = true;

            var g = GameFactory.Create();

            g.NewGame(fen);
            var pos = g.Pos;

            var blockage = new Blockage(pos);

            var actual = blockage.IsBlocked();

            Assert.Equal(expected, actual);
        }
コード例 #6
0
        public void OpenThree()
        {
            const string fen = "8/2p5/kp2p1p1/p1p1P1P1/P1P2P2/1P4K1/8/8 w - - 0 1";

            const bool expected = false;

            var g = GameFactory.Create();

            g.NewGame(fen);
            var pos = g.Pos;

            var blockage = new Blockage(pos);

            var actual = blockage.IsBlocked();

            Assert.Equal(expected, actual);
        }
コード例 #7
0
        public async Task <IActionResult> PostBlockage([FromBody] Blockage blockage)
        {
            /*if (!ModelState.IsValid)
             * {
             *  return BadRequest(ModelState);
             * }
             *
             * _context.Blockage.Add(blockage);*/
            var imagePath = ConvertImage(blockage.ImageUrl);

            blockage.ImageUrl = imagePath;
            _context.Blockage.Add(blockage);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBlockage", new { id = blockage.Id }, blockage));
        }
コード例 #8
0
        public void OpenOne()
        {
            // a white pawn cannot be blocked by the black king
            const string fen = "8/8/k7/p1p1pPp1/P1P1P1P1/8/8/4K3 w - - 0 1";

            const bool expected = false;

            var g = GameFactory.Create();

            g.NewGame(fen);
            var pos = g.Pos;

            var blockage = new Blockage(pos);

            var actual = blockage.IsBlocked();

            Assert.Equal(expected, actual);
        }
コード例 #9
0
        public async Task <ActionResult <CheckList> > Post([FromBody] CheckList checkList)
        {
            /*CheckList check = new CheckList()
             * {
             *  NombreP = checkList.NombreP,
             *  Transporteur = checkList.Transporteur,
             *  Tracteur = checkList.Tracteur,
             *  Date = checkList.Date,
             *  CatchAll = BsonDocument.Parse(checkList.CatchAll.ToString())
             * };*/
            var blockage = new Blockage();

            var jsonDoc = JsonConvert.SerializeObject(checkList.CatchAll);

            checkList.CatchAll = BsonSerializer.Deserialize <Dictionary <string, object> >(jsonDoc);
            System.Diagnostics.Debug.WriteLine(jsonDoc);
            System.Diagnostics.Debug.WriteLine(checkList.CatchAll);

            var conducteur = _conducteurRepo.GetConducteurByCIN(checkList.Conducteur["cin"]);
            var vehicule   = _vehiculeRepo.GetVehiculeByMatricule(checkList.Vehicule["matricule"]);
            var site       = _siteRepo.GetSiteByLibelle(checkList.Site);

            var conducteurID = conducteur != null ? conducteur.Id : -1;
            var vehiculeID   = vehicule != null ? vehicule.Id : -1;
            var siteID       = site != null ? site.Id : -1;

            // var blockageID = -1;
            if (!string.IsNullOrEmpty(checkList.ImageURL))
            {
                var imagePath = ConvertImage(checkList.ImageURL);
                checkList.ImageURL = imagePath;

                /*foreach (var image in checkList.ImagesURL)
                 * {
                 *  var imagePath = ConvertImage(image.Value);
                 *  checkList.ImagesURL[image.Key] = imagePath;
                 *  var imageKey = image.Key;
                 *  var index = 0;
                 *  foreach (var item in image.Value)
                 *  {
                 *      var imagePath = ConvertImage(item);
                 *      checkList.ImagesURL[imageKey][index] = imagePath;
                 *      index++;
                 *      System.Diagnostics.Debug.WriteLine("Image Path: " + imagePath);
                 *      System.Diagnostics.Debug.WriteLine("Image Index: " + checkList.ImagesURL[imageKey][index]);
                 *  }
                 * }*/
            }


            if (conducteur == null)
            {
                Conducteur cond = new Conducteur()
                {
                    Cin        = checkList.Conducteur["cin"],
                    NomComplet = checkList.Conducteur["nomComplet"]
                };

                await _conducteurRepo.Create(cond);

                conducteurID = cond.Id;
            }

            if (vehicule == null)
            {
                Vehicule vehi = new Vehicule()
                {
                    Matricule = checkList.Vehicule["matricule"],
                    IdEngin   = _vehiculeRepo.GetEnginByName(checkList.Vehicule["engin"])
                };

                await _vehiculeRepo.Create(vehi);

                vehiculeID = vehi.Id;
            }

            if (site == null)
            {
                Site st = new Site()
                {
                    Libelle = checkList.Site,
                };

                await _siteRepo.Create(site);

                siteID = st.Id;
            }

            checkList.Vehicule["idVehicule"]     = vehiculeID.ToString();
            checkList.Conducteur["idConducteur"] = conducteurID.ToString();

            await _checkListRepo.Create(checkList);

            System.Diagnostics.Debug.WriteLine(checkList.Id.ToString());
            System.Diagnostics.Debug.WriteLine(checkList.Controlleur);
            _context.CheckListRef.Add(new CheckListRef()
            {
                IdCheckListRef = checkList.Id.ToString(),
                Date           = checkList.Date.Value.Date,
                Rating         = checkList.Rating,
                Etat           = checkList.Etat,
                IdConducteur   = conducteurID,
                IdVehicule     = vehiculeID,
                IdSite         = siteID,
                IdControlleur  = Convert.ToInt32(checkList.Controlleur["id"])
            });


            if (checkList.Etat)
            {
                blockage.IdVehicule   = vehiculeID;
                blockage.DateBlockage = checkList.Date.Value.Date;
                blockage.IdCheckList  = checkList.Id;
                blockage.ImageUrl     = checkList.ImageURL;
                _context.Blockage.Add(blockage);
            }

            _context.SaveChanges();
            // checkList.Vehicule["idBlockage"] = blockage.IdVehicule != null ? blockage.Id.ToString() : "-1";
            // System.Diagnostics.Debug.WriteLine("BlockageID:" + blockageID);
            return(CreatedAtAction("GetCheckList", new { id = checkList.Id.ToString() }, checkList));
        }
コード例 #10
0
        public async Task <ActionResult <CheckList> > Post([FromBody] CheckList checkList)
        {
            /*CheckList check = new CheckList()
             * {
             *  NombreP = checkList.NombreP,
             *  Transporteur = checkList.Transporteur,
             *  Tracteur = checkList.Tracteur,
             *  Date = checkList.Date,
             *  CatchAll = BsonDocument.Parse(checkList.CatchAll.ToString())
             * };*/
            var blockage = new Blockage();

            var jsonDoc = JsonConvert.SerializeObject(checkList.CatchAll);

            checkList.CatchAll = BsonSerializer.Deserialize <Dictionary <string, object> >(jsonDoc);
            System.Diagnostics.Debug.WriteLine(jsonDoc);
            System.Diagnostics.Debug.WriteLine(checkList.CatchAll);

            var conducteur = _conducteurRepo.GetConducteurByNumBadge(checkList.Conducteur["numBadge"]);
            var vehicule   = _vehiculeRepo.GetVehiculeByMatricule(checkList.Vehicule["matricule"]);
            var site       = _siteRepo.GetSiteByLibelle(checkList.Site);

            var conducteurID = conducteur != null ? conducteur.Id : -1;
            var vehiculeID   = vehicule != null ? vehicule.Id : -1;
            var siteID       = site != null ? site.Id : -1;
            var blockageID   = -1;

            if (conducteur == null)
            {
                Conducteur cond = new Conducteur()
                {
                    NumBadge   = checkList.Conducteur["numBadge"],
                    NomComplet = checkList.Conducteur["nomComplet"]
                };

                await _conducteurRepo.Create(cond);

                conducteurID = cond.Id;
            }

            if (vehicule == null)
            {
                Vehicule vehi = new Vehicule()
                {
                    Matricule = checkList.Vehicule["matricule"],
                    IdEngin   = _vehiculeRepo.GetEnginByName(checkList.Vehicule["engin"])
                };

                await _vehiculeRepo.Create(vehi);

                vehiculeID = vehi.Id;
            }

            if (site == null)
            {
                Site st = new Site()
                {
                    Libelle = checkList.Site,
                };

                await _siteRepo.Create(site);

                siteID = st.Id;
            }

            checkList.Vehicule["idVehicule"]     = vehiculeID.ToString();
            checkList.Conducteur["idConducteur"] = conducteurID.ToString();

            await _checkListRepo.Create(checkList);

            System.Diagnostics.Debug.WriteLine(checkList.Id.ToString());

            _context.CheckListRef.Add(new CheckListRef()
            {
                IdCheckListRef = checkList.Id.ToString(),
                Date           = checkList.Date.Value.Date,
                Rating         = checkList.Rating,
                Etat           = checkList.Etat,
                IdConducteur   = conducteurID,
                IdVehicule     = vehiculeID,
                IdSite         = siteID
            });


            if (checkList.Etat)
            {
                blockage.IdVehicule   = vehiculeID;
                blockage.DateBlockage = checkList.Date.Value.Date;
                blockage.IdCheckList  = checkList.Id;
                _context.Blockage.Add(blockage);
            }
            _context.SaveChanges();
            checkList.Vehicule["idBlockage"] = blockage.IdVehicule != null?blockage.Id.ToString() : "-1";

            System.Diagnostics.Debug.WriteLine("BlockageID:" + blockageID);
            return(CreatedAtAction("GetCheckList", new { id = checkList.Id.ToString() }, checkList));
        }