public ActionResult Schedule(DateTime from, DateTime to) { var model = new ScheduleModel() { Activities = ScheduleService.GetActivities(from, to) }; return View(model); }
public async Task<IHttpActionResult> CreateSchedule(ScheduleModel schedule) { if (ModelState.IsValid && !schedule.UserId.Equals(this.CurrentUserId)) { ModelState.AddModelError("UserId", Resources.Error_CreateScheduleOnlyForYourself); } if (!ModelState.IsValid) { return BadRequest(ModelState); } var datamodel = this.TheModelFactory.CreateModel(schedule); await this.AppRepository.Schedules.AddAsync(datamodel); var result = this.TheModelFactory.CreateViewModel(datamodel); return CreatedAtRoute("GetScheduleById", new { id = schedule.Id }, result); }
public ActionResult Schedule() { var model = new ScheduleModel(); return View(model); }
public async static Task createTestdata(IManagementSession session) { Guid userId = session.CurrentUserId; ScheduleModel s = new ScheduleModel(); s.Name = "Arbeitstraining"; s.UserId = userId.ToString(); ScheduleModel back = await session.Users.CreateScheduleAsync(s); Console.WriteLine("Schedule angelegt"); var e1 = new ExerciseModel() { Name = "Bankdrücken", Description = "Stange von der Brust wegdrücken" }; var e2 = new ExerciseModel() { Name = "Kniebeuge", Description = "Ordentlich aus den Oberschnkeln drücken" }; var e3 = new ExerciseModel() { Name = "Beinpresse", Description = "Schweres Gewicht" }; ExerciseModel temp1 = await session.Admins.CreateExerciseAsync(e1); ExerciseModel temp2 = await session.Admins.CreateExerciseAsync(e2); ExerciseModel temp3 = await session.Admins.CreateExerciseAsync(e3); await session.Users.AddExerciseToScheduleAsync(back.Id, temp1.Id); await session.Users.AddExerciseToScheduleAsync(back.Id, temp2.Id); await session.Users.AddExerciseToScheduleAsync(back.Id, temp3.Id); Console.WriteLine("Übungen hinzugefügt"); /*EntryModel<int> a1 = new EntryModel<int>(); a1.Id = temp1.Id; exercises.Add(a1); ExerciseModel temp2 = await session.Admins.CreateExerciseAsync(e2); EntryModel<int> a2 = new EntryModel<int>(); a2.Id = temp2.Id; exercises.Add(a2); ExerciseModel temp3 = await session.Admins.CreateExerciseAsync(e3); EntryModel<int> a3 = new EntryModel<int>(); a3.Id = temp3.Id; exercises.Add(a3); ScheduleModel sUpdate = back; sUpdate.Exercises = exercises; var t = session.Users.UpdateScheduleAsync(sUpdate.Id, sUpdate); Console.WriteLine("Exercises angelegt"); /*PracticeModel p = new PracticeModel(); p.ExerciseId = temp1.Id; p.ScheduleId = back.Id; p.NumberOfRepetitions = 4; p.Repetitions = 12; p.Timestamp = DateTime.Now; p.UserId = userId.ToString(); p.Weight = 120.9; PracticeModel tempP = await session.Users.CreatePracticeAsync(p); PracticeModel p2 = new PracticeModel(); p2.ExerciseId = temp2.Id; p2.ScheduleId = back.Id; p2.NumberOfRepetitions = 5; p2.Repetitions = 15; p2.Timestamp = DateTime.Now; p2.UserId = userId.ToString(); p2.Weight = 40; PracticeModel tempP2 = await session.Users.CreatePracticeAsync(p2); Console.WriteLine("Practices angelegt");*/ }
/// <summary> /// Gibt alle Trainingspläne eines Benutzers zurück /// </summary> /// <returns></returns> public async Task<IEnumerable<ScheduleModel>> GetAllSchedulesAsync(Guid userID = new Guid()) { if (Online) { try { IEnumerable<ScheduleModel> schedules = await mgnService.GetAllSchedulesAsync().ConfigureAwait(continueOnCapturedContext: false); if(schedules != null) { foreach (var item in schedules) { Schedule s = new Schedule(); s.Id = item.Id; s.Name = item.Name; s.UserId = item.UserId; s.Url = item.Url; s.WasOffline = false; db.insertUpdateSchedule(s); foreach (var data in item.Exercises) { bool a = db.InsertScheduleHasExercises(item.Id, data.Id, false); } } return schedules; } return null; } catch (ServerException ex) { System.Console.WriteLine("Fehler beim Abrufen der Trainingspläne: " + ex.StackTrace); throw; } } else { try { //Alle Trainingspläne für den User zurückgeben IEnumerable<Schedule> schedules = db.GetAllSchedules(userID); List<ScheduleModel> resultSchedules = new List<ScheduleModel>(); if(schedules != null) { foreach (var schedule in schedules) { ScheduleModel temp = new ScheduleModel(); temp.Id = schedule.Id; temp.UserId = schedule.UserId; temp.Name = schedule.Name; temp.Url = schedule.Url; resultSchedules.Add(temp); } return resultSchedules; } return null; } catch (Exception exc) { System.Console.WriteLine("Fehler beim lokalen Abrufen der Trainingspläne: " + exc.StackTrace); return null; } } }
public ScheduleModel CreateViewModel(Schedule datamodel) { if (datamodel == null) { throw new ArgumentNullException("datamodel"); } var result = new ScheduleModel() { Id = datamodel.Id, Name = datamodel.Name, UserId = datamodel.UserID, Url = _UrlHelper.Link("GetScheduleById", new { id = datamodel.Id }) }; if (datamodel.Exercises != null && datamodel.Exercises.Any()) { result.Exercises = datamodel.Exercises.Select(x => new EntryModel<int>() { Id = x.Id, Name = x.Name, Url = _UrlHelper.Link("GetExerciseById", new { id = x.Id }), }); } return result; }
public Schedule CreateModel(ScheduleModel model, Schedule datamodel = null) { var result = datamodel ?? new Schedule(); result.UserID = model.UserId; result.Name = model.Name; result.Id = model.Id; return result; }
/// <summary> /// Updates a schedule /// </summary> /// <param name="scheduleId">id of the schedule</param> /// <param name="model">new module data</param> /// <returns></returns> public async Task UpdateScheduleAsync(int scheduleId, ScheduleModel model) { await PutAsJsonAsync(model, "api/schedule/" + scheduleId); }
/// <summary> /// Creates a new Schedule /// </summary> /// <param name="model">schedule data</param> /// <returns></returns> public async Task<ScheduleModel> CreateScheduleAsync(ScheduleModel model) { return await this.PostAsJsonReturnAsync<ScheduleModel, ScheduleModel>(model, "api/schedule"); }
public void Setup() { context = new ScheduleModel(new Uri("http://odata.microsoftpdc.com/ODataSchedule.svc/")); }