Example #1
0
        public GoalChangeModel GetEditChangeViewModelById(string goalId)
        {
            if (string.IsNullOrEmpty(goalId))
            {
                throw new ArgumentException(InvalidPropertyErrorMessage);
            }

            var goal          = this.goalRepository.All().Where(x => x.Id == goalId).To <GoalModel>().First();
            var goalViewModel = new GoalModel
            {
                Title      = goal.Title,
                Frequency  = this.enumParseService.GetEnumDescription(goal.Frequency.ToString(), typeof(Frequency)),
                DayTime    = this.enumParseService.GetEnumDescription(goal.DayTime.ToString(), typeof(DayTime)),
                Duration   = this.enumParseService.GetEnumDescription(goal.Duration.ToString(), typeof(Duration)),
                CalendarId = goal.CalendarId,
                ColorId    = goal.ColorId,
            };

            var goalChangeViewModel = new GoalChangeModel
            {
                GoalModel   = goalViewModel,
                DayTimes    = this.dayTimesDescriptions,
                Frequencies = this.frequenciesDescriptions,
                Durations   = this.durationsDescriptions,
                Calendars   = this.calendarService.GetAll(),
                Colors      = this.colorService.GetAllColors(),
            };

            return(goalChangeViewModel);
        }
        public async Task <IActionResult> CreateAsync(GoalChangeModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            await this.goalService.CreateFromAdminAsync(model.GoalModel);

            return(this.RedirectToAction(nameof(this.Index)));
        }
        public async Task <IActionResult> EditAsync(GoalChangeModel model, string id)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var habitId   = this.TempData["HabitId"].ToString();
            var goalModel = this.goalService.MapGoalModelToGoal(model.GoalModel, id);

            await this.goalService.UpdateFromAdminAsync(goalModel);

            return(this.RedirectToAction(nameof(this.Index)));
        }
Example #4
0
        public GoalChangeModel GetCreateViewModel()
        {
            var model = new GoalChangeModel
            {
                GoalModel = new GoalModel
                {
                    StartDateTime = DateTime.Now,
                },
                DayTimes    = this.dayTimesDescriptions,
                Frequencies = this.frequenciesDescriptions,
                Durations   = this.durationsDescriptions,
                Calendars   = this.calendarService.GetAll(),
                Colors      = this.colorService.GetAllColors(),
            };

            return(model);
        }