Пример #1
0
        public ActionResult VolunteerCreateAccount(Volunteer volunteer, int locationId)
        {
            VIMSDBContext context = new VIMSDBContext();
            var           v       = context.Volunteers.Where(m => m.UserName == volunteer.UserName).SingleOrDefault();

            if (v != null)
            {
                ModelState.AddModelError("UserName", "User already exist.");
            }
            else
            {
                context.Volunteers.Add(volunteer);
                volunteer.CreatedBy = 0; // todo
                volunteer.CreatedDt = DateTime.Now;
                volunteer.UpdatedBy = 0; // todo
                volunteer.UpdatedDt = DateTime.Now;
                context.SaveChanges();

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

            ViewBag.LocationId = locationId;
            ViewBag.Error      = "User already exsit! Please choose another user name.";
            return(View());
        }
Пример #2
0
        public ActionResult EditEmployee(Employee employee)
        {
            if (ModelState.IsValid)
            {
                using (VIMSDBContext context = new VIMSDBContext())
                {
                    Employee current_employee = context.Employees.Find(employee.Id);
                    if (employee != null && (bool)employee.Active) // BKP fix should not be nullable
                    {
                        int count = context.Employees.
                                    Where(m => m.UserName == employee.UserName && m.Id != employee.Id).
                                    Count();

                        if (count == 0)
                        {
                            //employee.UpdatedBy = admin_id;
                            employee.UpdatedDt = System.DateTime.Now;
                            context.Entry(current_employee).CurrentValues.SetValues(employee);
                            context.SaveChanges();
                            return(View("EditemployeeConfirmation", employee));
                        }
                    }
                }
            }
            return(View("Error"));
        }
Пример #3
0
 public ActionResult Location()
 {
     using (VIMSDBContext context = new VIMSDBContext())
     {
         List <Location> locations = context.Locations.ToList <Location>();
         return(View(new LocationViewModel(locations)));
     }
 }
Пример #4
0
        public ActionResult VolunteerEditAccount(int volunteerId, int locationId)
        {
            ViewBag.LocationId = locationId;
            VIMSDBContext context = new VIMSDBContext();
            Volunteer     info    = context.Volunteers.Find(volunteerId);

            return(View(info));
        }
Пример #5
0
 public void TestMethod1()
 {
     using (VIMSDBContext context = new VIMSDBContext())
     {
         List <Country> list = context.Countries.ToList();
         Assert.IsNotNull(context);
         Assert.IsNotNull(list);
     }
 }
Пример #6
0
 public ActionResult VolunteerInformation(long id)
 {
     using (VIMSDBContext context = new VIMSDBContext())
     {
         Volunteer volunteer = context.Volunteers.Find(id);
         if (volunteer != null)
         {
             return(View("VolunteerInformation", volunteer));
         }
     }
     return(View("Error"));
 }
Пример #7
0
        public ActionResult DeleteLocation(LocationViewModel model)
        {
            using (VIMSDBContext context = new VIMSDBContext())
            {
                Location location = context.Locations.Find(model.SelectedLocationId);
                context.Locations.Remove(location);
                context.SaveChanges();
            }

            return(RedirectToAction("Location"));
            //return View(location);
        }
Пример #8
0
 public ActionResult EditEmployee(long id)
 {
     using (VIMSDBContext context = new VIMSDBContext())
     {
         Employee employee = context.Employees.Find(id);
         if (employee != null)
         {
             //ViewBag.AdminId = admin_id;
             return(View("EditEmployee", employee));
         }
     }
     return(View("Error"));
 }
Пример #9
0
        public ActionResult EditLocation(LocationViewModel model)
        {
            EditLocationsViewModel vm = new EditLocationsViewModel();

            using (VIMSDBContext context = new VIMSDBContext())
            {
                vm.countries = context.Countries.ToList <Country>();
                vm.states    = context.States.ToList <State>();
                vm.Location  = context.Locations.Find(model.SelectedLocationId);
            }

            return(View("EditLocation", vm));
        }
Пример #10
0
        public ActionResult AddLocation()
        {
            EditLocationsViewModel vm = new EditLocationsViewModel();

            using (VIMSDBContext context = new VIMSDBContext())
            {
                vm.countries = context.Countries.ToList <Country>();
                vm.states    = context.States.ToList <State>();
                vm.Location  = new Location();
            }

            return(View("AddLocation", vm));
        }
Пример #11
0
 public ActionResult EditOrganization(long id)
 {
     using (VIMSDBContext context = new VIMSDBContext())
     {
         Organization organization = context.Organizations.Find(id);
         if (organization != null && (bool)organization.Active) // BKP fix should not be nullable
         {
             //TempData["admin_id"] = admin_id; // todo validate
             return(View("EditOrganization", organization));
         }
     }
     return(View("Error"));
 }
Пример #12
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));
        }
Пример #13
0
 public ActionResult UndoDeleteOrganization(long id)
 {
     using (VIMSDBContext context = new VIMSDBContext())
     {
         Organization organization = context.Organizations.Find(id);
         if (organization != null && !(bool)organization.Active)
         {
             organization.Active = true;
             //organization.UpdatedBy = admin_id;
             organization.UpdatedDt = DateTime.Now;
             context.SaveChanges();
             return(View("UndoDeleteOrganizationConfirmation"));
         }
     }
     return(View("Error"));
 }
Пример #14
0
        public ActionResult VolunteerUpdateAccount(Volunteer volunteer, int locationId)
        {
            if (ModelState.IsValid)
            {
                using (VIMSDBContext context = new VIMSDBContext())
                {
                    Volunteer info = context.Volunteers.Find(volunteer.Id);
                    context.Entry(info).CurrentValues.SetValues(volunteer);
                    context.SaveChanges();
                }

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

            return(View("VolunteerEditAccount", volunteer));
        }
Пример #15
0
 //[HttpPost]
 public ActionResult UndoEditEmployee(Employee employee)
 {
     if (ModelState.IsValid)
     {
         using (VIMSDBContext context = new VIMSDBContext())
         {
             employee.Active    = true;
             employee.CreatedBy = 0;
             employee.CreatedDt = System.DateTime.Now;
             context.Employees.Add(employee);
             context.SaveChanges();
         }
         return(View("UndoEditEmployeeConfirmation", employee));
     }
     return(View("Error"));
 }
Пример #16
0
 public ActionResult UpdateLocation(EditLocationsViewModel model)
 {
     if (ModelState.IsValid)
     {
         using (VIMSDBContext context = new VIMSDBContext())
         {
             //todo
             //model.Location.UpdatedBy = "0";
             //model.Location.UpdatedDt = System.DateTime.Now;
             Location location = context.Locations.Find(model.Location.Id);
             context.Entry(location).CurrentValues.SetValues(model.Location);
             context.SaveChanges();
         }
     }
     return(View(model.Location));
 }
Пример #17
0
 public ActionResult UndoDeleteEmployee(long id)
 {
     using (VIMSDBContext context = new VIMSDBContext())
     {
         Employee employee = context.Employees.Find(id);
         if (employee != null && employee.Active != true)
         {
             employee.Active = true; // just set to active
             //employee.UpdatedBy = admin_id;
             employee.UpdatedDt = System.DateTime.Now;
             context.SaveChanges();
             return(View("UndoDeleteEmployeeConfirmation"));
         }
     }
     return(View("Error"));
 }
Пример #18
0
 public ActionResult VolunteerInformation(Volunteer volunteer)
 {
     if (ModelState.IsValid)
     {
         using (VIMSDBContext context = new VIMSDBContext())
         {
             Volunteer info = context.Volunteers.Find(volunteer.Id);
             if (info != null)
             {
                 context.Entry(info).CurrentValues.SetValues(volunteer);
                 context.SaveChanges();
                 return(View("VolunteerInformationConfirmation"));
             }
         }
     }
     return(View("Error"));
 }
Пример #19
0
        public ActionResult AddLocation(EditLocationsViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (VIMSDBContext context = new VIMSDBContext())
                {
                    //todo
                    model.Location.CreatedBy = 0;
                    model.Location.CreatedDt = System.DateTime.Now;
                    context.Locations.Add(model.Location);
                    context.SaveChanges();
                }

                return(RedirectToAction("Location"));
            }
            return(View(model.Location));
        }
Пример #20
0
 public ActionResult DeleteEmployee(long id)
 {
     using (VIMSDBContext context = new VIMSDBContext())
     {
         Employee employee = context.Employees.Find(id);
         if (employee != null && employee.Active != false)
         {
             //ViewBag.AdminId = admin_id;
             ViewBag.Id      = id;
             employee.Active = false; // just set to not active
             //employee.UpdatedBy = admin_id;
             employee.UpdatedDt = System.DateTime.Now;
             context.SaveChanges();
             return(View("DeleteEmployeeConfirmation", employee));
         }
         return(View("Error"));
     }
 }
Пример #21
0
        public ActionResult UndoEditOrganization(Organization organization)
        {
            if (ModelState.IsValid)
            {
                using (VIMSDBContext context = new VIMSDBContext())
                {
                    Organization current_organization = context.Organizations.Find(organization.Id);
                    if (organization != null && (bool)organization.Active) // BKP fix should not be nullable
                    {
                        int count = context.Organizations.
                                    Where(m => m.Name == organization.Name && m.Id != organization.Id).
                                    Count();

                        if (count == 0)
                        {
                            context.Entry(current_organization).CurrentValues.SetValues(organization);
                            context.SaveChanges();
                            return(View("UndoEditOrganizationConfirmation"));
                        }
                    }
                }
            }
            return(View("Error"));
        }
Пример #22
0
        public void TestVM()
        {
            VIMSDBContext context = new VIMSDBContext();

            VolunteerViewModel vm = new VolunteerViewModel(context.Locations.ToList(), context.Organizations.ToList());
        }
Пример #23
0
 public UnitOfWork(VIMSDBContext context)
 {
     this.context = context;
 }