Example #1
0
        public async Task <ActionResult> Create(PersonAndLocationViewModel info)
        {
            try
            {
                string userId = User.Identity.GetUserId();
                info.person.ApplicationId = userId;
                int nextLocationId = context.Database.ExecuteSqlCommand("SELECT IDENT_CURRENT('dbo.Locations')") + 1;
                info.person.LocationId = nextLocationId;

                context.People.Add(info.person);

                string[] latLng = await GeoCode.GetLatLongFromApi(info.location);

                info.location.lat = latLng[0];
                info.location.lng = latLng[1];

                context.Locations.Add(info.location);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(View());
            }
        }
Example #2
0
        // GET: Person/Create
        public ActionResult Create()
        {
            Person   person   = new Person();
            Location location = new Location();

            PersonAndLocationViewModel info = new PersonAndLocationViewModel();

            info.person   = person;
            info.location = location;

            return(View(info));
        }
Example #3
0
        public ActionResult StudentIndex()
        {
            string userId    = User.Identity.GetUserId();
            var    userFound = context.People.Where(p => p.ApplicationId == userId).FirstOrDefault();

            if (userFound == null)
            {
                return(RedirectToAction("Create"));
            }
            List <PersonAndLocationViewModel> teachers = new List <PersonAndLocationViewModel>();
            List <Person> eligibleTeachers             = context.People.Where(s => s.subjects != null && s.PersonId != userFound.PersonId).ToList();

            foreach (Person teacher in eligibleTeachers)
            {
                PersonAndLocationViewModel info = new PersonAndLocationViewModel();
                info.person   = teacher;
                info.location = context.Locations.Where(l => l.LocationId == teacher.LocationId).Single();
                info.lessons  = context.Lessons.Where(lesson => lesson.teacherId == teacher.PersonId).ToList();
                info.avails   = context.TeacherAvailabilities.Where(av => av.PersonId == teacher.PersonId).ToList();
                teachers.Add(info);
            }
            List <Lesson> studentLessons = context.Lessons
                                           .Include("Teacher")
                                           .Include("Location")
                                           .Where(lesson => lesson.studentId == userFound.PersonId && lesson.teacherApproval == true && lesson.requiresMakeup == false).ToList();
            List <Lesson> lessonRequests = context.Lessons
                                           .Include("Student")
                                           .Include("Location")
                                           .Where(lesson => lesson.studentId == userFound.PersonId && lesson.teacherApproval == false && lesson.requiresMakeup == false).ToList();

            List <Lesson> makeupLessons = context.Lessons
                                          .Include("Teacher")
                                          .Include("Location")
                                          .Where(lesson => lesson.studentId == userFound.PersonId && lesson.requiresMakeup == true).ToList();

            BigIndexViewModel bigModel = new BigIndexViewModel();

            bigModel.teachersComp       = teachers;
            bigModel.studentLessons     = studentLessons;
            bigModel.currentUser        = userFound;
            bigModel.requestsForStudent = lessonRequests;
            bigModel.makeups            = makeupLessons;
            return(View(bigModel));
        }
Example #4
0
        // GET: Person/Details/5
        public async Task <ActionResult> Details(int id)
        {
            string head = User.Identity.GetUserId();

            Person student = context.People
                             .Include("Location")
                             .Where(per => per.ApplicationId == head)
                             .FirstOrDefault()
            ;

            //this is the teacher!
            PersonAndLocationViewModel personLocationDetails = new PersonAndLocationViewModel();

            personLocationDetails.person = context.People
                                           .Include("Location")
                                           .Where(p => p.PersonId == id)
                                           .Single();
            //this is the teacher's location!
            personLocationDetails.location = context.Locations.Where(l => l.LocationId == personLocationDetails.person.LocationId).Single();

            personLocationDetails.studentLocationId = student.LocationId;
            personLocationDetails.studentId         = student.PersonId;

            TeacherPreference tpreffer = context.Preferences.Where(pref => pref.teacherId == id).FirstOrDefault();

            int           range     = tpreffer.maxDistance;
            RadiusOptions type      = tpreffer.distanceType;
            decimal       increment = tpreffer.incrementalCost;

            decimal inHomeCost;

            //student.PersonId is still ok to use here!
            //string userId = User.Identity.GetUserId();
            //Person studentA = context.People.Where(peop => peop.ApplicationId == userId).FirstOrDefault();
            //int tempDistance = await Service_Classes.DistanceMatrix.GetTravelInfo(studentA, personLocationDetails.person);
            ////int tempDuration = await Service_Classes.DistanceMatrix.GetTravelInfo(student, personLocationDetails.person);
            ////inHomeCost = tpreffer.PerHourRate + (tpreffer.incrementalCost * tempDuration);


            ////personLocationDetails.outOfRange = tempDuration > tpreffer.maxDistance ? true : false;
            ////personLocationDetails.outOfRangeNum = personLocationDetails.outOfRange ? 1 : 0;
            ////personLocationDetails.inHomeCost = inHomeCost;
            ////personLocationDetails.studioCost = tpreffer.PerHourRate;


            var tempTeacher = context.Preferences.Where(p => p.teacherId == personLocationDetails.person.PersonId).SingleOrDefault();//tlc

            //this is the teacher's preferences
            var teacherPreferences = context.Preferences.Where(p => p.teacherId == personLocationDetails.person.PersonId).SingleOrDefault();//tlc

            if (teacherPreferences != null)
            {
                if (teacherPreferences.distanceType == RadiusOptions.Miles)
                {
                    string userId = User.Identity.GetUserId();

                    double teacherPreferenceRadius = teacherPreferences.maxDistance;                         //tlc
                    ViewBag.radius = teacherPreferenceRadius * Service_Classes.DistanceMatrix.metersToMiles; //tlc

                    var tempStudent = context.People.Include("Location").Where(p => p.ApplicationId == userId).SingleOrDefault();

                    if (tempStudent.PersonId != teacherPreferences.teacherId)
                    {
                        Lesson tempLesson = new Lesson();
                        tempLesson.Teacher    = context.People.Where(t => t.PersonId == teacherPreferences.teacherId).SingleOrDefault();
                        tempLesson.Student    = tempStudent;
                        tempLesson.Location   = tempStudent.Location;
                        tempLesson.LocationId = tempStudent.LocationId;
                        tempLesson            = await Service_Classes.DistanceMatrix.GetTravelInfo(tempLesson);

                        //ViewBag.lessonPrice =
                        ViewBag.outOfRange = teacherPreferences.maxDistance > tempLesson.travelDuration;
                    }
                }
                else if (tempTeacher.distanceType == RadiusOptions.Minutes)
                {
                    ViewBag.radius = teacherPreferences.maxDistance;
                }
            }



            return(View(personLocationDetails));
        }