public ActionResult <double> Commenter(string publicationId, [FromBody] CommentaireSend commentaire) { try { var id = Guid.NewGuid().ToString(); commentaire.Id = id; var com = commentaire.Commentaire; com.Id = id; var CommentaireML = new PredictedModels.PredictedCommentaire(com); CommentaireML = CommentaireML.AttribScoreAndTypeOfComment(); var commentf = CommentaireML; var publicationCollection = new PublicationCollection(); var publication = publicationCollection.GetItems(p1 => p1.Id == publicationId).FirstOrDefault(); if (publication == null) { throw new Exception("Publication not found"); } ((List <CommentaireSend>)(publication.Commentaires)).Add(commentaire); var p = publication; publicationCollection.UpdateItem(publication.Id, publication); return(StatusCode(200, commentaire)); } catch (Exception e) { return(StatusCode(500, $"Internal Server Error: {e.Message}")); } }
public ActionResult <IEnumerable <Publication> > GetPublication(int page) { try { PublicationCollection publicationCollection = new PublicationCollection(); var publications = publicationCollection.GetAllItem().OrderByDescending(p => p.PublicationDetails.Date).ToList(); if (publications.Count <= page) { return(StatusCode(200, new List <Publication>())); } var returnPubs = new List <Publication>(); for (int i = 0; i < publications.Count; i++) { if (i <= page * 5 && i >= (page * 5) - 5) { returnPubs.Add(publications[i]); } } return(StatusCode(200, returnPubs)); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public ActionResult <IEnumerable <Publication> > GetPublications(string id) { try { var publicationCollection = new PublicationCollection(); var publication = publicationCollection.GetItems(p => p.Demandeur.Id == id).ToList(); return(publication); } catch (Exception e) { return(StatusCode(500, $"Internal Server Error: {e.Message}")); } }
public ActionResult <object> GetPublication(string id) { try { PublicationCollection publicationCollection = new PublicationCollection(); var publication = publicationCollection.GetItems(p => p.Id == id).FirstOrDefault(); if (publication == null) { throw new Exception("Publication not found"); } return(StatusCode(200, publication)); } catch (Exception e) { return(StatusCode(500, $"Internal Server Error: {e.Message}")); } }
public ActionResult <bool> Like(string idEntreprise, string idPub) { try { PublicationCollection publicationCollection = new PublicationCollection(); var publication = publicationCollection.GetItems(p => p.Id == idPub).FirstOrDefault(); if (publication == null) { throw new Exception($"Publication not found"); } var like = publication.Likes.Where(l => l.Id == idEntreprise).FirstOrDefault(); if (like == null) { ((List <Like>)(publication.Likes)).Add(new Models.Like { Id = idEntreprise, Etat = true }); publicationCollection.UpdateItem(idPub, publication); return(StatusCode(200, true)); } else { if (like.Etat == false) { publication.Likes.Where(p => p.Id == idEntreprise).FirstOrDefault().Etat = true; var p2 = publication; publicationCollection.UpdateItem(idPub, publication); return(StatusCode(200, true)); } else { publication.Likes.Where(p => p.Id == idEntreprise).FirstOrDefault().Etat = false; var p2 = publication; publicationCollection.UpdateItem(idPub, publication); return(StatusCode(200, false)); } } } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public static (double, DemandeurIdentite) AttribScoreForOneCandidat(Demandeur demandeur) { var publicationId = demandeur.Publications.Select(p => p.Id); var PublicationsCollection = new PublicationCollection(); var publications = PublicationsCollection.GetItems(p => publicationId.Contains(p.Id)).ToList(); var like = 0; var ranking = 0.0; foreach (var p in publications) { foreach (var c in p.Commentaires) { var predictedCommentaire = new PredictedModels.PredictedCommentaire(c.Commentaire); predictedCommentaire = predictedCommentaire.AttribScoreAndTypeOfComment(); ranking += predictedCommentaire.Score; } like += p.Likes.Where(l => l.Etat == true).Count(); } return(ranking + like, demandeur.Identite); }
public ActionResult <string> UpdateEntreprise(string id, int type, [FromBody] EmployeurIdentite employeur) { try { string dataResult = ""; var entrepriseCollection = new EntrepriseCollection(); PublicationCollection publicationCollection = new PublicationCollection(); var employeurIdentite = entrepriseCollection.GetItems(e => e.Id == id).FirstOrDefault(); if (type == 1) { employeurIdentite.EmployeurIdentite.Nom = employeur.Nom; employeurIdentite.EmployeurIdentite.Adresse = employeur.Adresse; employeurIdentite.EmployeurIdentite.IdNational = employeur.IdNational; entrepriseCollection.UpdateItem(id, employeurIdentite); dataResult = "Identité modifié avec succès"; } else if (type == 2) { employeurIdentite.EmployeurIdentite.MotDePasse = employeur.MotDePasse; entrepriseCollection.UpdateItem(id, employeurIdentite); dataResult = "Mot de passe modifié avec succès"; } else if (type == 3) { employeurIdentite.EmployeurIdentite.AboutEntreprise = employeur.AboutEntreprise; employeurIdentite.EmployeurIdentite.Domaines = employeur.Domaines; entrepriseCollection.UpdateItem(id, employeurIdentite); dataResult = "Les details modifié avec succès"; } else { throw new Exception("Modifications non pris en charge"); } return(StatusCode(200, dataResult)); } catch (Exception) { throw; } }
public override void InsertCollection(int index, int itemsInCollection, int publicationsCount) { var collection = new PublicationCollection() { Id = Guid.NewGuid().ToString(), Name = CollectionName(index), RemoteId = index }; _realm.Add(collection); var lowerBound = (index * itemsInCollection) % publicationsCount; var upperBound = lowerBound + itemsInCollection; //((index + 1) * itemsInCollection) % publicationsCount; var publications = _realm.All <Publication>() .Where(x => x.RemoteId >= lowerBound && x.RemoteId < upperBound); foreach (var publication in publications) { collection.Publications.Add(publication); } }