Example #1
0
        public IActionResult VolunteerProfile(int volunteerId)
        {
            var volunteer = _db.Volunteers.Find(volunteerId);

            if (volunteer == null)
            {
                return(BadRequest(ErrorMessagesProvider.VolunteerErrors.VolunteerNotExists));
            }

            var pastEvents = _db.VolunteersOnEvent
                             .Include(voe => voe.Event)
                             .ThenInclude(e => e.Organizer)
                             .Include(voe => voe.Volunteer)
                             .AsNoTracking()
                             .Where(voe => voe.Event.Date < DateTime.Now && voe.Volunteer == volunteer)
                             .OrderByDescending(voe => voe.Event.Date)
                             .Select(voe => new PastEventsViewModel
            {
                Name          = voe.Event.Name,
                OrganizerName = voe.Event.Organizer.FullName,
                Rating        = voe.OpinionAboutVolunteer
            }).ToList();

            var vm = new VolunteerProfileViewModel
            {
                VolunteerId            = volunteer.AppUserId,
                FullName               = volunteer.FullName,
                City                   = volunteer.Address.City,
                PastEventViewModelList = pastEvents,
                Points                 = volunteer.Points
            };

            return(View(vm));
        }
Example #2
0
        public VolunteerProfileViewModel GetSignedVolunteer()
        {
            if (CurrentSigned.VolunteerId == -1)
            {
                throw new ArgumentException("You need to be Logged In");
            }

            var volunteer = context.Volunteers.Find(CurrentSigned.VolunteerId);
            var ads       = new List <AdvertSingleViewModel>();


            var model = new VolunteerProfileViewModel()
            {
                Username    = volunteer.Username,
                FirstName   = volunteer.FirstName,
                LastName    = volunteer.LastName,
                Age         = volunteer.Age,
                Contact     = volunteer.ContactInformation,
                SignedInAds = new IndexSingleAdViewModel()
                {
                    Ads = ads
                }
            };

            return(model);
        }
 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.");
     }
 }