public ActionResult NewProposition(string id, [FromBody] Offre offre) { try { var proposition = new Proposition { Id = offre.Id, Offre = offre }; var entrepriseCollection = new EntrepriseCollection(); var entreprise = entrepriseCollection.GetItems(e => e.Id == id).FirstOrDefault(); if (entreprise == null) { return(StatusCode(500, "Internal Server Error: Entreprise not found")); } if (entreprise.Propositions == null) { entreprise.Propositions = new List <Offre>(); } ((List <Offre>)(entreprise.Propositions)).Add(offre); entrepriseCollection.UpdateItem(entreprise.Id, entreprise); var propositionCollection = new PropositionCollection(); propositionCollection.NewItems(proposition); return(Ok("Propositions posté avec success")); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public ActionResult <(IEnumerable <Proposition>, IEnumerable <Publicite>)> GetPubliciteAndPropositions(string id) { try { var entrepriseCollection = new EntrepriseCollection(); var entreprise = entrepriseCollection.GetItems(e => e.Id == id).FirstOrDefault(); if (entreprise == null) { throw new Exception("Entreprise not found"); } var publicites = entreprise.Publicites.ToList(); var idPropositions = entreprise.Propositions.Select(p => p.Id).ToList(); var propositionCollection = new PropositionCollection(); var propositions = propositionCollection.GetAllItem().Where(p => idPropositions.Contains(p.Id)).ToList(); return(Ok(new { propositions = propositions, publicites = publicites })); } catch (Exception e) { return(StatusCode(200, e.Message)); } }
public ActionResult <IEnumerable <Proposition> > Getpropositions(int page) { try { var PropositionCollection = new PropositionCollection(); var Propositions = PropositionCollection.GetItems(p => p.Offre.DeadLine >= DateTime.Now || p.Offre.MaxParticipant > p.DemandeurIdentites.Count()); if (Propositions.Count() < page) { return(StatusCode(200, new List <Proposition>())); } var returnProp = new List <Proposition>(); for (int i = 0; i < Propositions.Count(); i++) { if (i <= page * 5 && i >= (page * 5) - 5) { returnProp.Add(Propositions.ToList()[i]); } } return(StatusCode(200, returnProp)); } catch (Exception e) { return(StatusCode(500, e)); } }
public ActionResult <Proposition> GetProposition(string id, string idProposition) { try { var entrepriseCollection = new EntrepriseCollection(); var propositionCollection = new PropositionCollection(); var user = entrepriseCollection.GetItems((u) => u.Id == id).FirstOrDefault(); if (user == null) { throw new Exception("Internal Server Error: Entreprise not found"); } if (user.Propositions == null) { throw new Exception("Internal Server Error: Aucune proposition"); } var propositionExist = user.Propositions.ToList().Select(p => p.Id).Contains(idProposition); if (propositionExist == false) { throw new Exception("Internal Server Error: Proposition not found"); } else { var proposition = propositionCollection.GetItems(p => p.Id == idProposition).FirstOrDefault(); if (proposition == null) { throw new Exception("Internal Server Error: Proposition not found"); } if (proposition.DemandeurIdentites == null) { proposition.DemandeurIdentites = new List <DemandeurIdentite>(); } return(Ok(proposition)); } } catch (Exception e) { return(StatusCode(500, $"Internal Server Error: {e.Message}")); } }