public IHttpActionResult GetUserPosts(string ID) { int a = int.Parse(ID); var user = db.Clients.FirstOrDefault(p => p.ID == a); var userPostes = db.Postes.Where(p => p.ClientID == user.ID).ToList(); var userActivites = db.Activites.Where(p => p.Activite_client_id == user.ID).ToList(); PostTraitemenrInfo pti = new PostTraitemenrInfo(); pti.nombrePosts = userPostes.Count(); pti.nombreActivites = userActivites.Count(); List <PostsUserApiModel> pu = new List <PostsUserApiModel>(); foreach (var up in userPostes) { PostsUserApiModel puam = new PostsUserApiModel(); puam.ID = up.ID; puam.Poste_title = up.Poste_title; puam.Poste_description = up.Poste_description; puam.Date_CreationPost = up.Date_CreationPost; puam.Pay = up.Pay; puam.Poste_image = up.Poste_image; puam.nombreActivitiesParPoste = up.Activites.Count(); pu.Add(puam); } pti.posts = pu; return(Ok(pti)); }
public IHttpActionResult GetUserPosts() { TourismeEntities db = new TourismeEntities(); var identityClaims = (ClaimsIdentity)User.Identity; string Email = identityClaims.FindFirst("Email").Value; var user = db.Clients.FirstOrDefault(p => p.Email == Email); var userPostes = db.Postes.Where(p => p.ID == user.ID).ToList(); var userActivites = db.Activites.Where(p => p.Activite_client_id == user.ID).ToList(); PostTraitemenrInfo pti = new PostTraitemenrInfo(); pti.nombrePosts = userPostes.Count(); pti.nombreActivites = userActivites.Count(); List <PostsUserApiModel> pu = new List <PostsUserApiModel>(); foreach (var up in userPostes) { PostsUserApiModel puam = new PostsUserApiModel(); puam.ID = up.ID; puam.Poste_title = up.Poste_title; puam.Poste_description = up.Poste_description; puam.Date_CreationPost = up.Date_CreationPost; puam.Pay = up.Pay; pu.Add(puam); } pti.posts = pu; return(Ok(pti)); }