Example #1
0
        //public ActionResult VolunteerClockedInOut(int locationId, string userName)
        public ActionResult VolunteerClockedInOut()
        {
            VIMSDBContext context   = ((Repository <Volunteer>)volunteerInfoRepository).Context;
            Volunteer     volunteer = (Volunteer)TempData["VolunteerInfo"];
            Location      location  = ((Location)TempData["Location"]);

            context.Entry(volunteer).State = EntityState.Modified; // reload after request

            VolunteerTimeClock clockInfo = volunteerInfoRepository.GetClockedInInfo(volunteer);
            VolunteerPhoto     photo     = volunteerInfoRepository.GetLastPhotoInfo(volunteer);
            VolunteerProfile   profile   = volunteerInfoRepository.GetDefaultProfileInfo(volunteer.Id);

            if (clockInfo != null)
            {
                // was clocked in so clock out
                clockInfo.ClockOut      = DateTime.Now;
                clockInfo.ClockOutPhoto =
                    photo != null ? photo.Path : null;
                context.SaveChanges(); //BKP todo, merge with repo code
            }
            else
            {
                // clock in
                VolunteerTimeClock clockIn = new VolunteerTimeClock();
                clockIn.VolunteerProfile = profile;
                clockIn.LocationId       = location.Id;
                clockIn.ClockIn          = DateTime.Now;
                clockIn.LocationId       = ViewBag.LocationId;
                clockIn.ClockInPhoto     =
                    photo != null ? photo.Path : null;
                clockIn.CreatedBy = null;
                clockIn.CreatedDt = DateTime.Now;
                volunteer.VolunteerTimeClocks.Add(clockIn);
                context.SaveChanges(); //BKP todo, merge with repo code
            }

            // build model for view
            VolunteerClockedInOutViewModel model = new VolunteerClockedInOutViewModel();

            model.isClockedIn            = (clockInfo == null); // now!, clocked in
            model.Volunteer              = volunteer;
            model.LocationId             = (int)location.Id;
            model.LocationName           = location.Name;
            model.TimeLogged             = VolunteerClockedInOutViewModel.GetHoursLogged(volunteerInfoRepository.GetVolunteersCompletedInOutInfos(volunteer));
            model.RecentClockInformation = volunteerInfoRepository.GetVolunteersRecentClockInOutInfos(volunteer, Util.TJSConstants.RECENT_LIST_LEN);
            model.CaseNumber             = profile != null ? profile.CaseNumber : "NA";
            model.TimeNeeded             = profile != null ? new TimeSpan((short)profile.Volunteer_Hours_Needed, 0, 0) : new TimeSpan(0, 0, 0);

            return(View(model));
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="locationId"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        //[HttpGet]
        public ActionResult VolunteerClockIn(int locationId, string userName)
        {
            Volunteer volunteer = volunteerInfoRepository.GetVolunteer(userName);
            Location  location  = lookUpRepository.GetLocationById((int)locationId);

            if (volunteer != null && volunteer.Id > 0)
            {
                VolunteerProfile profile =
                    volunteerInfoRepository.GetLastProfileInfo(volunteer.Id);
                VolunteerTimeClock clockInfo = volunteerInfoRepository.GetClockedInInfo(volunteer);

                //todo move to a view model?
                ViewBag.isClockedIn = (clockInfo != null); // clocked in
                ViewBag.Case        = profile != null ? profile.CaseNumber : "NA";

                TempData["VolunteerInfo"] = volunteer;
                TempData["Location"]      = location;

                VolunteerClockInViewModel vm = new VolunteerClockInViewModel();
                vm.Volunteer    = volunteer;
                vm.LocationId   = (int)location.Id;
                vm.LocationName = location.Name;
                VolunteerPhoto photo = volunteerInfoRepository.GetLastPhotoInfo(volunteer);
                if (photo != null)
                {
                    vm.DefaultPhotoPath = volunteerInfoRepository.GetLastPhotoInfo(volunteer).Path;
                }

                //dispose now, new context will be created in next request
                volunteerInfoRepository.Dispose();

                return(View(vm));
            }

            return(RedirectToAction("VolunteerLookUp", "VolunteerClockTime", new { locationId = location.Id }));
        }