public async Task <UserProfileViewResult> GetUserProfileViewInfo(int userId) { var userProfile = await context.UserProfile .Include(p => p.User) .ThenInclude(p => p.University) .Include(p => p.User) .ThenInclude(p => p.Country) .FirstOrDefaultAsync(p => p.Id == userId); var coverImage = new Domain.Food.Food(); if (userProfile.CoverFoodImageId != 0) { coverImage = await context.Foods.FirstOrDefaultAsync(p => p.Id == userProfile.CoverFoodImageId); } return(new UserProfileViewResult() { UserId = userProfile.User.Id, UserName = userProfile.User.UserName, FullName = userProfile.User.FullName, Email = userProfile.User.Email, ProfileImage = userProfile.User.ProfilePictureImagePath == null ? null : FolderPath.ImagePath + FolderPath.ProfileImages + userProfile.User.ProfilePictureImagePath, CoverImage = coverImage.DefaultFoodImagepath == null ? null : FolderPath.ImagePath + FolderPath.FoodImages + coverImage.DefaultFoodImagepath, University = userProfile.User.University?.Name, Country = userProfile.User.Country?.Name, CountryCode = userProfile.User.Country?.CountryCode, AvailableDays = userProfile.AvailableDays == null ? new List <int>() : userProfile.AvailableDays.Split(',').Select(int.Parse).ToList(), AboutMe = userProfile.AboutMe, Languages = userProfile.AvailableDays == null ? new List <string>() : userProfile.Languages.Split(',').ToList <string>(), Instagram = userProfile.Instagram, Twitter = userProfile.Twitter, Address = new Common.Model.AddressModel { City = userProfile.City, Country = userProfile.Country } }); }
public async Task <UserProfileFoodViewResult> GetUserProfileInfoByUserName(string username) { var res = await context.Users.FirstOrDefaultAsync(p => p.UserName == username); if (res == null) { throw new Exception("User not found"); } var userProfileFoodViewResult = new UserProfileFoodViewResult(); var userProfile = await context.UserProfile .Include(p => p.User) .ThenInclude(p => p.University) .Include(p => p.User) .ThenInclude(p => p.Country) .FirstOrDefaultAsync(p => p.Id == res.Id); var coverImage = new Domain.Food.Food(); if (userProfile.CoverFoodImageId != 0) { coverImage = await context.Foods.FirstOrDefaultAsync(p => p.Id == userProfile.CoverFoodImageId); } userProfileFoodViewResult.Profile = new UserProfileViewResult() { UserId = userProfile.User.Id, UserName = userProfile.User.UserName, FullName = userProfile.User.FullName, Email = userProfile.User.Email, ProfileImage = userProfile.User.ProfilePictureImagePath == null ? null : FolderPath.ImagePath + FolderPath.ProfileImages + userProfile.User.ProfilePictureImagePath, CoverImage = coverImage.DefaultFoodImagepath == null ? null : FolderPath.ImagePath + FolderPath.FoodImages + coverImage.DefaultFoodImagepath, University = userProfile.User.University.Name, Country = userProfile.User.Country.Name, CountryCode = userProfile.User.Country.CountryCode, AvailableDays = userProfile.AvailableDays == null ? new List <int>() : userProfile.AvailableDays.Split(',').Select(int.Parse).ToList(), AboutMe = userProfile.AboutMe, Languages = userProfile.AvailableDays == null ? new List <string>() : userProfile.Languages.Split(',').ToList <string>(), Instagram = userProfile.Instagram, Twitter = userProfile.Twitter, Address = new Common.Model.AddressModel { City = userProfile.City, Country = userProfile.Country } }; userProfileFoodViewResult.Foods = await(from userfood in context.UserFood join foods in context.Foods on userfood.Id equals foods.Id join country in context.Country on foods.CountryId equals country.Id where userfood.UserProfileId == res.Id select new FoodViewResult { Id = foods.Id, FullName = res.FullName, Name = foods.Name, DefaultFoodImagepath = foods.DefaultFoodImagepath == null ? null : FolderPath.ImagePath + FolderPath.FoodImages + foods.DefaultFoodImagepath, Country = country.Name, Description = foods.Description, CountryCode = country.CountryCode, IsVegeterian = foods.IsVegetarian, }).ToListAsync(); return(userProfileFoodViewResult); }