public IActionResult SearchDefault()
        {
            if (HttpContext.Session.GetInt32("LoggedInUserId") is null)
            {
                return(RedirectToAction("Index", "LoginReg"));
            }

            List <Commute> AllCommutes = dbContext.Commutes
                                         .Include(c => c.startLocation)
                                         .Include(c => c.endLocation)
                                         .Include(c => c.carpool)
                                         .ThenInclude(c => c.user)
                                         .Include(c => c.carpool)
                                         .ThenInclude(c => c.riderships)
                                         .ThenInclude(r => r.user)
                                         .Where(c => (c.carpool.user.Id != HttpContext.Session.GetInt32("LoggedInUserId")) && (!(c.carpool.riderships.Any(r => r.user.Id == HttpContext.Session.GetInt32("LoggedInUserId")))))
                                         .OrderBy(c => c.Day)
                                         .ThenBy(c => c.ArriveBy.Hour)
                                         .ToList();

            Commute defaultCommute = dbContext.Commutes
                                     .Include(c => c.startLocation)
                                     .Include(c => c.endLocation)
                                     .FirstOrDefault();
            ViewPools Data = new ViewPools()
            {
                ClickedCommute = defaultCommute,
                AllCommutes    = AllCommutes
            };

            return(View("Search", Data));
        }
Esempio n. 2
0
        public ActionResult Create([Bind(Include = "CommuteID,CommuteTime,StartPoint,EndPoint,TotalMiles,CO2GeneratedLbs,TransportMethodID")] Commute commute)
        {
            if (ModelState.IsValid)
            {
                //vehicle MPG Avg
                var myMPG = from test in db.TransportMethods
                            where test.TransportMethodID == test.TransportMethodID
                            select test.AvgMPG;

                //need to set test.TransportMethodID == identity column of TransportMethod or transport.TransportMethodID if possible.
                double mpgAvg = 0;

                foreach (var mpg in myMPG)
                {
                    mpgAvg = mpg;
                }

                //C02Footprint calculation
                if (travelDistance != 0)
                {
                    commute.CO2GeneratedLbs = (travelDistance / mpgAvg) * 20;
                }

                db.Commutes.Add(commute);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TransportMethodID = new SelectList(db.TransportMethods, "TransportMethodID", "TransportMode", commute.TransportMethodID);
            return(View(commute));
        }
        public IActionResult Search()
        {
            if (HttpContext.Session.GetInt32("LoggedInUserId") is null)
            {
                return(RedirectToAction("Index", "LoginReg"));
            }

            List <Commute> AllCommutes = dbContext.Commutes
                                         .Include(c => c.startLocation)
                                         .Include(c => c.endLocation)
                                         .Include(c => c.carpool)
                                         .ThenInclude(c => c.user)
                                         .Include(c => c.carpool)
                                         .ThenInclude(c => c.riderships)
                                         .ThenInclude(r => r.user)
                                         .Where(c => (c.carpool.user.Id != HttpContext.Session.GetInt32("LoggedInUserId")) && (!(c.carpool.riderships.Any(r => r.user.Id == HttpContext.Session.GetInt32("LoggedInUserId")))))
                                         .OrderBy(c => c.Day)
                                         .ThenBy(c => c.ArriveBy.Hour)
                                         .ToList();

            bool idValid = Int32.TryParse(RouteData.Values["mappedCommuteId"].ToString(), out int comId);

            Commute clickedCommute = dbContext.Commutes
                                     .Include(c => c.startLocation)
                                     .Include(c => c.endLocation)
                                     .FirstOrDefault(c => c.Id == comId);
            ViewPools Data = new ViewPools()
            {
                ClickedCommute = clickedCommute,
                AllCommutes    = AllCommutes
            };

            return(View(Data));
        }
        public async Task <IActionResult> PutCommute(int id, Commute commute)
        {
            if (id != commute.Id)
            {
                return(BadRequest());
            }

            _context.Entry(commute).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommuteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <Commute> > PostCommute(Commute commute)
        {
            _context.Commute.Add(commute);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCommute", new { id = commute.Id }, commute));
        }
        public IActionResult Carpool(int id, int mappedCommuteId)
        {
            if (HttpContext.Session.GetInt32("LoggedInUserId") is null)
            {
                return(RedirectToAction("Index", "LoginReg"));
            }

            Carpool carpool = dbContext.Carpools.Where(c => c.Id == id)
                              .Include(c => c.user)
                              .Include(c => c.commutes)
                              .ThenInclude(com => com.startLocation)
                              .Include(c => c.commutes)
                              .ThenInclude(com => com.endLocation)
                              .Include(c => c.riderships)
                              .ThenInclude(r => r.user)
                              .FirstOrDefault();

            Commute clickedCommute = dbContext.Commutes
                                     .Include(c => c.startLocation)
                                     .Include(c => c.endLocation)
                                     .FirstOrDefault(c => c.Id == mappedCommuteId);

            User logged_in_user = dbContext.Users.FirstOrDefault(u => u.Id == HttpContext.Session.GetInt32("LoggedInUserId"));

            ViewBag.logged_in_user = logged_in_user;
            ViewBag.ClickedCommute = clickedCommute;
            return(View(carpool));
        }
Esempio n. 7
0
        // GET: Commutes/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Commute commute = db.Commutes.Find(id);

            var commutes = db.Commutes.Include(c => c.TransportMethod);

            //personal comparisons to ...
            //*100 to make percentages easier

            double globalAvg   = (commute.CO2GeneratedLbs / 51.28) * 100;
            double cuyahogaAvg = (commute.CO2GeneratedLbs / 73.98) * 100;
            double twenty30Avg = (commute.CO2GeneratedLbs / 41.3) * 100;

            globalAvg   = Math.Round(globalAvg, 2);
            cuyahogaAvg = Math.Round(cuyahogaAvg, 2);
            twenty30Avg = Math.Round(twenty30Avg, 2);

            ViewBag.Global         = globalAvg;
            ViewBag.CuyahogaCounty = cuyahogaAvg;
            ViewBag.Twenty30Goal   = twenty30Avg;

            if (commute == null)
            {
                return(HttpNotFound());
            }
            return(View(commute));
        }
Esempio n. 8
0
        public ActionResult Create([Bind(Include = "CommuteID,CommuteTime,StartPoint,EndPoint,TotalMiles,CO2GeneratedLbs,TransportMethodID")] Commute commute)
        {
            if (ModelState.IsValid)
            {
                //vehicle MPG Avg
                var myMPG = from test in db.TransportMethods
                            where test.TransportMethodID == commute.TransportMethodID
                            select test.AvgMPG;

                //need to set test.TransportMethodID == identity column of TransportMethod or transport.TransportMethodID if possible.
                double mpgAvg = 0;

                foreach (var m in myMPG)
                {
                    mpgAvg = m;
                }

                //C02Footprint calculation
                if (travelDistance != 0)
                {
                    commute.CO2GeneratedLbs = (travelDistance / mpgAvg) * 20;
                }

                db.Commutes.Add(commute);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            var carStrings = db.TransportMethods
                             .OrderBy(q => q.Year)
                             .ToDictionary(q => q.TransportMethodID, q => q.Year + " " + q.Make + " " + q.Model + " " + q.TransportClass);

            ViewBag.TransportMethodID = new SelectList(carStrings, "Key", "Value");

            return(View(commute));
        }
Esempio n. 9
0
        public List <int> VerifyCommute()
        {
            var errors = new List <int>();

            if (Commute == null)
            {
                return(errors);
            }

            Commute = Commute.Trim().Replace(HidroConstants.DOUBLE_SPACE, HidroConstants.WHITE_SPACE);
            if (string.IsNullOrWhiteSpace(Commute))
            {
                Commute = null;
                return(errors);
            }

            Commute = HelperProvider.CapitalizeFirstLetterOfEachWord(Commute);

            var lenTest = new Regex(@".{1,40}");

            if (!lenTest.IsMatch(Commute))
            {
                errors.Add(29);
            }

            var rx = new Regex(@"^[A-Za-z\d ]*$");

            if (!rx.IsMatch(Commute))
            {
                errors.Add(30);
            }

            return(errors);
        }
Esempio n. 10
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CommuteDistance,CommuteDescription,CommuteSaved,CommuteName,CommuteDate,CommuteTypeId,StartPointId,StartPointCustom,EndPointId,EndPointCustom,UserId")] Commute commute)
        {
            ApplicationUser CurrentUser = await _userManager.GetUserAsync(HttpContext.User);

            commute.UserId = CurrentUser.Id;

            if (commute.StartPointId == 0)
            {
                commute.StartPointId = null;

                commute.StartPoint = new StartPoint()
                {
                    StartPointName = commute.StartPointCustom,
                    UserId         = CurrentUser.Id
                };
            }

            if (commute.EndPointId == 0)
            {
                commute.EndPointId = null;

                commute.EndPoint = new EndPoint()
                {
                    EndPointName = commute.EndPointCustom,
                    UserId       = CurrentUser.Id
                };
            }

            if (id != commute.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(commute);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CommuteExists(commute.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CommuteTypeId"] = new SelectList(_context.CommuteType, "Id", "CommuteTypeName", commute.CommuteTypeId);
            ViewData["EndPointId"]    = new SelectList(_context.Set <EndPoint>(), "Id", "EndPointName", commute.EndPointId);
            ViewData["StartPointId"]  = new SelectList(_context.Set <StartPoint>(), "Id", "StartPointName", commute.StartPointId);
            ViewData["UserId"]        = new SelectList(_context.Users, "Id", "Id", commute.UserId);
            return(View(commute));
        }
Esempio n. 11
0
        public ActionResult DeleteConfirmed(int id)
        {
            Commute commute = db.Commutes.Find(id);

            db.Commutes.Remove(commute);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 12
0
        /// <summary>
        /// Returns true if ActivitiesBody instances are equal
        /// </summary>
        /// <param name="other">Instance of ActivitiesBody to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(ActivitiesBody other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                     ) &&
                 (
                     Type == other.Type ||
                     Type != null &&
                     Type.Equals(other.Type)
                 ) &&
                 (
                     StartDateLocal == other.StartDateLocal ||
                     StartDateLocal != null &&
                     StartDateLocal.Equals(other.StartDateLocal)
                 ) &&
                 (
                     ElapsedTime == other.ElapsedTime ||
                     ElapsedTime != null &&
                     ElapsedTime.Equals(other.ElapsedTime)
                 ) &&
                 (
                     Description == other.Description ||
                     Description != null &&
                     Description.Equals(other.Description)
                 ) &&
                 (
                     Distance == other.Distance ||
                     Distance != null &&
                     Distance.Equals(other.Distance)
                 ) &&
                 (
                     Trainer == other.Trainer ||
                     Trainer != null &&
                     Trainer.Equals(other.Trainer)
                 ) &&
                 (
                     Commute == other.Commute ||
                     Commute != null &&
                     Commute.Equals(other.Commute)
                 ) &&
                 (
                     HideFromHome == other.HideFromHome ||
                     HideFromHome != null &&
                     HideFromHome.Equals(other.HideFromHome)
                 ));
        }
 public TravelViewModelSample()
 {
     Commute = new Commute
     {
         From        = "From: 810 River road",
         To          = "To: 810 test street",
         TravelingBy = "Car"
     };
 }
Esempio n. 14
0
        private void calculateToolStripButton_Click(object sender, EventArgs e)
        {
            Commute     currentCommute = data.CurrentCommute;
            PointLatLng p = CommuteDistance.FindWeightedCenterOfCommute(currentCommute);

            GMapMarker home = new GMarkerGoogle(p, GMarkerGoogleType.red);

            commuteOverlay.Markers.Add(home);
        }
Esempio n. 15
0
 public ActionResult Edit([Bind(Include = "CommuteID,CommuteTime,StartPoint,EndPoint,TotalMiles,CO2GeneratedLbs,TransportMethodID")] Commute commute)
 {
     if (ModelState.IsValid)
     {
         db.Entry(commute).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.TransportMethodID = new SelectList(db.TransportMethods, "TransportMethodID", "TransportMode", commute.TransportMethodID);
     return(View(commute));
 }
Esempio n. 16
0
        //Check Two commutes per day rule
        public bool CheckCommuteCountForDate(Commute commute, ApplicationUser currentUser)
        {
            var commuteCountForDate = _context.Commute.Where(c => c.UserId == currentUser.Id && c.CommuteDate.ToShortDateString() == commute.CommuteDate.ToShortDateString()).Count();

            if (commuteCountForDate >= 2)
            {
                ViewBag.DateError = "There are already 2 commutes entered for this date. Please change the date.";
                return(false);//False = Too many commutes for this date.
            }
            ViewBag.DateError = "";
            return(true);//True = May add this commute for this date.
        }
Esempio n. 17
0
        public async Task <IActionResult> Create([Bind("Id,CommuteDistance,CommuteDescription,CommuteSaved,CommuteName,CommuteDate,CommuteTypeId,StartPointId,StartPointCustom,EndPointId,EndPointCustom,UserId,User")] Commute commute)
        {
            ApplicationUser CurrentUser = await _userManager.GetUserAsync(HttpContext.User);

            commute.UserId = CurrentUser.Id;

            if (commute.StartPointId == 0)
            {
                commute.StartPointId = null;

                commute.StartPoint = new StartPoint()
                {
                    StartPointName = commute.StartPointCustom,
                    UserId         = CurrentUser.Id
                };
            }

            if (commute.EndPointId == 0)
            {
                commute.EndPointId = null;

                commute.EndPoint = new EndPoint()
                {
                    EndPointName = commute.EndPointCustom,
                    UserId       = CurrentUser.Id
                };
            }

            //If date has 2 or more commutes entered, prevent this entry.
            if (CheckCommuteCountForDate(commute, CurrentUser))
            {
                if (ModelState.IsValid)
                {
                    _context.Add(commute);
                    await _context.SaveChangesAsync();

                    if (CurrentUser.IsSubscribed == true)
                    {
                        SendCommuteSummaryEmail(commute, CurrentUser);
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["StartDate"]     = _context.ConfigDate.Select(c => c.StartDate).SingleOrDefault();
            ViewData["EndDate"]       = _context.ConfigDate.Select(c => c.EndDate).SingleOrDefault();
            ViewData["SavedCommutes"] = GetSavedCommutes(CurrentUser);
            ViewData["CommuteTypeId"] = new SelectList(_context.CommuteType, "Id", "CommuteTypeName", commute.CommuteTypeId);
            ViewData["EndPointId"]    = new SelectList(_context.Set <EndPoint>(), "Id", "EndPointName", commute.EndPointId);
            ViewData["StartPointId"]  = new SelectList(_context.Set <StartPoint>(), "Id", "StartPointName", commute.StartPointId);
            return(View(commute));
        }
Esempio n. 18
0
        // GET: Commutes/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Commute commute = db.Commutes.Find(id);

            if (commute == null)
            {
                return(HttpNotFound());
            }
            return(View(commute));
        }
Esempio n. 19
0
        public static string GetCommuteText(Commute commuteType)
        {
            switch (commuteType)
            {
                case Commute.ToWork:
                    return "to work";

                case Commute.FromWork:
                    return "back home";

                default:
                    throw new ArgumentOutOfRangeException("commuteType");
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Returns true if UpdatableActivity instances are equal
        /// </summary>
        /// <param name="other">Instance of UpdatableActivity to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(UpdatableActivity other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Commute == other.Commute ||
                     Commute != null &&
                     Commute.Equals(other.Commute)
                     ) &&
                 (
                     Trainer == other.Trainer ||
                     Trainer != null &&
                     Trainer.Equals(other.Trainer)
                 ) &&
                 (
                     HideFromHome == other.HideFromHome ||
                     HideFromHome != null &&
                     HideFromHome.Equals(other.HideFromHome)
                 ) &&
                 (
                     Description == other.Description ||
                     Description != null &&
                     Description.Equals(other.Description)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     Type == other.Type ||
                     Type != null &&
                     Type.Equals(other.Type)
                 ) &&
                 (
                     GearId == other.GearId ||
                     GearId != null &&
                     GearId.Equals(other.GearId)
                 ));
        }
Esempio n. 21
0
        /// <summary>
        /// Returns true if UploadsBody instances are equal
        /// </summary>
        /// <param name="other">Instance of UploadsBody to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(UploadsBody other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     File == other.File ||
                     File != null &&
                     File.Equals(other.File)
                     ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     Description == other.Description ||
                     Description != null &&
                     Description.Equals(other.Description)
                 ) &&
                 (
                     Trainer == other.Trainer ||
                     Trainer != null &&
                     Trainer.Equals(other.Trainer)
                 ) &&
                 (
                     Commute == other.Commute ||
                     Commute != null &&
                     Commute.Equals(other.Commute)
                 ) &&
                 (
                     DataType == other.DataType ||
                     DataType != null &&
                     DataType.Equals(other.DataType)
                 ) &&
                 (
                     ExternalId == other.ExternalId ||
                     ExternalId != null &&
                     ExternalId.Equals(other.ExternalId)
                 ));
        }
Esempio n. 22
0
        public IActionResult CommuteDelete(int id)
        {
            if (HttpContext.Session.GetInt32("LoggedInUserId") is null)
            {
                return(RedirectToAction("Index", "LoginReg"));
            }

            Commute thisCommute = dbContext.Commutes
                                  .Where(u => u.Id == id)
                                  .FirstOrDefault();

            dbContext.Remove(thisCommute);
            dbContext.SaveChanges();
            int carpoolId = thisCommute.CarpoolId;

            return(RedirectToAction("CarpoolEdit", "Carpool", new { id = carpoolId }));
        }
Esempio n. 23
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (Type != null)
         {
             hashCode = hashCode * 59 + Type.GetHashCode();
         }
         if (StartDateLocal != null)
         {
             hashCode = hashCode * 59 + StartDateLocal.GetHashCode();
         }
         if (ElapsedTime != null)
         {
             hashCode = hashCode * 59 + ElapsedTime.GetHashCode();
         }
         if (Description != null)
         {
             hashCode = hashCode * 59 + Description.GetHashCode();
         }
         if (Distance != null)
         {
             hashCode = hashCode * 59 + Distance.GetHashCode();
         }
         if (Trainer != null)
         {
             hashCode = hashCode * 59 + Trainer.GetHashCode();
         }
         if (Commute != null)
         {
             hashCode = hashCode * 59 + Commute.GetHashCode();
         }
         if (HideFromHome != null)
         {
             hashCode = hashCode * 59 + HideFromHome.GetHashCode();
         }
         return(hashCode);
     }
 }
Esempio n. 24
0
        public static Commute LoadCommute()
        {
            OpenFileDialog loadFileDialog = new OpenFileDialog();

            loadFileDialog.Filter = "XML Files (*.xml)|*.xml";

            Commute loadedCommute = null;

            if (loadFileDialog.ShowDialog() == DialogResult.OK)
            {
                XmlSerializer x        = new XmlSerializer(typeof(Commute));
                StreamReader  myReader = new StreamReader(loadFileDialog.FileName);

                loadedCommute = (Commute)x.Deserialize(myReader);
            }

            return(loadedCommute);
        }
Esempio n. 25
0
        public async Task <IActionResult> Create()
        {
            ApplicationUser CurrentUser = await _userManager.GetUserAsync(HttpContext.User);

            ViewBag.DateError         = "";
            ViewData["StartDate"]     = _context.ConfigDate.Select(c => c.StartDate).SingleOrDefault();
            ViewData["EndDate"]       = _context.ConfigDate.Select(c => c.EndDate).SingleOrDefault();
            ViewData["SavedCommutes"] = GetSavedCommutes(CurrentUser);
            ViewData["CommuteTypeId"] = new SelectList(_context.CommuteType, "Id", "CommuteTypeName");
            ViewData["EndPointId"]    = new SelectList(_context.Set <EndPoint>().Where(c => c.UserId == null || c.UserId == CurrentUser.Id).OrderBy(c => c.EndPointName), "Id", "EndPointName");
            ViewData["StartPointId"]  = new SelectList(_context.Set <StartPoint>().Where(c => c.UserId == null || c.UserId == CurrentUser.Id).OrderBy(c => c.StartPointName), "Id", "StartPointName");
            var model = new Commute()
            {
                CommuteDate = DateTime.Now
            };

            return(View(model));
        }
Esempio n. 26
0
        private void AddDestinationFromUI()
        {
            double visits;

            double.TryParse(visitsPerWeekMaskedTextBox.Text, out visits);

            Destination destination = new Destination();

            destination.destinationUid = destinationIDTextBox.Text;
            destination.location       = myMap.Position;
            destination.visitsPerWeek  = Convert.ToDouble(visitsPerWeekMaskedTextBox.Text);

            Commute currentCommute = new Commute();

            currentCommute.destinations = data.CurrentCommute.destinations;
            currentCommute.destinations.Add(destination);
            data.CurrentCommute = currentCommute;
        }
Esempio n. 27
0
        public static DaylightInfoModel BuildDaylightInfoModel(DateTime today, DaylightInfo daylightInfo, Commute commuteType, WorkingDays workingDays)
        {
            var daysToTransition = 0;
            DateTime? nextWorkingDayDaylightTransition = null;

            if (daylightInfo.NextDaylightTransition.HasValue)
            {
                var day = today;

                if (day >= daylightInfo.NextDaylightTransition.Value)
                {
                    throw new InvalidOperationException(string.Format("daylightInfo.NextDaylightTransition.Value equals {0}; but it should be in the future.", daylightInfo.NextDaylightTransition.Value));
                }

                var days = new List<DateTime>();

                while (day < daylightInfo.NextDaylightTransition.Value)
                {
                    day = day.AddDays(1);
                    days.Add(day);
                }

                // Nudge to the first working day, if necessary
                // TODO: Get rid of the flags variable here
                var workingDayFlags = new[] { workingDays.HasFlag(WorkingDays.Sunday), workingDays.HasFlag(WorkingDays.Monday), workingDays.HasFlag(WorkingDays.Tuesday), workingDays.HasFlag(WorkingDays.Wednesday), workingDays.HasFlag(WorkingDays.Thursday), workingDays.HasFlag(WorkingDays.Friday), workingDays.HasFlag(WorkingDays.Saturday) };
                while (!workingDayFlags[(int)days.Last().DayOfWeek])
                {
                    days.Add(days.Last().AddDays(1));
                }

                daysToTransition = days.Count(d => workingDayFlags[(int)d.DayOfWeek]);
                nextWorkingDayDaylightTransition = days.Last();
            }

            return new DaylightInfoModel
            {
                IsCurrentlyInDaylight = daylightInfo.IsCurrentlyInDaylight,
                PercentOfTheYearInTheDark = GetPercentOfTheYearInTheDark(daylightInfo.CommutesInDaylightPerYear),
                NextWorkingDayDaylightTransition = nextWorkingDayDaylightTransition,
                CommuteType = commuteType,
                NumberOfDaysToTransition = daysToTransition,
            };
        }
Esempio n. 28
0
        public async Task <IActionResult> CreateFromSaved(int id)
        {
            ApplicationUser CurrentUser = await _userManager.GetUserAsync(HttpContext.User);

            var savedCommute = _context.Commute.Find(id);
            var commute      = new Commute()
            {
                CommuteDate        = DateTime.Now,
                CommuteTypeId      = savedCommute.CommuteTypeId,
                CommuteDescription = savedCommute.CommuteDescription,
                CommuteDistance    = savedCommute.CommuteDistance,
                CommuteName        = savedCommute.CommuteName,
                CommuteSaved       = false,
                EndPointId         = savedCommute.EndPointId,
                StartPointId       = savedCommute.StartPointId,
                UserId             = savedCommute.UserId
            };

            //If this date contains 2 or more commutes for this user, do not let them post.
            if (CheckCommuteCountForDate(commute, CurrentUser))
            {
                if (ModelState.IsValid)
                {
                    _context.Add(commute);
                    await _context.SaveChangesAsync();

                    if (CurrentUser.IsSubscribed == true)
                    {
                        SendCommuteSummaryEmail(commute, CurrentUser);
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }


            ViewData["StartDate"]     = _context.ConfigDate.Select(c => c.StartDate).SingleOrDefault();
            ViewData["EndDate"]       = _context.ConfigDate.Select(c => c.EndDate).SingleOrDefault();
            ViewData["SavedCommutes"] = GetSavedCommutes(CurrentUser);
            ViewData["CommuteTypeId"] = new SelectList(_context.CommuteType, "Id", "CommuteTypeName", commute.CommuteTypeId);
            ViewData["EndPointId"]    = new SelectList(_context.Set <EndPoint>(), "Id", "EndPointName", commute.EndPointId);
            ViewData["StartPointId"]  = new SelectList(_context.Set <StartPoint>(), "Id", "StartPointName", commute.StartPointId);
            return(View("Create", commute));
        }
Esempio n. 29
0
        // GET: Commutes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Commute commute = db.Commutes.Find(id);

            if (commute == null)
            {
                return(HttpNotFound());
            }
            var carStrings = db.TransportMethods
                             .OrderBy(q => q.Year)
                             .ToDictionary(q => q.TransportMethodID, q => q.Year + " " + q.Make + " " + q.Model + " " + q.TransportClass);

            ViewBag.TransportMethodID = new SelectList(carStrings, "Key", "Value");
            return(View(commute));
        }
Esempio n. 30
0
        public async void SendCommuteSummaryEmail(Commute commute, ApplicationUser user)
        {
            var totalCommutes = _context.Commute.Where(c => c.UserId == commute.UserId).Count();
            var totalDistance = _context.Commute.Where(c => c.UserId == commute.UserId).Sum(c => c.CommuteDistance);
            var email         = user.Email;
            var subject       = "Congratulations on logging a Smart Commute!";

            var message = "<h1 style='color:white;background-color:black;text-align:center;padding:5px;margin:0px;border-radius: 10px 10px 0px 0px;'>Smart Commute Logged!</h1>";

            message += "<div style='background-color:darkcyan;color:white;text-align:center;padding:5px;margin:0px;border-radius: 0px 0px 10px 10px;'>";
            message += "<strong>Commute Name:</strong> " + commute.CommuteName + "<br/>";
            message += "<strong>Commute Distance:</strong> " + commute.CommuteDistance + "<br/>";
            message += "<strong>Commute Description:</strong> " + commute.CommuteDescription + "<br/>";
            message += "<strong>Commute Date:</strong> " + commute.CommuteDate + "<br/>";
            message += "<br/>";
            message += "<strong>Total Commutes:</strong> " + totalCommutes + "<br/>" + "<strong>Total Distance:</strong> " + totalDistance + "<br/><br/>";
            message += "Thank you for participating!<br/>Make sure to check your rewards on your Profile Page by selecting the Rewards button.";
            message += "</div>";
            await _emailSender.SendEmailAsync(email, subject, message);
        }
Esempio n. 31
0
        /// <summary>
        /// Returns an HtmlString for a right pointing (to work) or left pointing (from work) icon.
        /// </summary>
        public static HtmlString GetCommuteDirectionIcon(Commute commuteType)
        {
            string commuteDirectionIcon;

            switch (commuteType)
            {
                case Commute.ToWork:
                    commuteDirectionIcon = "<i class=\"fa fa-arrow-circle-o-right commute-direction\"></i>";
                    break;

                case Commute.FromWork:
                    commuteDirectionIcon = "<i class=\"fa fa-arrow-circle-o-left commute-direction\"></i>";
                    break;

                default:
                    throw new ArgumentOutOfRangeException("commuteType");
            }

            return new HtmlString(commuteDirectionIcon);
        }
Esempio n. 32
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Commute currentCommute = data.CurrentCommute;

            XmlSerializer x = new XmlSerializer(typeof(Commute));

            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "XML Files (*.xml)|*.xml";

            string saveFileName = "My Commute";

            saveFileDialog.FileName = saveFileName;

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                StreamWriter myWriter = new StreamWriter(saveFileDialog.FileName);
                x.Serialize(myWriter, currentCommute);
                myWriter.Close();
            }
        }
Esempio n. 33
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (File != null)
         {
             hashCode = hashCode * 59 + File.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (Description != null)
         {
             hashCode = hashCode * 59 + Description.GetHashCode();
         }
         if (Trainer != null)
         {
             hashCode = hashCode * 59 + Trainer.GetHashCode();
         }
         if (Commute != null)
         {
             hashCode = hashCode * 59 + Commute.GetHashCode();
         }
         if (DataType != null)
         {
             hashCode = hashCode * 59 + DataType.GetHashCode();
         }
         if (ExternalId != null)
         {
             hashCode = hashCode * 59 + ExternalId.GetHashCode();
         }
         return(hashCode);
     }
 }