public async Task <ActionResult <Fiche_Suivi> > PostFiche_Suivi(Fiche_Suivi fiche_Suivi) { _context.Fiche_Suivis.Add(fiche_Suivi); await _context.SaveChangesAsync(); return(CreatedAtAction("GetFiche_Suivi", new { id = fiche_Suivi.FicheSuiviID }, fiche_Suivi)); }
public async Task <IActionResult> PutFiche_Suivi(int id, Fiche_Suivi fiche_Suivi) { if (id != fiche_Suivi.FicheSuiviID) { return(BadRequest()); } _context.Entry(fiche_Suivi).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Fiche_SuiviExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
//pour tester la contrainte date: //Le saisi du premier jour de chaque mois ne se fait qu’après le saisi //du dernier jour de mois précédant public string testDatePost(Fiche_Suivi fiche_Suivi) { int value = DateTime.Compare(fiche_Suivi.Date, DateTime.Now); if (value <= 0) { if (fiche_Suivi.Date.DayOfWeek != DayOfWeek.Saturday && fiche_Suivi.Date.DayOfWeek != DayOfWeek.Sunday) { var exist = _context.Fiche_Suivis.Where(c => c.CompFilialeID == fiche_Suivi.CompFilialeID).FirstOrDefault(); if (exist != null) { DateTime date2; int annee = fiche_Suivi.Date.Year; int mois = fiche_Suivi.Date.Month - 1; if (mois == 0) { mois = 12; annee--; } int last = DateTime.DaysInMonth(annee, mois); DateTime date = new DateTime(annee, mois, last); if (date.DayOfWeek == DayOfWeek.Saturday) { date2 = new DateTime(annee, mois, last - 1); } else if (date.DayOfWeek != DayOfWeek.Sunday) { date2 = new DateTime(annee, mois, last - 2); } else { date2 = new DateTime(annee, mois, last); } var res = _context.Fiche_Suivis.Where(c => c.Date == date2).FirstOrDefault(); if (res != null) { return("true"); } else { return("The last day of the previous month not completed"); } } else { return("true"); } } return("Week-end"); } else { return("Date superior to the date of today"); } }
public string PutFiche_Suivi(int id, Fiche_Suivi fiche_Suivi) { int max = _context.Fiche_Suivis.Where(c => c.CompFilialeID == fiche_Suivi.CompFilialeID).Max(c => c.Index_Electrique); string testval = testDatePut(fiche_Suivi); if (testval == "true") { if (fiche_Suivi.Nbre_Heurs_Charge < fiche_Suivi.Nbre_Heurs_Total) { if (fiche_Suivi.Index_Electrique >= max) { { var entity = _context.Fiche_Suivis.Find(id); if (entity != null) { entity.Date = fiche_Suivi.Date; entity.Nbre_Heurs_Total = fiche_Suivi.Nbre_Heurs_Total; entity.Nbre_Heurs_Charge = fiche_Suivi.Nbre_Heurs_Charge; entity.Index_Electrique = fiche_Suivi.Index_Electrique; entity.TempsArret = fiche_Suivi.TempsArret; entity.Etat = fiche_Suivi.Etat; entity.FréquenceEentretienDeshuileur = fiche_Suivi.FréquenceEentretienDeshuileur; entity.TypeDernierEntretien = fiche_Suivi.TypeDernierEntretien; entity.PriseCompteur = fiche_Suivi.PriseCompteur; entity.THuileC = fiche_Suivi.THuileC; entity.TSécheurC = fiche_Suivi.TSécheurC; entity.Remarques = fiche_Suivi.Remarques; // _context.Entry(entity).State = EntityState.Modified; _context.SaveChanges(); return("Update done " + id); } else { return("Fiche suivi don't exist"); } } } else { return("Index lower than the previous index"); } } else { return("Total number of hours less than the number of hours in charge"); } } else { return(testval); } }
public string TestDoubleDate(Fiche_Suivi fiche_Suivi) { var doubledate = _context.Fiche_Suivis.Where(c => c.CompFilialeID == fiche_Suivi.CompFilialeID && c.Date == fiche_Suivi.Date).FirstOrDefault(); if (doubledate == null) { return("true"); } else { return("Existing Fiche_suivi at this date"); } }
public string PostFiche_Suivi(Fiche_Suivi fiche_Suivi) { int max = 0; // int max = _context.Fiche_Suivis.Max(c => c.Index_Electrique); var maxpossible = _context.Fiche_Suivis.Where(c => c.CompFilialeID == fiche_Suivi.CompFilialeID && DateTime.Compare(fiche_Suivi.Date, c.Date) < 0).FirstOrDefault(); if (maxpossible != null) { max = _context.Fiche_Suivis.Where(c => c.CompFilialeID == fiche_Suivi.CompFilialeID && DateTime.Compare(fiche_Suivi.Date, c.Date) < 0).Max(c => c.Index_Electrique); } string testval = testDatePost(fiche_Suivi); string datedouble = TestDoubleDate(fiche_Suivi); if (datedouble == "true") { if (testval == "true") { if (fiche_Suivi.Nbre_Heurs_Charge < fiche_Suivi.Nbre_Heurs_Total) { if (fiche_Suivi.Index_Electrique >= max) { _context.Fiche_Suivis.Add(fiche_Suivi); _context.SaveChanges(); return("Added done " + fiche_Suivi.FicheSuiviID); } else { return("Index lower than the previous index"); } } else { return("Total number of hours less than the number of hours in charge"); } } else { return(testval); } } else { return(datedouble); } }
public async Task <ActionResult <string> > PostFiche_Suivi([FromBody] Fiche_Suivi fiche_Suivi) { ValidationContraint validationFiche_Suivi = new ValidationContraint(_context); string testval = validationFiche_Suivi.testPost(fiche_Suivi); if (testval == "true") { return(await mediator.Send(new CreateGenericCommand <Fiche_Suivi>(fiche_Suivi))); } else { return(testval); } }
public async Task <string> PutFiche_Suivi([FromRoute] Guid id, [FromBody] Fiche_Suivi fiche_Suivi) { ValidationContraint validationFiche_Suivi = new ValidationContraint(_context); string testval = validationFiche_Suivi.testPut(fiche_Suivi, id); if (testval == "true") { return(await mediator.Send(new PutGenericCommand <Fiche_Suivi>(id, fiche_Suivi))); } else { return(testval); } }
public string TestDoubleDatePut(Fiche_Suivi fiche_Suivi, Guid id) { var entity = _context.Fiche_Suivis.Find(id); if (entity.Date == fiche_Suivi.Date) { return("true"); } else { var doubledate = _context.Fiche_Suivis.Where(c => c.EquipementFilialeID == fiche_Suivi.EquipementFilialeID && c.Date == fiche_Suivi.Date).FirstOrDefault(); if (doubledate == null) { return("true"); } else { return("Existing Fiche_suivi at this date"); } } }
public string testPut(Fiche_Suivi fiche_Suivi, Guid id) { string result; string datedouble = TestDoubleDatePut(fiche_Suivi, id); if (datedouble == "true") { int value = DateTime.Compare(fiche_Suivi.Date, DateTime.Now); if (value <= 0) { if (fiche_Suivi.Date.DayOfWeek != DayOfWeek.Saturday && fiche_Suivi.Date.DayOfWeek != DayOfWeek.Sunday) { DateTime date2; int annee = fiche_Suivi.Date.Year; int mois = fiche_Suivi.Date.Month - 1; if (mois == 0) { mois = 12; annee--; } int last = DateTime.DaysInMonth(annee, mois); DateTime date = new DateTime(annee, mois, last); if (date.DayOfWeek == DayOfWeek.Saturday) { date2 = new DateTime(annee, mois, last - 1); } else if (date.DayOfWeek == DayOfWeek.Sunday) { date2 = new DateTime(annee, mois, last - 2); } else { date2 = new DateTime(annee, mois, last); } var res = _context.Fiche_Suivis.Where(c => c.Date == date2).FirstOrDefault(); if (res != null) { result = "true"; } else { result = "The last day of the previous month not completed"; } } else { result = "Week-end"; } } else { result = "Date superior to the date of today"; } if (result == "true") { int max = _context.Fiche_Suivis.Where(c => (c.CompFilialeID == fiche_Suivi.CompFilialeID) && (c.Date < fiche_Suivi.Date)).Max(c => c.Index_Electrique); if (fiche_Suivi.Nbre_Heurs_Charge < fiche_Suivi.Nbre_Heurs_Total) { if (fiche_Suivi.Index_Electrique >= max) { { var entity = _context.Fiche_Suivis.Find(id); if (entity != null) { return("true"); } else { return("Fiche suivi don't exist"); } } } else { return("Index lower than the previous index"); } } else { return("Total number of hours less than the number of hours in charge"); } } else { return(result); } } else { return(datedouble); } }
public CreateFicheSuiviCommand(Fiche_Suivi ficheSuivi) { FicheSuivi = ficheSuivi; }
public string PostFiche_Suivi(Fiche_Suivi fiche_Suivi) { return(_fiches_SuiviRepository.PostFiche_Suivi(fiche_Suivi)); }
public string testPost(Fiche_Suivi fiche_Suivi) { string result; int max = 0; var maxpossible = _context.Fiche_Suivis.Where(c => c.CompFilialeID == fiche_Suivi.CompFilialeID && DateTime.Compare(fiche_Suivi.Date, c.Date) < 0).FirstOrDefault(); if (maxpossible != null) { max = _context.Fiche_Suivis.Where(c => c.CompFilialeID == fiche_Suivi.CompFilialeID && DateTime.Compare(fiche_Suivi.Date, c.Date) < 0).Max(c => c.Index_Electrique); } string datedouble = TestDoubleDate(fiche_Suivi); int firtM = 0; if (datedouble == "true") { int value = DateTime.Compare(fiche_Suivi.Date, DateTime.Now); if (value <= 0) { if (fiche_Suivi.Date.DayOfWeek != DayOfWeek.Saturday && fiche_Suivi.Date.DayOfWeek != DayOfWeek.Sunday) { var exist = _context.Fiche_Suivis.Where(c => c.CompFilialeID == fiche_Suivi.CompFilialeID).FirstOrDefault(); if (exist != null) { var FirstMonth = _context.Fiche_Suivis.Min(c => c.Date); firtM = DateTime.Compare(fiche_Suivi.Date, FirstMonth); if (firtM != 0) { DateTime lastMonthDate; int annee = fiche_Suivi.Date.Year; int mois = fiche_Suivi.Date.Month - 1; if (mois == 0) { mois = 12; annee--; } int numberOfDays = DateTime.DaysInMonth(annee, mois); DateTime date = new DateTime(annee, mois, numberOfDays); if (date.DayOfWeek == DayOfWeek.Saturday) { lastMonthDate = new DateTime(annee, mois, numberOfDays - 1); } else if (date.DayOfWeek == DayOfWeek.Sunday) { lastMonthDate = new DateTime(annee, mois, numberOfDays - 2); } else { lastMonthDate = new DateTime(annee, mois, numberOfDays); } var res = _context.Fiche_Suivis.Where(c => c.Date == lastMonthDate).FirstOrDefault(); if (res != null) { result = "true"; } else { result = "The last day of the previous month not completed"; } } else { result = "true"; } } else { result = "true"; } } else { result = "Week-end"; } } else { result = "Date superior to the date of today"; } if (result == "true") { if (fiche_Suivi.Nbre_Heurs_Charge < fiche_Suivi.Nbre_Heurs_Total) { if (fiche_Suivi.Index_Electrique >= max) { return("true"); } else { return("Index lower than the previous index"); } } else { return("Total number of hours less than the number of hours in charge"); } } else { return(result); } } else { return(datedouble); } }
public string testPost(Fiche_Suivi fiche_Suivi) { string result; int max = 0; int maxtothours = 0; int maxchargehours = 0; int maxIndexDebimetre = 0; var maxpossible = _context.Fiche_Suivis.Where(x => x.EquipementFilialeID == fiche_Suivi.EquipementFilialeID).OrderBy(x => x.Date).LastOrDefault(); //&& //DateTime.Compare(fiche_Suivi.Date, c.Date) < 0).FirstOrDefault(); if (maxpossible != null) { max = maxpossible.Index_Electrique; maxtothours = maxpossible.Nbre_Heurs_Total; maxchargehours = maxpossible.Nbre_Heurs_Charge; maxIndexDebimetre = maxpossible.Index_Debitmetre; } string datedouble = TestDoubleDate(fiche_Suivi); int firtM = 0; if (datedouble == "true") { int value = DateTime.Compare(fiche_Suivi.Date, DateTime.Now); if (value <= 0) { ////if (fiche_Suivi.Date.DayOfWeek != DayOfWeek.Saturday && fiche_Suivi.Date.DayOfWeek != DayOfWeek.Sunday) // //{ var exist = _context.Fiche_Suivis.Where(c => c.EquipementFilialeID == fiche_Suivi.EquipementFilialeID).FirstOrDefault(); if (exist != null) { var FirstMonth = _context.Fiche_Suivis.Min(c => c.Date); firtM = DateTime.Compare(fiche_Suivi.Date, FirstMonth); if (firtM != 0) { DateTime lastMonthDate; int annee = fiche_Suivi.Date.Year; int mois = fiche_Suivi.Date.Month - 1; if (mois == 0) { mois = 12; annee--; } int numberOfDays = DateTime.DaysInMonth(annee, mois); DateTime date = new DateTime(annee, mois, numberOfDays); if (date.DayOfWeek == DayOfWeek.Saturday) { lastMonthDate = new DateTime(annee, mois, numberOfDays - 1); } else if (date.DayOfWeek == DayOfWeek.Sunday) { lastMonthDate = new DateTime(annee, mois, numberOfDays - 2); } else { lastMonthDate = new DateTime(annee, mois, numberOfDays); } if (_context.Fiche_Suivis.Count(c => c.EquipementFilialeID == fiche_Suivi.EquipementFilialeID) < 30) { result = "true"; } else { var res = _context.Fiche_Suivis.Where(c => c.Date == lastMonthDate).FirstOrDefault(); if (res != null) { result = "true"; } else { result = "The last day of the previous month not completed"; } } } else { result = "true"; } } else { result = "true"; } //} //else // result = "Week-end"; } else { result = "Date superior to the date of today"; } if (result == "true") { if (fiche_Suivi.Nbre_Heurs_Charge < fiche_Suivi.Nbre_Heurs_Total) { if (fiche_Suivi.Index_Electrique >= max) { if (fiche_Suivi.Nbre_Heurs_Total >= maxtothours) { if (fiche_Suivi.Nbre_Heurs_Charge >= maxchargehours) { if (fiche_Suivi.Index_Debitmetre >= maxIndexDebimetre) { return("true"); } else { return("Index debimetre lower than the previous index"); } } else { return("nbre heures charge lower than the previous nbre heures charge"); } } else { return("nbre heures total lower than the previous nbre heures total"); } } else { return("Index lower than the previous index"); } } else { return("Total number of hours less than the number of hours in charge"); } } else { return(result); } } else { return(datedouble); } }
public string PutFiche_Suivi(int id, Fiche_Suivi fiche_Suivi) { return(_fiches_SuiviRepository.PutFiche_Suivi(id, fiche_Suivi)); }
public ActionResult <string> Postfiche_Suivi(Fiche_Suivi fiche_Suivi) { return(Ok(_fiches_SuiviService.PostFiche_Suivi(fiche_Suivi))); }
public ActionResult <string> PutFiche_Suivi(int id, Fiche_Suivi fiche_Suivi) { return(Ok(_fiches_SuiviService.PutFiche_Suivi(id, fiche_Suivi))); }
public Guid AddFicheSuivi(Fiche_Suivi fiche_Suivi) { _db.Fiche_Suivis.Add(fiche_Suivi); _db.SaveChanges(); return(fiche_Suivi.FicheSuiviID); }
public async Task <ActionResult <string> > PostFiche_Suivi(IFormFile fiche_SuiviFormFile) { ValidationContraint validationFiche_Suivi = new ValidationContraint(_context); // fiche_SuiviFormFile. StringValues EquipementFilialeID; StringValues Index_Debitmetre; StringValues FraisEntretienReparation; StringValues Date; StringValues Etat; StringValues PointDeRoseeDuSecheur; StringValues THuileC; StringValues TempsArret; StringValues Nbre_Heurs_Total; StringValues TSecheurC; StringValues Remarques; StringValues PriseCompteurDernierEntretien; StringValues Nbre_Heurs_Charge; StringValues Index_Electrique; StringValues TypeDernierEntretien; StringValues NombreHeuresProductionUsineLeJourPrecedent; StringValues NombreDeJoursOuvrablesDuMois; // Request.Form.TryGetValue("Date", out Date); Request.Form.TryGetValue("EquipementFilialeID", out EquipementFilialeID); Request.Form.TryGetValue("Nbre_Heurs_Total", out Nbre_Heurs_Total); Request.Form.TryGetValue("Nbre_Heurs_Charge", out Nbre_Heurs_Charge); Request.Form.TryGetValue("TempsArret", out TempsArret); Request.Form.TryGetValue("Etat", out Etat); Request.Form.TryGetValue("PointDeRoseeDuSecheur", out PointDeRoseeDuSecheur); Request.Form.TryGetValue("Index_Debitmetre", out Index_Debitmetre); Request.Form.TryGetValue("FraisEntretienReparation", out FraisEntretienReparation); Request.Form.TryGetValue("PriseCompteurDernierEntretien", out PriseCompteurDernierEntretien); Request.Form.TryGetValue("Remarques", out Remarques); Request.Form.TryGetValue("THuileC", out THuileC); Request.Form.TryGetValue("Index_Electrique", out Index_Electrique); Request.Form.TryGetValue("TypeDernierEntretien", out TypeDernierEntretien); Request.Form.TryGetValue("NombreHeuresProductionUsineLeJourPrecedent", out NombreHeuresProductionUsineLeJourPrecedent); Request.Form.TryGetValue("NombreDeJoursOuvrablesDuMois", out NombreDeJoursOuvrablesDuMois); if (Request.Form.TryGetValue("NombreDeJoursOuvrablesDuMois", out NombreDeJoursOuvrablesDuMois) == false) { NombreDeJoursOuvrablesDuMois = "0"; } var fiche_Suivi = new Fiche_Suivi() { EquipementFilialeID = Guid.Parse(EquipementFilialeID), FraisEntretienReparation = Convert.ToInt32(FraisEntretienReparation), Date = Convert.ToDateTime(Date), Etat = ConvertFromStringToListeEtat(Etat), PointDeRoseeDuSecheur = PointDeRoseeDuSecheur, THuileC = Convert.ToDouble(THuileC), TempsArret = Convert.ToDouble(TempsArret), Nbre_Heurs_Total = Convert.ToInt32(Nbre_Heurs_Total), Remarques = Remarques, PriseCompteurDernierEntretien = Convert.ToInt32(PriseCompteurDernierEntretien), Nbre_Heurs_Charge = Convert.ToInt32(Nbre_Heurs_Charge), Index_Electrique = Convert.ToInt32(Index_Electrique), TypeDernierEntretien = ConvertFromStringToTypeEntretien(TypeDernierEntretien), NombreHeuresProductionUsineLeJourPrecedent = Convert.ToInt32(NombreHeuresProductionUsineLeJourPrecedent), NombreDeJoursOuvrablesDuMois = Convert.ToInt32(NombreDeJoursOuvrablesDuMois), Index_Debitmetre = Convert.ToInt32(Index_Debitmetre) }; //Request.Form.Files string testval = validationFiche_Suivi.testPost(fiche_Suivi); if (testval == "true") { // fiche_Suivi.FicheSuiviID= await mediator.Send(new CreateFicheSuiviCommand(fiche_Suivi)); _context.Fiche_Suivis.Add(fiche_Suivi); _context.SaveChanges(); foreach (IFormFile formFile in Request.Form.Files) { if (formFile.Length > 0) { var filePath = Path.GetTempFileName(); using (var stream = System.IO.File.Create(filePath)) { await formFile.CopyToAsync(stream); } } var tempAttachement = new Attachment(); _context.Attachments.Add(tempAttachement); try { var file = formFile; var folderName = Path.Combine("Resources", "FicheSuiviFiles"); var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName); if (file.Length > 0) { var OriginFileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var OriginFileFormat = file.FileName.Substring(file.FileName.LastIndexOf('.') + 1, ((file.FileName.Length - 1) - file.FileName.LastIndexOf('.'))); var fileName = "pieceJointeFS" + tempAttachement.AttachmentId; var fullPath = Path.Combine(pathToSave, fileName); var dbPath = Path.Combine(folderName, fileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); } //create attachement for DB table tempAttachement.AttachmentName = fileName; tempAttachement.AttachmentFileFormat = file.FileName.Substring(file.FileName.LastIndexOf('.') + 1, ((file.FileName.Length - 1) - file.FileName.LastIndexOf('.'))); tempAttachement.AttachmentOriginFileName = OriginFileName; tempAttachement.FicheSuiviID = fiche_Suivi.FicheSuiviID; tempAttachement.AttachmentPhysicalPath = fullPath; //assign attachement to fichSuivi _context.Entry(tempAttachement).State = EntityState.Added; _context.SaveChanges(); } _context.SaveChanges(); } catch (Exception ex) { } } return("Added done"); } else { return(testval); } }
public string testPut(Fiche_Suivi fiche_Suivi, Guid id) { int max = 0; int maxtothours = 0; int maxchargehours = 0; int maxIndexDebimetre = 0; var maxpossible = _context.Fiche_Suivis.Where(x => x.EquipementFilialeID == fiche_Suivi.EquipementFilialeID).OrderBy(x => x.Date).LastOrDefault(); //&& //DateTime.Compare(fiche_Suivi.Date, c.Date) < 0).FirstOrDefault(); if (maxpossible != null) { max = maxpossible.Index_Electrique; maxtothours = maxpossible.Nbre_Heurs_Total; maxchargehours = maxpossible.Nbre_Heurs_Charge; maxIndexDebimetre = maxpossible.Index_Debitmetre; } string result; //string datedouble = TestDoubleDatePut(fiche_Suivi, id); //if (datedouble == "true") //{ //int value = DateTime.Compare(fiche_Suivi.Date, DateTime.Now); //if (value <= 0) //{ //if (fiche_Suivi.Date.DayOfWeek != DayOfWeek.Saturday && fiche_Suivi.Date.DayOfWeek != DayOfWeek.Sunday) //{ // DateTime date2; // int annee = fiche_Suivi.Date.Year; // int mois = fiche_Suivi.Date.Month - 1; // if (mois == 0) // { // mois = 12; // annee--; // } // int last = DateTime.DaysInMonth(annee, mois); // DateTime date = new DateTime(annee, mois, last); // if (date.DayOfWeek == DayOfWeek.Saturday) // { // date2 = new DateTime(annee, mois, last - 1); // } // else if (date.DayOfWeek == DayOfWeek.Sunday) // { // date2 = new DateTime(annee, mois, last - 2); // } // else // { // date2 = new DateTime(annee, mois, last); // } // var res = _context.Fiche_Suivis.Where(c => c.Date == date2).FirstOrDefault(); // if (res != null) // result = "true"; // else // result = "The last day of the previous month not completed"; //} // else // result = "Week-end"; //} //else // result = "Date superior to the date of today"; //if (result == "true") //{ // int max = _context.Fiche_Suivis.Where(c => (c.EquipementFilialeID == fiche_Suivi.EquipementFilialeID) && (c.Date < fiche_Suivi.Date)).Max(c => c.Index_Electrique); if (fiche_Suivi.Nbre_Heurs_Charge < fiche_Suivi.Nbre_Heurs_Total) { if (fiche_Suivi.Index_Electrique >= max) { if (fiche_Suivi.Nbre_Heurs_Total >= maxtothours) { if (fiche_Suivi.Nbre_Heurs_Charge >= maxchargehours) { if (fiche_Suivi.Index_Debitmetre >= maxIndexDebimetre) { var entity = _context.Fiche_Suivis.Find(id); if (entity != null) { return("true"); } else { return("Fiche suivi don't exist"); } } else { return("Index debimetre lower than the previous index"); } } else { return("nbre heures charge lower than the previous nbre heures charge"); } } else { return("nbre heures total lower than the previous nbre heures total"); } } else { return("Index lower than the previous index"); } } else { return("Total number of hours less than the number of hours in charge"); } //} //else //return result; //} //else return datedouble; }