예제 #1
0
        public async Task <IActionResult> Save(WorkoutEntry model)
        {
            if (model == null || model.NumberOfRepeatations == null || model.NumberOfRepeatations.Count == 0)
            {
                throw new ArgumentNullException(nameof(model));
            }

            IList <WorkoutEntity> workoutEntityCollection = new List <WorkoutEntity>();
            int setNumber = 1;

            foreach (var count in model.NumberOfRepeatations)
            {
                var entity = new WorkoutEntity()
                {
                    ActivityName = model.ActivityName,
                    CreatedOn    = DateTime.Now,
                    SetNumber    = setNumber,
                    Repeatations = count
                };

                workoutEntityCollection.Add(entity);
            }

            await this.workoutBusiness.SaveWorkoutRecordsAsync(workoutEntityCollection);

            return(View());
        }
예제 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            WorkoutEntry workoutEntry = db.WorkoutEntries.Find(id);

            db.WorkoutEntries.Remove(workoutEntry);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #3
0
        public WorkoutEntry UpdateWorkoutEntry(WorkoutEntry entry)
        {
            using (var transaction = this.context.Database.BeginTransaction())
            {
                this.context.WorkoutEntries.Update(entry);
                this.context.SaveChanges();
                this.RefreshPerformanceTotals(entry.UserId);

                transaction.Commit();
                return(entry);
            }
        }
예제 #4
0
 public ActionResult Edit([Bind(Include = "WorkoutEntryId,WorkoutEntryName,WorkoutEntryDateTime,AthleteId,RouteId,VehicleId")] WorkoutEntry workoutEntry)
 {
     if (ModelState.IsValid)
     {
         db.Entry(workoutEntry).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AthleteId = new SelectList(db.Athletes, "AthleteId", "FirstName", workoutEntry.AthleteId);
     ViewBag.RouteId   = new SelectList(db.Routes, "RouteId", "RouteDescription", workoutEntry.RouteId);
     ViewBag.VehicleId = new SelectList(db.Vehicles, "VehicleId", "VehicleName", workoutEntry.VehicleId);
     return(View(workoutEntry));
 }
예제 #5
0
        // GET: WorkoutEntries/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WorkoutEntry workoutEntry = db.WorkoutEntries.Find(id);

            if (workoutEntry == null)
            {
                return(HttpNotFound());
            }
            return(View(workoutEntry));
        }
예제 #6
0
        public void DeleteWorkoutEntry(int id, string userId)
        {
            using (var transaction = this.context.Database.BeginTransaction())
            {
                var entity = new WorkoutEntry {
                    Id = id
                };
                this.context.Attach(entity);
                this.context.Remove(entity);
                context.SaveChanges();
                this.RefreshPerformanceTotals(userId);

                transaction.Commit();
            }
        }
예제 #7
0
        // GET: WorkoutEntries/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WorkoutEntry workoutEntry = db.WorkoutEntries.Find(id);

            if (workoutEntry == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AthleteId = new SelectList(db.Athletes, "AthleteId", "FirstName", workoutEntry.AthleteId);
            ViewBag.RouteId   = new SelectList(db.Routes, "RouteId", "RouteDescription", workoutEntry.RouteId);
            ViewBag.VehicleId = new SelectList(db.Vehicles, "VehicleId", "VehicleName", workoutEntry.VehicleId);
            return(View(workoutEntry));
        }
예제 #8
0
        public bool ParseWorkouts()
        {
            string pathToArchive  = _appConfiguration.Value.PathToArchive;
            string pathToWorkouts = _appConfiguration.Value.PathToWorkouts;

            if (!File.Exists(pathToArchive))
            {
                _logger.LogError($"Cannot find file with archive: {pathToArchive}");
            }

            if (string.IsNullOrEmpty(pathToWorkouts))
            {
                _logger.LogError($"Path to workouts folder cannot be empty: {pathToWorkouts}.");
                return(false);
            }

            WriteMessage($"Staring parsing archive file {pathToArchive}...");

            var workoutEntries = new List <WorkoutEntry>();
            int i = 0;

            using (ZipArchive archive = ZipFile.OpenRead(pathToArchive))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.Name.EndsWith(".json", StringComparison.InvariantCultureIgnoreCase) &&
                        string.Equals(Path.GetDirectoryName(entry.FullName), "Workouts", StringComparison.InvariantCultureIgnoreCase))
                    {
                        _logger.LogInformation($"Trying to find a sport type in {entry.FullName}");
                        string sportType = GetSportType(entry);
                        _logger.LogInformation($"Found '{sportType}'");

                        workoutEntries.Add(new WorkoutEntry(sportType, Path.GetFileNameWithoutExtension(entry.FullName)));
                    }
                }

                if (workoutEntries.Count > 0)
                {
                    WriteMessage($"Found {workoutEntries.Count} json files");

                    if (Directory.Exists(pathToWorkouts))
                    {
                        WriteMessage($"Deleting directory '{pathToWorkouts}'");
                        Directory.Delete(pathToWorkouts, true);
                    }

                    WriteMessage($"Creating directory '{pathToWorkouts}'");
                    Directory.CreateDirectory(pathToWorkouts);
                }

                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.Name.EndsWith(".tcx", StringComparison.InvariantCultureIgnoreCase) &&
                        string.Equals(Path.GetDirectoryName(entry.FullName), "Workouts", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string       fileName     = Path.GetFileNameWithoutExtension(entry.FullName);
                        WorkoutEntry workoutEntry = workoutEntries.FirstOrDefault(x => x.fileName.Equals(fileName, StringComparison.InvariantCultureIgnoreCase));

                        if (workoutEntry != null)
                        {
                            string destinationPath = Path.Combine(pathToWorkouts, workoutEntry.sportType, fileName.Replace(':', '_') + $".tcx");
                            WriteMessage($"{++i}: Saving workout '{entry.FullName}' to {destinationPath}");

                            Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));

                            entry.ExtractToFile(destinationPath);
                        }
                    }
                }
            }

            WriteMessage("DONE");

            return(true);
        }
 public IActionResult Put([FromBody] WorkoutEntry entry)
 {
     entry.UserId = this.GetUserId();
     this.repository.UpdateWorkoutEntry(entry);
     return(new ObjectResult(entry));
 }