static async Task notifySubmissiontoParticipants(Audit audit) { ApplicationUser auditeuruser = ServiceUser.getUserAuditeur(audit.auditeur.AuditeurId); await ServiceEmail.sendEmailAsync(auditeuruser.Email, "Soumission d'audit", "la soumission de l'audit de la zone " + audit.zone.NomZone + " est terminée"); String htmlresultbody = @""; htmlresultbody += @"<h2>Dernier Resultats de la Zone " + audit.zone.NomZone + "</h2>"; List <Theme> themes = ServiceTheme.GetAllThemeswithoutdetaching(audit); int compt = -1; htmlresultbody += @"<table style=""width: 100%; margin: 0; float: none; text-align:left;"" class=""table"">"; foreach (Theme item in themes) { htmlresultbody += @"<tr> <th></th> </tr> <tr> <th></th> <th>" + item.info + @"</th><th></th> <th></th> </tr> <tr> <th></th> </tr>"; foreach (Point insideitem in item.points) { compt++; htmlresultbody += @"<tr> <th style=""width: 5%"">" + insideitem.NumPoint + @"</th> <th style=""width: 63%"">" + insideitem.NomPoint + @"</th> <th style=""width: 7%"">" + audit.resultats[compt].Note + @"</th> <th style=""width: 25%"">" + audit.resultats[compt].req_comment + @"</th> </tr>"; } } htmlresultbody += @"</table>";//piloteuser.Email ApplicationUser piloteuser = ServiceUser.getUserPilote(audit.zone.PiloteZoneObli.PiloteId); await ServiceEmail.sendHTMLEmailAsync(piloteuser.Email, "Résultats de l'audit de votre Zone " + audit.zone.NomZone, htmlresultbody); if (audit.zone.PiloteZoneOpti != null) { ApplicationUser piloteuseropt = ServiceUser.getUserAuditeur(audit.zone.PiloteZoneOpti.PiloteId); // await ServiceEmail.sendHTMLEmailAsync(piloteuseropt.Email, "Résultats de l'audit de votre Zone " + audit.zone.NomZone, htmlresultbody); } }
static public void AddResultats(ResultsViewModel resultvm) { using (ResultatRepository resultatrepo = new ResultatRepository()) { //geeting the audit and setting it to modified automatically resultatrepo.context.Entry(resultvm.audit).State = EntityState.Modified; //geeting the themes and the points and setting it to unchanged so it wont be readded to the database that will be hell oh no no resultvm.themes = ServiceTheme.GetAllThemes(); foreach (var item in resultvm.themes) { resultatrepo.context.Entry(item).State = EntityState.Unchanged; } //a workaround to reattach the relations the results you can say that this is MAGIC int compteur = -1; foreach (var item in resultvm.themes) { foreach (var inneritem in item.points) { compteur++; resultvm.resultats[compteur].audit = resultvm.audit; resultvm.resultats[compteur].theme = item; resultvm.resultats[compteur].point = inneritem; resultatrepo.Add(resultvm.resultats[compteur]); } } resultatrepo.Save(); } }
static public int GetAudit5StarsLevel(Audit audit) { List <Theme> themes = ServiceTheme.GetAllThemeswithoutdetaching(); List <Resultat> derniersresultats = ServiceResultat.getAuditresults(audit); int niv = 0; foreach (var theme in themes) { niv++; if (!levelPassed(niv, theme.Passinggrade, derniersresultats, themes)) { return(niv - 1); } } return(5); }
static public void UpdateResultats(ResultsViewModel resultvm) { using (ResultatRepository resultatrepo = new ResultatRepository()) { //geeting the audit and setting it to unchanged so it wont be readded to the database that will be hell oh no no resultatrepo.context.Entry(resultvm.audit).State = EntityState.Unchanged; //geeting the themes and the points and setting it to unchanged so it wont be readded to the database that will be hell oh no no resultvm.themes = ServiceTheme.GetAllThemes(resultvm.audit); foreach (var item in resultvm.themes) { resultatrepo.context.Entry(item).State = EntityState.Unchanged; } List <int> ResultPoints = new List <int>(); foreach (var item in resultvm.audit.resultats) { ResultPoints.Add(item.point.PointID); } List <Point> PointTemp1 = new List <Point>(); //foreach (var item in ServicePoint.GetAllPoints()) //{ //} foreach (var theme in resultvm.themes) { PointTemp1.Clear(); foreach (var item1 in theme.points) { PointTemp1.Add(item1); } //for (int i = 0; i < PointTemp1.Count; i++) //{ // if (!ResultPoints.Contains(point.PointID)) // { // theme.points.Remove(point); // } //} foreach (var point in PointTemp1) { if (!ResultPoints.Contains(point.PointID)) { theme.points.Remove(point); } } } //getting the results from the database and updating them Resultat tempresultat = null; int compteur = -1; foreach (var item in resultvm.themes) { foreach (var inneritem in item.points) { compteur++; tempresultat = ServiceResultat.getresultatbyCriteria(resultvm.audit, item, inneritem); tempresultat.audit = resultvm.audit; tempresultat.theme = item; tempresultat.point = inneritem; tempresultat.Note = resultvm.resultats[compteur].Note; tempresultat.req_comment = resultvm.resultats[compteur].req_comment; resultatrepo.Update(tempresultat); } } resultatrepo.Save(); } }