public ActionResult Create([Bind(Include = "Id,PersonId,ActivityId,Date,Duration,Distance,UnitId,Title,Notes")] WorkoutEventViewModel formData)
        {
            if (ModelState.IsValid)
            {
                var workoutEvent = new WorkoutEvent()
                {
                    Id       = formData.Id,
                    User     = new User(formData.PersonId, ""),
                    Type     = new ActivityType(formData.ActivityId, ""),
                    Date     = formData.Date,
                    Duration = formData.Duration,
                    Distance = formData.Distance,
                    Unit     = new UnitOfMeasurement(formData.UnitId, ""),
                    Title    = formData.Title,
                    Notes    = formData.Notes
                };
                WorkoutEventManager.Insert(workoutEvent);
                return(RedirectToAction("Index"));
            }

            ViewBag.ActivityId = new SelectList(WorkoutEventManager.GetActivityTypes(), "Id", "Name", formData.ActivityId);
            ViewBag.PersonId   = new SelectList(MembershipProvider.ReadAll(), "Id", "Name", formData.PersonId);
            ViewBag.UnitId     = new SelectList(WorkoutEventManager.GetUnitOfMeasurements(), "Id", "Name", formData.UnitId);
            return(View(formData));
        }
Ejemplo n.º 2
0
        public void UpdateActivity(WorkoutEvent activity)
        {
            var runningEvent = MapRunningEvent(activity);

            using (var db = new Juggle4Food_RunningEntities())
            {
                db.Entry(runningEvent).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public int CreateActivity(WorkoutEvent activity)
        {
            var runningEvent = MapRunningEvent(activity);

            using (var db = new Juggle4Food_RunningEntities())
            {
                db.RunningEvents.Add(runningEvent);
                db.SaveChanges();
            }

            return(runningEvent.Id);
        }
Ejemplo n.º 4
0
        public WorkoutEvent ReadActivity(int id)
        {
            var workoutEvent = new WorkoutEvent();

            using (var db = new Juggle4Food_RunningEntities())
            {
                var runningEvent = db.RunningEvents.Find(id);
                if (runningEvent != null)
                {
                    workoutEvent = MapWorkoutEvent(runningEvent);
                }
            }

            return(workoutEvent);
        }
Ejemplo n.º 5
0
 private static RunningEvent MapRunningEvent(WorkoutEvent e)
 {
     return(new RunningEvent
     {
         Id = e.Id,
         Date = e.Date,
         Duration = e.Duration,
         ActivityId = e.Type.Id,
         Distance = Convert.ToDouble(e.Distance),
         Race = e.Title,
         Notes = e.Notes,
         PersonId = e.User.Id,
         UnitId = e.Unit.Id
     });
 }
Ejemplo n.º 6
0
        private IEnumerable <WorkoutEvent> CreateWorkoutEvents(IEnumerable <IEnumerable <string> > rawData)
        {
            var results = new List <WorkoutEvent>();

            //Get the first row column names into a list so we can find the correct data in any order
            var headerRow     = rawData.First().ToArray();
            var columnIndexes = new Dictionary <string, int>();

            for (int i = 0; i < headerRow.Count(); i++)
            {
                columnIndexes[headerRow[i].ToLower()] = i;
            }

            //validate that the required columns are present somewhere in the file
            string[] requiredColumns = { "activity type", "date", "title", "distance", "time" };
            foreach (string columnName in requiredColumns)
            {
                if (!columnIndexes.ContainsKey(columnName))
                {
                    throw new ArgumentException("File does not contain the required fields: " + requiredColumns);
                }
            }

            for (int i = 1; i < rawData.Count(); i++)
            {
                //Processing row
                //Activity Type,Date,Favorite,Title,Distance,Calories,Time
                var fields = rawData.ElementAt(i).ToArray();
                if (fields != null && fields[columnIndexes["activity type"]].ToLower() == "running")
                {
                    var workoutEvent = new WorkoutEvent
                    {
                        Date     = Convert.ToDateTime(fields[columnIndexes["date"]]),
                        Title    = fields[columnIndexes["title"]],
                        Distance = Convert.ToDecimal(fields[columnIndexes["distance"]]),
                        Duration = fields[columnIndexes["time"]]
                    };

                    results.Add(workoutEvent);
                }
            }

            return(results);
        }
Ejemplo n.º 7
0
        private List <WorkoutEvent> FilterEvents(IEnumerable <WorkoutEvent> importedEvents, int personId)
        {
            var cleansedEvents = new List <WorkoutEvent>();

            foreach (var currentEvent in importedEvents)
            {
                var newEvent = new WorkoutEvent
                {
                    Type     = new ActivityType(1, "Running"),
                    Unit     = new UnitOfMeasurement(1, "mi"),
                    User     = MembershipProvider.ReadAll().FirstOrDefault(u => u.Id == personId),
                    Date     = currentEvent.Date.Date,
                    Distance = currentEvent.Distance,
                    Duration = currentEvent.Duration
                };

                if (currentEvent.Title.ToLower() != "richardson running" && currentEvent.Title.ToLower() != "dallas running")
                {
                    newEvent.Title = currentEvent.Title;
                }

                //Only add if there's not a similar activity on the same day
                var matchingEventExists = WorkoutEventManager.ReadAll().Any(
                    e =>
                    e.User.Id == newEvent.User.Id &&
                    e.Date.Date == newEvent.Date.Date &&
                    e.Distance <newEvent.Distance + 1 &&
                                e.Distance> newEvent.Distance - 1);

                if (!matchingEventExists)
                {
                    cleansedEvents.Add(newEvent);
                }
            }

            return(cleansedEvents);
        }
Ejemplo n.º 8
0
        public static void Handle(WorkoutEvent @event)
        {
            switch (@event)
            {
            case WorkoutStarted e:
                WorkoutState.Save(e);
                Scorecard.Save(e);
                break;

            case ExerciseScored e:
                WorkoutState.Save(e);
                Scorecard.Save(e);
                TopScores.Save(e);
                break;

            case WorkoutCompleted e:
                WorkoutState.Save(e);
                Scorecard.Save(e);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 9
0
 public static void Update(WorkoutEvent workoutEvent)
 {
     Repository.UpdateActivity(workoutEvent);
 }
Ejemplo n.º 10
0
 public static void Insert(WorkoutEvent workoutEvent)
 {
     Repository.CreateActivity(workoutEvent);
 }