Example #1
0
 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));
     }
 }
Example #2
0
        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}"));
            }
        }