public VolunteerProfileViewModel GetSignedVolunteer() { if (CurrentSigned.VolunteerId != -1) { if (context.Volunteers.Find(CurrentSigned.VolunteerId) != null) { var currentlySigned = context.Volunteers.Find(CurrentSigned.VolunteerId); var ads = new List <AdvertSingleViewModel>(); foreach (JobVolunteer ad in context.JobVolunteer.Where(x => x.VolunteerId == CurrentSigned.VolunteerId)) { var viewAd = context.JobAds.Find(ad.JobAdId); var singleViewModel = new AdvertSingleViewModel() { Id = ad.JobAd.Id, Position = ad.JobAd.PositionName, Description = ad.JobAd.Description, CompanyName = context.Employers.Find(ad.JobAd.EmployerId).CompanyName }; ads.Add(singleViewModel); } var singleAdViewModel = new IndexSingleAdViewModel() { Ads = ads }; var profileView = new VolunteerProfileViewModel() { Username = currentlySigned.Username, NewPassword = currentlySigned.Password, OldPassword = currentlySigned.Password, FirstName = currentlySigned.FirstName, LastName = currentlySigned.LastName, Age = currentlySigned.Age, Contact = currentlySigned.ContactInformation, SignedInAds = singleAdViewModel }; return(profileView); } else { throw new ArgumentException("Cannot find the account with the currently specified id."); } } else { throw new ArgumentException("There is currently no signed in account."); } }
private IndexSingleAdViewModel GetAllHostedAds(int id) { var hostedAds = new List <AdvertSingleViewModel>(); foreach (var item in context.JobAds.Where(j => j.EmployerId == id)) { var temp = new AdvertSingleViewModel() { Id = item.Id, Position = item.PositionName, Description = item.Description, CompanyName = context.Employers.Find(id).CompanyName }; hostedAds.Add(temp); } IndexSingleAdViewModel model = new IndexSingleAdViewModel(); model.Ads = hostedAds; return(model); }
public IndexSingleAdViewModel GetAllAds() { //throw new NotImplementedException("Impl. GetAllAds"); var availableAds = new List <AdvertSingleViewModel>(); foreach (var item in context.JobAds) { var ad = new AdvertSingleViewModel { Id = item.Id, Position = item.PositionName, Description = item.Description, CompanyName = context.Employers.First(e => e.Id == item.EmployerId).CompanyName }; availableAds.Add(ad); } var db_ads = new IndexSingleAdViewModel(); db_ads.Ads = availableAds; return(db_ads); }