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()); }
public async Task <IActionResult> PostCheckListRef([FromBody] CheckListRef checkListRef) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.CheckListRef.Add(checkListRef); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCheckListRef", new { id = checkListRef.Id }, checkListRef)); }
public async Task <IActionResult> GetBlocked([FromRoute] string id) { CheckListRef check = await _context.CheckListRef.FirstOrDefaultAsync(x => x.IdCheckListRef == id); if (check != null) { check.Etat = true; _context.SaveChanges(); } return(Ok(new { Etat = check.Etat })); }
public async Task <IActionResult> Put(string id, [FromBody] CheckList checkList) { var checkListSearch = _checkListRepo.GetCheckListByID(id); if (checkListSearch == null) { return(NotFound()); } var jsonDoc = JsonConvert.SerializeObject(checkList.CatchAll); checkList.CatchAll = BsonSerializer.Deserialize <Dictionary <string, object> >(jsonDoc); var conducteur = _conducteurRepo.GetConducteurByCIN(checkList.Conducteur["cin"]); var vehicule = _vehiculeRepo.GetVehiculeByMatricule(checkList.Vehicule["matricule"]); var site = _siteRepo.GetSiteByLibelle(checkList.Site); var conducteurID = conducteur.Id; var vehiculeID = vehicule.Id; var siteID = site.Id; 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; } await _checkListRepo.Update(checkList); CheckListRef checkListRef = _context.CheckListRef.FirstOrDefault(x => x.IdCheckListRef == checkList.Id.ToString()); checkListRef.Date = checkList.Date.Value.Date; checkListRef.IdConducteur = conducteurID; checkListRef.IdVehicule = vehiculeID; checkListRef.IdCheckListRef = checkList.Id.ToString(); checkListRef.IdSite = siteID; checkListRef.IdControlleur = Convert.ToInt32(checkList.Controlleur["id"]); _context.Entry(checkListRef).State = EntityState.Modified; _context.SaveChanges(); return(NoContent()); }