public async Task <IActionResult> PutUsers([FromRoute] int id, [FromBody] Users users) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != users.Id) { return(BadRequest()); } _context.Entry(users).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UsersExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
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> 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()); }
public async Task <IActionResult> PutEngins([FromRoute] int id, [FromBody] Engins engins) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != engins.Id) { return(BadRequest()); } _context.Entry(engins).State = EntityState.Modified; if (engins.ImageEngin.Contains("Images")) { System.Diagnostics.Debug.WriteLine(engins.ImageEngin); } else { System.Diagnostics.Debug.WriteLine("Base64"); var imagePath = ConvertImage(engins.ImageEngin); engins.ImageEngin = imagePath; } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EnginsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
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()); }