public async Task <IActionResult> EditAsync(GoalChangeViewModel model, string id) { if (!this.ModelState.IsValid) { return(this.View(model)); } var habitId = this.TempData["HabitId"].ToString(); var goalModel = this.goalService.MapGoalViewModelToGoal(model.GoalModel, id); await this.goalService.UpdateAsync(goalModel, habitId); return(this.Redirect("/Calendar")); }
public GoalChangeViewModel GetGoalChangeViewModel(string username) { if (string.IsNullOrEmpty(username)) { throw new ArgumentException(InvalidPropertyErrorMessage); } var goalViewModel = new GoalChangeViewModel { DayTimes = this.dayTimesDescriptions, Frequencies = this.frequenciesDescriptions, Durations = this.durationsDescriptions, Calendars = this.calendarService.GetAllCalendarTitlesByUserName <CalendarHabitViewModel>(username), Colors = this.colorService.GetAllColors(), }; return(goalViewModel); }
public async Task <IActionResult> CreateAsync(GoalChangeViewModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } if (!this.enumParseService.IsEnumValid <DayTime>(model.GoalModel.DayTime.ToString()) || !this.enumParseService.IsEnumValid <Frequency>(model.GoalModel.Frequency.ToString()) || !this.enumParseService.IsEnumValid <Duration>(model.GoalModel.Duration.ToString())) { return(this.View(model)); } await this.goalService.CreateAsync(model.GoalModel); return(this.Redirect("/")); }
public GoalChangeViewModel GetGoalChangeViewModelById(string goalId, string username) { if (string.IsNullOrEmpty(goalId) || string.IsNullOrEmpty(username)) { throw new ArgumentException(InvalidPropertyErrorMessage); } if (this.goalRepository.All().Count() <= 0) { throw new ArgumentException(InvalidPropertyErrorMessage); } var goalModel = this.goalRepository.All().Where(x => x.Id == goalId).First(); var goalViewModel = new GoalViewModel { Title = goalModel.Title, Frequency = this.enumParseService.GetEnumDescription(goalModel.Frequency.ToString(), typeof(Frequency)), DayTime = this.enumParseService.GetEnumDescription(goalModel.DayTime.ToString(), typeof(DayTime)), Duration = this.enumParseService.GetEnumDescription(goalModel.Duration.ToString(), typeof(Duration)), CalendarId = goalModel.CalendarId, ColorId = goalModel.ColorId, }; var goalChangeViewModel = new GoalChangeViewModel { GoalModel = goalViewModel, DayTimes = this.dayTimesDescriptions, Frequencies = this.frequenciesDescriptions, Durations = this.durationsDescriptions, Calendars = this.calendarService.GetAllCalendarTitlesByUserName <CalendarHabitViewModel>(username), Colors = this.colorService.GetAllColors(), }; return(goalChangeViewModel); }